@@ -299,34 +299,37 @@ export default class SecurityBlog extends SecurityRelease {
299299 }
300300
301301 getImpact ( content ) {
302- const impact = content . reports . reduce ( ( acc , report ) => {
303- for ( const affectedVersion of report . affectedVersions ) {
304- if ( acc [ affectedVersion ] ) {
305- acc [ affectedVersion ] . push ( report ) ;
306- } else {
307- acc [ affectedVersion ] = [ report ] ;
308- }
302+ const impact = new Map ( ) ;
303+ for ( const report of content . reports ) {
304+ for ( const version of report . affectedVersions ) {
305+ if ( ! impact . has ( version ) ) impact . set ( version , [ ] ) ;
306+ impact . get ( version ) . push ( report ) ;
309307 }
310- return acc ;
311- } , { } ) ;
312-
313- const impactText = [ ] ;
314- for ( const [ key , value ] of Object . entries ( impact ) ) {
315- const groupedByRating = Object . values ( _ . groupBy ( value , 'severity.rating' ) )
316- . map ( severity => {
317- if ( ! severity [ 0 ] ?. severity ?. rating ) {
318- this . cli . error ( `severity.rating not found for the report ${ severity [ 0 ] . id } . \
319- Please add it manually before continuing.` ) ;
308+ }
309+
310+ const result = Array . from ( impact . entries ( ) )
311+ . sort ( ( [ a ] , [ b ] ) => b . localeCompare ( a ) ) // DESC
312+ . map ( ( [ version , reports ] ) => {
313+ const severityCount = new Map ( ) ;
314+
315+ for ( const report of reports ) {
316+ const rating = report . severity . rating ?. toLowerCase ( ) ;
317+ if ( ! rating ) {
318+ this . cli . error ( `severity.rating not found for report ${ report . id } .` ) ;
320319 process . exit ( 1 ) ;
321320 }
322- const firstSeverityRating = severity [ 0 ] . severity . rating . toLocaleLowerCase ( ) ;
323- return `${ severity . length } ${ firstSeverityRating } severity issues` ;
324- } ) . join ( ', ' ) ;
321+ severityCount . set ( rating , ( severityCount . get ( rating ) || 0 ) + 1 ) ;
322+ }
325323
326- impactText . push ( `The ${ key } release line of Node.js is vulnerable to ${ groupedByRating } .` ) ;
327- }
324+ const groupedByRating = Array . from ( severityCount . entries ( ) )
325+ . map ( ( [ rating , count ] ) => `${ count } ${ rating } severity issues` )
326+ . join ( ', ' ) ;
327+
328+ return `The ${ version } release line of Node.js is vulnerable to ${ groupedByRating } .` ;
329+ } )
330+ . join ( '\n' ) ;
328331
329- return impactText . join ( '\n' ) ;
332+ return result ;
330333 }
331334
332335 getVulnerabilities ( content ) {
0 commit comments