@@ -135,6 +135,26 @@ function configureGlobalProxy(proxyUrl) {
135
135
} ) ;
136
136
}
137
137
138
+ function countFailingVulnerabilities ( failThreshold , foundCounts , ignoredCounts ) {
139
+ let count = foundCounts . critical - ignoredCounts . critical ;
140
+ if ( failThreshold === 'critical' ) {
141
+ return count ;
142
+ }
143
+ count += foundCounts . high - ignoredCounts . high ;
144
+ if ( failThreshold === 'high' ) {
145
+ return count ;
146
+ }
147
+ count += foundCounts . medium - ignoredCounts . medium ;
148
+ if ( failThreshold === 'medium' ) {
149
+ return count ;
150
+ }
151
+ count += foundCounts . low - ignoredCounts . low ;
152
+ if ( failThreshold === 'low' ) {
153
+ return count ;
154
+ }
155
+ return count + foundCounts . informational - ignoredCounts . informational ;
156
+ }
157
+
138
158
const main = async ( ) => {
139
159
core . debug ( 'Entering main' )
140
160
const repository = core . getInput ( 'repository' , { required : true } )
@@ -247,12 +267,11 @@ const main = async () => {
247
267
console . log ( '=================' )
248
268
console . log ( `${ total . toString ( ) . padStart ( 3 , ' ' ) } Total ${ getCount ( 'total' , ignoredCounts ) } ` )
249
269
250
- const numFailingVulns =
251
- failThreshold === 'informational' ? total - ignoredCounts . informational
252
- : failThreshold === 'low' ? critical + high + medium + low - ignoredCounts . low
253
- : failThreshold === 'medium' ? critical + high + medium - ignoredCounts . medium
254
- : failThreshold === 'high' ? critical + high - ignoredCounts . high
255
- : /* failThreshold === 'critical' ? */ critical - ignoredCounts . critical
270
+ const numFailingVulns = countFailingVulnerabilities (
271
+ failThreshold ,
272
+ { informational, low, medium, high, critical } ,
273
+ ignoredCounts ,
274
+ )
256
275
257
276
if ( numFailingVulns > 0 ) {
258
277
throw new Error ( `Detected ${ numFailingVulns } vulnerabilities with severity >= ${ failThreshold } (the currently configured fail_threshold).` )
0 commit comments