@@ -281,34 +281,37 @@ export default class SecurityBlog extends SecurityRelease {
281
281
}
282
282
283
283
getImpact ( content ) {
284
- const impact = content . reports . reduce ( ( acc , report ) => {
285
- for ( const affectedVersion of report . affectedVersions ) {
286
- if ( acc [ affectedVersion ] ) {
287
- acc [ affectedVersion ] . push ( report ) ;
288
- } else {
289
- acc [ affectedVersion ] = [ report ] ;
290
- }
284
+ const impact = new Map ( ) ;
285
+ for ( const report of content . reports ) {
286
+ for ( const version of report . affectedVersions ) {
287
+ if ( ! impact . has ( version ) ) impact . set ( version , [ ] ) ;
288
+ impact . get ( version ) . push ( report ) ;
291
289
}
292
- return acc ;
293
- } , { } ) ;
294
-
295
- const impactText = [ ] ;
296
- for ( const [ key , value ] of Object . entries ( impact ) ) {
297
- const groupedByRating = Object . values ( _ . groupBy ( value , 'severity.rating' ) )
298
- . map ( severity => {
299
- if ( ! severity [ 0 ] ?. severity ?. rating ) {
300
- this . cli . error ( `severity.rating not found for the report ${ severity [ 0 ] . id } . \
301
- Please add it manually before continuing.` ) ;
290
+ }
291
+
292
+ const result = Array . from ( impact . entries ( ) )
293
+ . sort ( ( [ a ] , [ b ] ) => b . localeCompare ( a ) ) // DESC
294
+ . map ( ( [ version , reports ] ) => {
295
+ const severityCount = new Map ( ) ;
296
+
297
+ for ( const report of reports ) {
298
+ const rating = report . severity . rating ?. toLowerCase ( ) ;
299
+ if ( ! rating ) {
300
+ this . cli . error ( `severity.rating not found for report ${ report . id } .` ) ;
302
301
process . exit ( 1 ) ;
303
302
}
304
- const firstSeverityRating = severity [ 0 ] . severity . rating . toLocaleLowerCase ( ) ;
305
- return `${ severity . length } ${ firstSeverityRating } severity issues` ;
306
- } ) . join ( ', ' ) ;
303
+ severityCount . set ( rating , ( severityCount . get ( rating ) || 0 ) + 1 ) ;
304
+ }
307
305
308
- impactText . push ( `The ${ key } release line of Node.js is vulnerable to ${ groupedByRating } .` ) ;
309
- }
306
+ const groupedByRating = Array . from ( severityCount . entries ( ) )
307
+ . map ( ( [ rating , count ] ) => `${ count } ${ rating } severity issues` )
308
+ . join ( ', ' ) ;
309
+
310
+ return `The ${ version } release line of Node.js is vulnerable to ${ groupedByRating } .` ;
311
+ } )
312
+ . join ( '\n' ) ;
310
313
311
- return impactText . join ( '\n' ) ;
314
+ return result ;
312
315
}
313
316
314
317
getVulnerabilities ( content ) {
0 commit comments