1
1
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" ;
3
3
import { ActionInputs } from "./action" ;
4
4
5
5
const EVALUATION : any = {
@@ -24,36 +24,70 @@ export async function generateSummary(opts: ActionInputs, data: Report, filters?
24
24
await core . summary . write ( { overwrite : true } ) ;
25
25
}
26
26
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 ) ;
31
77
32
78
core . summary . addHeading ( `Vulnerabilities summary` , 2 ) ;
33
79
core . summary . addTable ( [
34
80
[
35
81
{ 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 } ) )
41
83
] ,
42
84
[
43
85
{ 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 } ` )
49
87
] ,
50
88
[
51
89
{ 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 } ` )
57
91
] ,
58
92
] ) ;
59
93
}
@@ -166,7 +200,7 @@ function addReportToSummary(data: Report) {
166
200
core . summary . addHeading ( `Rule Bundle: ${ bundle . name } ` , 4 )
167
201
168
202
bundle . rules . forEach ( rule => {
169
- core . summary . addHeading ( `${ EVALUATION [ rule . evaluationResult ] } Rule: ${ rule . description } ` , 5 )
203
+ core . summary . addHeading ( `Rule: ${ rule . description } ` , 5 )
170
204
171
205
if ( rule . evaluationResult != "passed" ) {
172
206
if ( rule . failureType == "pkgVulnFailure" ) {
0 commit comments