1
1
import * as core from "@actions/core" ;
2
- import { FilterOptions , filterPackages , Package , Report , Rule } from "./report" ;
2
+ import { FilterOptions , filterPackages , Package , Severity , SeverityNames , Report , Rule } from "./report" ;
3
3
import { ActionInputs } from "./action" ;
4
4
5
5
const EVALUATION : any = {
@@ -24,36 +24,72 @@ 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
+ severities : Severity [ ]
38
+ ) : {
39
+ total : Record < Severity , number > ;
40
+ fixable : Record < Severity , number > ;
41
+ } {
42
+ const result = {
43
+ total : { critical : 0 , high : 0 , medium : 0 , low : 0 , negligible : 0 } ,
44
+ fixable : { critical : 0 , high : 0 , medium : 0 , low : 0 , negligible : 0 }
45
+ } ;
46
+
47
+ for ( const pkg of packages ) {
48
+ for ( const vuln of pkg . vulns ?? [ ] ) {
49
+ const sev = ( vuln . severity . value as Severity ) . toLowerCase ( ) as Severity ;
50
+ if ( severities . includes ( sev ) ) {
51
+ result . total [ sev ] ++ ;
52
+ if ( vuln . fixedInVersion || pkg . suggestedFix ) {
53
+ result . fixable [ sev ] ++ ;
54
+ }
55
+ }
56
+ }
57
+ }
58
+ return result ;
59
+ }
60
+
61
+ function getVisibleSeverities ( minSeverity ?: Severity ) : Severity [ ] {
62
+ const SEVERITY_ORDER : Severity [ ] = [ "critical" , "high" , "medium" , "low" , "negligible" ] ;
63
+ if ( ! minSeverity || minSeverity === "negligible" ) {
64
+ return SEVERITY_ORDER ;
65
+ }
66
+ const minIndex = SEVERITY_ORDER . indexOf ( minSeverity ) ;
67
+ return minIndex >= 0 ? SEVERITY_ORDER . slice ( 0 , minIndex + 1 ) : SEVERITY_ORDER ;
68
+ }
69
+
70
+ // Updated summary function
71
+ function addVulnTableToSummary (
72
+ data : Report ,
73
+ minSeverity ?: Severity
74
+ ) {
75
+ const pkgs = data . result . packages ;
76
+ const visibleSeverities = getVisibleSeverities ( minSeverity ) ;
77
+
78
+ const totalVulns = countVulnsBySeverity ( pkgs , visibleSeverities ) ;
31
79
32
80
core . summary . addHeading ( `Vulnerabilities summary` , 2 ) ;
33
81
core . summary . addTable ( [
34
82
[
35
83
{ 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 }
84
+ ...visibleSeverities . map ( s => ( { data : SEVERITY_LABELS [ s ] , header : true } ) )
41
85
] ,
42
86
[
43
87
{ 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 } `
88
+ ...visibleSeverities . map ( s => `${ totalVulns . total [ s ] ?? 0 } ` )
49
89
] ,
50
90
[
51
91
{ 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 } `
92
+ ...visibleSeverities . map ( s => `${ totalVulns . fixable [ s ] ?? 0 } ` )
57
93
] ,
58
94
] ) ;
59
95
}
@@ -166,7 +202,7 @@ function addReportToSummary(data: Report) {
166
202
core . summary . addHeading ( `Rule Bundle: ${ bundle . name } ` , 4 )
167
203
168
204
bundle . rules . forEach ( rule => {
169
- core . summary . addHeading ( `${ EVALUATION [ rule . evaluationResult ] } Rule: ${ rule . description } ` , 5 )
205
+ core . summary . addHeading ( `Rule: ${ rule . description } ` , 5 )
170
206
171
207
if ( rule . evaluationResult != "passed" ) {
172
208
if ( rule . failureType == "pkgVulnFailure" ) {
0 commit comments