Skip to content

Commit

Permalink
fix: sort impacted versions DESC
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGSS committed Jan 14, 2025
1 parent d944670 commit 2595ea1
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions lib/security_blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,34 +281,37 @@ export default class SecurityBlog extends SecurityRelease {
}

getImpact(content) {
const impact = content.reports.reduce((acc, report) => {
for (const affectedVersion of report.affectedVersions) {
if (acc[affectedVersion]) {
acc[affectedVersion].push(report);
} else {
acc[affectedVersion] = [report];
}
const impact = new Map();
for (const report of content.reports) {
for (const version of report.affectedVersions) {
if (!impact.has(version)) impact.set(version, []);
impact.get(version).push(report);
}
return acc;
}, {});

const impactText = [];
for (const [key, value] of Object.entries(impact)) {
const groupedByRating = Object.values(_.groupBy(value, 'severity.rating'))
.map(severity => {
if (!severity[0]?.severity?.rating) {
this.cli.error(`severity.rating not found for the report ${severity[0].id}. \
Please add it manually before continuing.`);
}

const result = Array.from(impact.entries())
.sort(([a], [b]) => b.localeCompare(a)) // DESC
.map(([version, reports]) => {
const severityCount = new Map();

for (const report of reports) {
const rating = report.severity.rating?.toLowerCase();
if (!rating) {
this.cli.error(`severity.rating not found for report ${report.id}.`);
process.exit(1);
}
const firstSeverityRating = severity[0].severity.rating.toLocaleLowerCase();
return `${severity.length} ${firstSeverityRating} severity issues`;
}).join(', ');
severityCount.set(rating, (severityCount.get(rating) || 0) + 1);
}

impactText.push(`The ${key} release line of Node.js is vulnerable to ${groupedByRating}.`);
}
const groupedByRating = Array.from(severityCount.entries())
.map(([rating, count]) => `${count} ${rating} severity issues`)
.join(', ');

return `The ${version} release line of Node.js is vulnerable to ${groupedByRating}.`;
})
.join('\n');

return impactText.join('\n');
return result;
}

getVulnerabilities(content) {
Expand Down

0 comments on commit 2595ea1

Please sign in to comment.