@@ -53,44 +53,43 @@ function getIPAFromIPARule(ipaRule) {
5353}
5454
5555export function merge ( ownershipData , collectorResults , ruleSeverityMap ) {
56- const results = [ ] ;
56+ function mapResults ( entry , adoptionStatus ) {
57+ let ownerTeam = null ;
58+ if ( entry . componentId . startsWith ( 'paths' ) ) {
59+ const pathParts = entry . componentId . split ( '.' ) ;
60+ if ( pathParts . length === 2 ) {
61+ const path = pathParts [ 1 ] ;
62+ ownerTeam = ownershipData [ path ] ;
63+ }
64+ }
5765
58- function addEntry ( entryType , adoptionStatus ) {
59- for ( const entry of collectorResults [ entryType ] ) {
60- const existing = results . find (
61- ( result ) => result . component_id === entry . componentId && result . ipa_rule === entry . ruleName
62- ) ;
66+ return {
67+ component_id : entry . componentId ,
68+ ipa_rule : entry . ruleName ,
69+ ipa : getIPAFromIPARule ( entry . ruleName ) ,
70+ severity_level : ruleSeverityMap [ entry . ruleName ] ,
71+ adoption_status : adoptionStatus ,
72+ exception_reason : adoptionStatus === 'exempted' && entry . exceptionReason ? entry . exceptionReason : null ,
73+ owner_team : ownerTeam ,
74+ timestamp : new Date ( ) . toISOString ( ) ,
75+ } ;
76+ }
6377
64- if ( existing ) {
65- console . warn ( 'Duplicate entries found' , existing ) ;
66- continue ;
67- }
78+ const violations = collectorResults [ EntryType . VIOLATION ] || [ ] ;
79+ const adoptions = collectorResults [ EntryType . ADOPTION ] || [ ] ;
80+ const exceptions = collectorResults [ EntryType . EXCEPTION ] || [ ] ;
6881
69- let ownerTeam = null ;
70- if ( entry . componentId . startsWith ( 'paths' ) ) {
71- const pathParts = entry . componentId . split ( '.' ) ;
72- if ( pathParts . length === 2 ) {
73- const path = pathParts [ 1 ] ;
74- ownerTeam = ownershipData [ path ] ;
75- }
76- }
82+ console . log ( '\tMerging violations (total ' + violations . length + ')' ) ;
83+ const violationResults = violations . map ( ( entry ) => mapResults ( entry , 'violated' ) ) ;
7784
78- results . push ( {
79- component_id : entry . componentId ,
80- ipa_rule : entry . ruleName ,
81- ipa : getIPAFromIPARule ( entry . ruleName ) ,
82- severity_level : ruleSeverityMap [ entry . ruleName ] ,
83- adoption_status : adoptionStatus ,
84- exception_reason : entryType === EntryType . EXCEPTION ? entry . exceptionReason : null ,
85- owner_team : ownerTeam ,
86- timestamp : new Date ( ) . toISOString ( ) ,
87- } ) ;
88- }
89- }
85+ console . log ( '\tMerging adoptions (total ' + adoptions . length + ')' ) ;
86+ const adoptionResults = adoptions . map ( ( entry ) => mapResults ( entry , 'adopted' ) ) ;
9087
91- addEntry ( EntryType . VIOLATION , 'violated' ) ;
92- addEntry ( EntryType . ADOPTION , 'adopted' ) ;
93- addEntry ( EntryType . EXCEPTION , 'exempted' ) ;
88+ console . log ( '\tMerging exceptions (total ' + exceptions . length + ')' ) ;
89+ const exceptionResults = exceptions . map ( ( entry ) => mapResults ( entry , 'exempted' ) ) ;
9490
95- return results ;
91+ console . log (
92+ '\tMerging complete. Total entries: ' + ( violationResults . length + adoptionResults . length + exceptionResults . length )
93+ ) ;
94+ return [ ...violationResults , ...adoptionResults , ...exceptionResults ] ;
9695}
0 commit comments