Skip to content

Commit e11ec54

Browse files
committed
Hide columns conditionally when applying severity filter
1 parent a122958 commit e11ec54

File tree

4 files changed

+97
-44
lines changed

4 files changed

+97
-44
lines changed

dist/index.js

Lines changed: 40 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/report.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export interface RiskAcceptanceDefinition {
212212

213213
const severityOrder = ["negligible", "low", "medium", "high", "critical"];
214214

215-
function isSeverityGte(a: string, b: string): boolean {
215+
export function isSeverityGte(a: string, b: string): boolean {
216216
return severityOrder.indexOf(a.toLocaleLowerCase()) >= severityOrder.indexOf(b.toLocaleLowerCase());
217217
}
218218

src/summary.ts

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as core from "@actions/core";
2-
import { FilterOptions, filterPackages, Package, Report, Rule } from "./report";
2+
import { FilterOptions, filterPackages, Package, Severity, isSeverityGte, Report, Rule } from "./report";
33
import { ActionInputs } from "./action";
44

55
const EVALUATION: any = {
@@ -24,36 +24,70 @@ export async function generateSummary(opts: ActionInputs, data: Report, filters?
2424
await core.summary.write({ overwrite: true });
2525
}
2626

27-
function addVulnTableToSummary(data: Report) {
28-
// Fallback to empty object if undefined
29-
const totalVuln = data.result.vulnTotalBySeverity ?? {};
30-
const fixableVuln = data.result.fixableVulnTotalBySeverity ?? {};
27+
const SEVERITY_LABELS: Record<Severity, string> = {
28+
critical: "🟣 Critical",
29+
high: "🔴 High",
30+
medium: "🟠 Medium",
31+
low: "🟡 Low",
32+
negligible: "⚪ Negligible"
33+
};
34+
35+
function countVulnsBySeverity(
36+
packages: Package[],
37+
minSeverity?: Severity
38+
): {
39+
total: Record<Severity, number>;
40+
fixable: Record<Severity, number>;
41+
} {
42+
// Inicializamos todas las severidades
43+
const result = {
44+
total: { critical: 0, high: 0, medium: 0, low: 0, negligible: 0 },
45+
fixable: { critical: 0, high: 0, medium: 0, low: 0, negligible: 0 }
46+
};
47+
48+
for (const pkg of packages) {
49+
for (const vuln of pkg.vulns ?? []) {
50+
const sev = vuln.severity.value.toLowerCase() as Severity;
51+
// Solo cuenta si cumple el minSeverity (o no hay minSeverity)
52+
if (!minSeverity || isSeverityGte(sev, minSeverity)) {
53+
result.total[sev]++;
54+
if (vuln.fixedInVersion || pkg.suggestedFix) {
55+
result.fixable[sev]++;
56+
}
57+
}
58+
}
59+
}
60+
return result;
61+
}
62+
63+
function addVulnTableToSummary(
64+
data: Report,
65+
minSeverity?: Severity
66+
) {
67+
const pkgs = data.result.packages;
68+
// Lista completa de severidades en orden, de mayor a menor
69+
const SEVERITY_ORDER: Severity[] = ["critical", "high", "medium", "low", "negligible"];
70+
71+
// Solo mostramos las severidades >= minSeverity
72+
const visibleSeverities = SEVERITY_ORDER.filter(sev =>
73+
!minSeverity || isSeverityGte(sev, minSeverity)
74+
);
75+
76+
const totalVulns = countVulnsBySeverity(pkgs, minSeverity);
3177

3278
core.summary.addHeading(`Vulnerabilities summary`, 2);
3379
core.summary.addTable([
3480
[
3581
{ data: '', header: true },
36-
{ data: '🟣 Critical', header: true },
37-
{ data: '🔴 High', header: true },
38-
{ data: '🟠 Medium', header: true },
39-
{ data: '🟡 Low', header: true },
40-
{ data: '⚪ Negligible', header: true }
82+
...visibleSeverities.map(s => ({ data: SEVERITY_LABELS[s], header: true }))
4183
],
4284
[
4385
{ data: '⚠️ Total Vulnerabilities', header: true },
44-
`${totalVuln.critical ?? 0}`,
45-
`${totalVuln.high ?? 0}`,
46-
`${totalVuln.medium ?? 0}`,
47-
`${totalVuln.low ?? 0}`,
48-
`${totalVuln.negligible ?? 0}`
86+
...visibleSeverities.map(s => `${totalVulns.total[s] ?? 0}`)
4987
],
5088
[
5189
{ data: '🔧 Fixable Vulnerabilities', header: true },
52-
`${fixableVuln.critical ?? 0}`,
53-
`${fixableVuln.high ?? 0}`,
54-
`${fixableVuln.medium ?? 0}`,
55-
`${fixableVuln.low ?? 0}`,
56-
`${fixableVuln.negligible ?? 0}`
90+
...visibleSeverities.map(s => `${totalVulns.fixable[s] ?? 0}`)
5791
],
5892
]);
5993
}
@@ -166,7 +200,7 @@ function addReportToSummary(data: Report) {
166200
core.summary.addHeading(`Rule Bundle: ${bundle.name}`, 4)
167201

168202
bundle.rules.forEach(rule => {
169-
core.summary.addHeading(`${EVALUATION[rule.evaluationResult]} Rule: ${rule.description}`, 5)
203+
core.summary.addHeading(`Rule: ${rule.description}`, 5)
170204

171205
if (rule.evaluationResult != "passed") {
172206
if (rule.failureType == "pkgVulnFailure") {

0 commit comments

Comments
 (0)