Skip to content

Commit

Permalink
feat: configurable min severity level for charts
Browse files Browse the repository at this point in the history
  • Loading branch information
gabidobo committed Feb 5, 2023
1 parent b5467f8 commit 2950408
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/charts/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const getBody = (string) => string.substring(string.indexOf('{') + 1, string.lastIndexOf('}'));

const setupTooltips = () => {
const SEVERITIES = ['critical', 'high', 'moderate', 'low'];
const SEVERITY_ICONS = {
critical: '🔴',
high: '🟠',
Expand All @@ -20,7 +19,6 @@ const setupTooltips = () => {
const [offsetX, offsetY, viewBoxWidth, viewBoxHeight] = viewBox.split(',').map(parseFloat);
const maxX = offsetX + viewBoxWidth;
const maxY = offsetY + viewBoxHeight;
const sortBySeverity = (a, b) => SEVERITIES.indexOf(a.severity) - SEVERITIES.indexOf(b.severity);
const getHTML = (ancestry, issues, licenseName) => {
let html =
'<div style="padding: 2px; background: #777; color: white; margin-bottom: 2px;">Path</div>';
Expand All @@ -33,7 +31,7 @@ const setupTooltips = () => {
if (issues.length) {
html +=
'<div style="padding: 2px; background: #777; color: white; margin: 2px 0;">Issues</div>';
issues.sort(sortBySeverity).forEach(({title, url, severity = 'critical'}) => {
issues.forEach(({title, url, severity = 'critical'}) => {
html += `<div style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
${SEVERITY_ICONS[severity]} ${url ? `<a href="${url}" target="_blank">` : ''}${title}${
url ? '</a>' : ''
Expand Down
23 changes: 17 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ const {getReports} = require('./issues/utils');
const csv = require('./charts/csv');

const getReport = async ({
types = ['tree', 'treemap'],
appPath,
dependencyGraph,
includeDev = false,
showVersions = false,
minDisplayedSeverity = 'high',
width = 1500,
maxDepth = 7,
types = ['tree', 'treemap'],
onProgress = () => {},
dependencyGraph,
}) => {
const errors = [];

Expand Down Expand Up @@ -51,21 +52,31 @@ const getReport = async ({
// Get license info and issues
onProgress({type: 'start', stage: 'licenses'});
try {
licenseUsage = await getLicenseUsage({dependencies: dGraph.prodDependencies});
licenseUsage = await getLicenseUsage({
dependencies: includeDev ? dGraph.all : dGraph.prodDependencies,
});
licenseIssues = await getLicenseIssues({licenseUsage, packageGraph});
} catch (error) {
errors.push(error);
}
onProgress({type: 'end', stage: 'licenses'});

// Generate charts
const SEVERITIES = ['critical', 'high', 'moderate', 'low'];
const sortBySeverity = (a, b) => SEVERITIES.indexOf(a.severity) - SEVERITIES.indexOf(b.severity);
const filteredIssues = (dependencyVulnerabilities || [])
.concat(rootVulnerabilities || [])
.concat(licenseIssues || [])
.filter(
({severity}) => SEVERITIES.indexOf(severity) <= SEVERITIES.indexOf(minDisplayedSeverity),
)
.sort(sortBySeverity);

const options = {
showVersions,
width,
maxDepth,
issues: (dependencyVulnerabilities || [])
.concat(rootVulnerabilities || [])
.concat(licenseIssues || []),
issues: filteredIssues,
includeDev,
onProgress: (message) => onProgress({type: 'update', stage: 'chart', message}),
};
Expand Down

0 comments on commit 2950408

Please sign in to comment.