summaryrefslogtreecommitdiff
path: root/html2json.js
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2019-10-22 20:24:29 +0000
committermo khan <mo.khan@gmail.com>2019-10-22 20:24:29 +0000
commit431f07f8d11b2bc2a8fd09351a4323c9df676822 (patch)
tree4f40b60925a4edf8eace71ae8af65bb5d67c7b6b /html2json.js
parent7f175952a5a047d785b5ea72c15a10642523c62a (diff)
parent561556fbd1f59492cfa8fdd790f2ce39c90f3a8d (diff)
Merge branch 'remove-tech-debt' into 'master'v1.7.2
Remove feature flags and temporary mappings See merge request gitlab-org/security-products/license-management!75
Diffstat (limited to 'html2json.js')
-rw-r--r--html2json.js88
1 files changed, 0 insertions, 88 deletions
diff --git a/html2json.js b/html2json.js
deleted file mode 100644
index 1c4ae9b..0000000
--- a/html2json.js
+++ /dev/null
@@ -1,88 +0,0 @@
-var cheerio = require('cheerio')
-var path = require('path')
-
-// Read the HTML report
-fs = require('fs')
-var htmlContent;
-try {
- htmlContent = fs.readFileSync(process.argv[2], 'utf8');
-} catch(e) {
- console.log('Error:', e.stack);
- process.exit(1);
-}
-
-// Get the directory containing the results to make pathes relative to it later.
-report_directory = path.dirname(process.argv[2])
-
-const $ = cheerio.load(htmlContent)
-
-// Map that keeps the total tally of the license occurrences
-var licenses = {};
-
-// Extract dependencies info.
-var dependencies = []
-$('div.dependencies div').each(function(i, doc) {
- // Get license name.
- license = $(this).find('blockquote p').text().trim();
- license = license.split("\n")[0];
-
- if(licenses[license]) {
- licenses[license].count += 1;
- } else {
- licenses[license] = { count: 1, name: license }
- }
-
- // Get URL.
- license_url = $(this).find('blockquote p a[href]').attr('href');
-
- // Get dependency name.
- dependency_name = $(this).find('h2').text().trim();
- dependency_name = dependency_name.split("\n")[0];
-
- // Get dependency URL.
- dependency_url = $(this).find('h2 a[href]').attr('href');
-
- // Get dependency description.
- dependency_description = $(this).find('dl').first().next().text().trim();
-
- // Get dependency location relative to the project root path
- dependency_pathes = []
- $(this).find('dl').first().find('dd').each(function(i, doc) {
- dependency_path = path.relative(report_directory, $(this).text().trim());
-
- // Whitespace path means current directory
- if (!dependency_path) {
- dependency_path = ".";
- }
-
- dependency_pathes.push(dependency_path);
- })
- dependencies.push({
- license: {
- name: license,
- url: license_url
- },
- dependency: {
- name: dependency_name,
- url: dependency_url,
- description: dependency_description,
- pathes: dependency_pathes
- }
- })
-})
-
-// Stable sort of licenses. First license count descending, then license name ascending
-licenses = Object.values(licenses)
- .sort(function (a, b) {
- if (a.count === b.count) {
- return a.name > b.name ? 1 : -1;
- }
- return a.count < b.count ? 1 : -1;
-});
-
-console.log(JSON.stringify({
- licenses: licenses,
- dependencies: dependencies}, null, 2))
-
-
-