@@ -281,34 +281,37 @@ export default class SecurityBlog extends SecurityRelease {
281281 }
282282
283283 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 ) ;
291289 }
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 } .` ) ;
302301 process . exit ( 1 ) ;
303302 }
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+ }
307305
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' ) ;
310313
311- return impactText . join ( '\n' ) ;
314+ return result ;
312315 }
313316
314317 getVulnerabilities ( content ) {
0 commit comments