@@ -157,15 +157,45 @@ def trim_version_report(version_report, reduced_path_set):
157
157
reduced_aggregate_bom_view_entries = [e for e in aggregate_bom_view_entries if f"{ e ['producerProject' ]['id' ]} :{ e ['producerReleases' ][0 ]['id' ]} " in deduplicated ]
158
158
version_report ['aggregateBomViewEntries' ] = reduced_aggregate_bom_view_entries
159
159
160
+ '''
161
+
162
+ CSV output details
163
+
164
+ component name = aggregateBomViewEntries[].producerProject.name
165
+ version name = aggregateBomViewEntries[].producerReleases[0].version
166
+ license = licenses[].licenseDisplay
167
+ file path = extract from detailedFileBomViewEntries
168
+ match type = aggregateBomViewEntries[].matchTypes
169
+ review status = aggregateBomViewEntries[].reviewSummary.reviewStatus
170
+
171
+ '''
172
+ def get_csv_fieldnames ():
173
+ return ['component name' , 'version name' , 'license' , 'file path' , 'match type' , 'review status' ]
174
+
175
+ def get_csv_data (version_report ):
176
+ csv_data = list ()
177
+ for bom_view_entry in version_report ['aggregateBomViewEntries' ]:
178
+ entry = dict ()
179
+ entry ['component name' ] = bom_view_entry ['producerProject' ]['name' ]
180
+ entry ['version name' ] = bom_view_entry ['producerReleases' ][0 ]['version' ]
181
+ entry ['license' ] = bom_view_entry ['licenses' ][0 ]['licenseDisplay' ].replace (' AND ' ,';' ).replace ('(' ,'' ).replace (')' ,'' )
182
+ pid = bom_view_entry ['producerProject' ]['id' ]
183
+ vid = bom_view_entry ['producerReleases' ][0 ]['id' ]
184
+ path_list = [p ['path' ] for p in version_report ['detailedFileBomViewEntries' ] if p ['projectId' ] == pid and p ['versionId' ] == vid ]
185
+ entry ['file path' ] = ';' .join (path_list )
186
+ entry ['match type' ] = ';' .join (bom_view_entry ['matchTypes' ])
187
+ entry ['review status' ] = bom_view_entry ['reviewSummary' ]['reviewStatus' ]
188
+ csv_data .append (entry )
189
+ return csv_data
190
+
160
191
def write_output_file (version_report , output_file ):
161
192
if output_file .lower ().endswith (".csv" ):
162
193
logging .info (f"Writing CSV output into { output_file } " )
163
- field_names = list ( version_report [ 'aggregateBomViewEntries' ][ 0 ]. keys () )
194
+ field_names = get_csv_fieldnames ( )
164
195
with open (output_file , "w" ) as f :
165
196
writer = csv .DictWriter (f , fieldnames = field_names , extrasaction = 'ignore' ) # TODO
166
197
writer .writeheader ()
167
- writer .writerows (version_report ['aggregateBomViewEntries' ])
168
-
198
+ writer .writerows (get_csv_data (version_report ))
169
199
return
170
200
# If it's neither, then .json
171
201
if not output_file .lower ().endswith (".json" ):
0 commit comments