4242from sonar .util import types
4343
4444from sonar import exceptions , errcodes
45- from sonar import sqobject , components , qualitygates , qualityprofiles , tasks , settings , webhooks , devops , syncer
45+ from sonar import sqobject , components , qualitygates , qualityprofiles , rules , tasks , settings , webhooks , devops , syncer
4646import sonar .permissions .permissions as perms
4747from sonar import pull_requests , branches
4848import sonar .utilities as util
@@ -783,6 +783,20 @@ def get_issues(self, filters: dict[str, str] = None) -> dict[str, object]:
783783 findings_list = {** findings_list , ** comp .get_issues ()}
784784 return findings_list
785785
786+ def count_third_party_issues (self , filters : dict [str , str ] = None ) -> dict [str , int ]:
787+ branches_or_prs = self .get_branches_and_prs (filters )
788+ if branches_or_prs is None :
789+ return super ().count_third_party_issues (filters )
790+ issue_counts = {}
791+ for comp in branches_or_prs .values ():
792+ if not comp :
793+ continue
794+ for k , total in comp .count_third_party_issues (filters ):
795+ if k not in issue_counts :
796+ issue_counts [k ] = 0
797+ issue_counts [k ] += total
798+ return issue_counts
799+
786800 def __sync_community (self , another_project : object , sync_settings : types .ConfigSettings ) -> tuple [list [dict [str , str ]], dict [str , int ]]:
787801 """Syncs 2 projects findings on a community edition"""
788802 report , counters = [], {}
@@ -960,7 +974,7 @@ def export(self, export_settings: types.ConfigSettings, settings_list: dict[str,
960974 json_data ["webhooks" ] = hooks
961975 json_data = util .filter_export (json_data , _IMPORTABLE_PROPERTIES , export_settings .get ("FULL_EXPORT" , False ))
962976
963- if export_settings [ "MODE" ] == "MIGRATION" :
977+ if export_settings . get ( "MODE" , "" ) == "MIGRATION" :
964978 json_data ["lastAnalysis" ] = util .date_to_string (self .last_analysis ())
965979 json_data ["detectedCi" ] = self .ci ()
966980 json_data ["revision" ] = self .revision ()
@@ -978,6 +992,8 @@ def export(self, export_settings: types.ConfigSettings, settings_list: dict[str,
978992 "lastTaskWarnings" : last_task .warnings (),
979993 "taskHistory" : [t ._json for t in self .task_history ()],
980994 }
995+ json_data ["thirdPartyIssues" ] = self .count_third_party_issues ()
996+ log .info ("%s has %d 3rd party issues" , str (self ), sum (v for v in json_data ["thirdPartyIssues" ].values ()))
981997
982998 settings_dict = settings .get_bulk (endpoint = self .endpoint , component = self , settings_list = settings_list , include_not_set = False )
983999 # json_data.update({s.to_json() for s in settings_dict.values() if include_inherited or not s.inherited})
0 commit comments