@@ -78,12 +78,14 @@ def _json(self, components: list) -> Dict[str, Any]:
7878 :param components: List of components with copyleft licenses
7979 :return: Dictionary with formatted JSON details and summary
8080 """
81+ # A component is considered unique by its combination of PURL (Package URL) and license
82+ component_licenses = self ._group_components_by_license (components )
8183 details = {}
8284 if len (components ) > 0 :
8385 details = {'components' : components }
8486 return {
8587 'details' : f'{ json .dumps (details , indent = 2 )} \n ' ,
86- 'summary' : f'{ len (components )} component(s) with copyleft licenses were found.\n ' ,
88+ 'summary' : f'{ len (component_licenses )} component(s) with copyleft licenses were found.\n ' ,
8789 }
8890
8991 def _markdown (self , components : list ) -> Dict [str , Any ]:
@@ -93,24 +95,24 @@ def _markdown(self, components: list) -> Dict[str, Any]:
9395 :param components: List of components with copyleft licenses
9496 :return: Dictionary with formatted Markdown details and summary
9597 """
96- headers = ['Component' , 'Version' , 'License' , 'URL' , 'Copyleft' ]
98+ # A component is considered unique by its combination of PURL (Package URL) and license
99+ component_licenses = self ._group_components_by_license (components )
100+ headers = ['Component' , 'License' , 'URL' , 'Copyleft' ]
97101 centered_columns = [1 , 4 ]
98102 rows : [[]] = []
99- for component in components :
100- for lic in component ['licenses' ]:
103+ for comp_lic_item in component_licenses :
101104 row = [
102- component ['purl' ],
103- component ['version' ],
104- lic ['spdxid' ],
105- lic ['url' ],
106- 'YES' if lic ['copyleft' ] else 'NO' ,
105+ comp_lic_item ['purl' ],
106+ comp_lic_item ['spdxid' ],
107+ comp_lic_item ['url' ],
108+ 'YES' if comp_lic_item ['copyleft' ] else 'NO' ,
107109 ]
108110 rows .append (row )
109111 # End license loop
110112 # End component loop
111113 return {
112114 'details' : f'### Copyleft licenses\n { self .generate_table (headers , rows , centered_columns )} \n ' ,
113- 'summary' : f'{ len (components )} component(s) with copyleft licenses were found.\n ' ,
115+ 'summary' : f'{ len (component_licenses )} component(s) with copyleft licenses were found.\n ' ,
114116 }
115117
116118 def _jira_markdown (self , components : list ) -> Dict [str , Any ]:
@@ -120,24 +122,24 @@ def _jira_markdown(self, components: list) -> Dict[str, Any]:
120122 :param components: List of components with copyleft licenses
121123 :return: Dictionary with formatted Markdown details and summary
122124 """
123- headers = ['Component' , 'Version' , 'License' , 'URL' , 'Copyleft' ]
125+ # A component is considered unique by its combination of PURL (Package URL) and license
126+ component_licenses = self ._group_components_by_license (components )
127+ headers = ['Component' , 'License' , 'URL' , 'Copyleft' ]
124128 centered_columns = [1 , 4 ]
125129 rows : [[]] = []
126- for component in components :
127- for lic in component ['licenses' ]:
130+ for comp_lic_item in component_licenses :
128131 row = [
129- component ['purl' ],
130- component ['version' ],
131- lic ['spdxid' ],
132- lic ['url' ],
133- 'YES' if lic ['copyleft' ] else 'NO' ,
132+ comp_lic_item ['purl' ],
133+ comp_lic_item ['spdxid' ],
134+ comp_lic_item ['url' ],
135+ 'YES' if comp_lic_item ['copyleft' ] else 'NO' ,
134136 ]
135137 rows .append (row )
136138 # End license loop
137139 # End component loop
138140 return {
139141 'details' : f'{ self .generate_jira_table (headers , rows , centered_columns )} ' ,
140- 'summary' : f'{ len (components )} component(s) with copyleft licenses were found.\n ' ,
142+ 'summary' : f'{ len (component_licenses )} component(s) with copyleft licenses were found.\n ' ,
141143 }
142144
143145 def _filter_components_with_copyleft_licenses (self , components : list ) -> list :
@@ -161,7 +163,6 @@ def _filter_components_with_copyleft_licenses(self, components: list) -> list:
161163 lic .pop ('count' , None ) # None is default value if key doesn't exist
162164
163165 filtered_component ['licenses' ] = copyleft_licenses
164- del filtered_component ['status' ]
165166 filtered_components .append (filtered_component )
166167 # End component loop
167168 self .print_debug (f'Copyleft components: { filtered_components } ' )
0 commit comments