diff --git a/sonar/branches.py b/sonar/branches.py index ac9c3d0ca..14b4f7656 100644 --- a/sonar/branches.py +++ b/sonar/branches.py @@ -220,6 +220,8 @@ def export(self, export_settings: types.ConfigSettings) -> types.ObjectJsonRepr: :return: The branch new code period definition :rtype: str """ + from sonar import issues + log.debug("Exporting %s", str(self)) data = {settings.NEW_CODE_PERIOD: self.new_code()} if self.is_main(): @@ -238,6 +240,21 @@ def export(self, export_settings: types.ConfigSettings) -> types.ObjectJsonRepr: loc_distrib = {m.split("=")[0]: int(m.split("=")[1]) for m in lang_distrib.split(";")} loc_distrib["total"] = self.loc() data["ncloc"] = loc_distrib + if export_settings["MODE"] == "MIGRATION": + tpissues = self.count_third_party_issues() + issue_data = {"thirdParty": tpissues if len(tpissues) > 0 else 0} + if self.endpoint.version() >= (10, 0, 0): + issue_data["falsePositives"] = issues.count( + self.endpoint, components=self.concerned_object.key, branch=self.name, issueStatuses="FALSE_POSITIVE" + ) + issue_data["accepted"] = issues.count(self.endpoint, components=self.concerned_object.key, branch=self.name, issueStatuses="ACCEPTED") + else: + issue_data["falsePositives"] = issues.count( + self.endpoint, componentKeys=self.concerned_object.key, branch=self.name, resolutions="FALSE-POSITIVE" + ) + issue_data["wontFix"] = issues.count(self.endpoint, componentKeys=self.concerned_object.key, branch=self.name, resolutions="WONTFIX") + data["issues"] = issue_data + log.debug("%s has these notable issues %s", str(self), str(data["issues"])) data = util.remove_nones(data) return None if len(data) == 0 else data diff --git a/sonar/projects.py b/sonar/projects.py index 69be5d74b..85f46ff77 100644 --- a/sonar/projects.py +++ b/sonar/projects.py @@ -953,6 +953,8 @@ def export(self, export_settings: types.ConfigSettings, settings_list: dict[str, :return: All project configuration settings :rtype: dict """ + from sonar import issues + log.info("Exporting %s", str(self)) try: json_data = self._json.copy() @@ -994,8 +996,16 @@ def export(self, export_settings: types.ConfigSettings, settings_list: dict[str, "lastTaskWarnings": last_task.warnings(), "taskHistory": [t._json for t in self.task_history()], } - json_data["thirdPartyIssues"] = self.count_third_party_issues() - log.debug("%s has %d 3rd party issues", str(self), sum(v for v in json_data["thirdPartyIssues"].values())) + tpissues = self.count_third_party_issues() + issue_data = {"thirdParty": tpissues if len(tpissues) > 0 else 0} + if self.endpoint.version() >= (10, 0, 0): + issue_data["falsePositives"] = issues.count(self.endpoint, components=self.key, issueStatuses="FALSE_POSITIVE") + issue_data["accepted"] = issues.count(self.endpoint, components=self.key, issueStatuses="ACCEPTED") + else: + issue_data["falsePositives"] = issues.count(self.endpoint, componentKeys=self.key, resolutions="FALSE-POSITIVE") + issue_data["wontFix"] = issues.count(self.endpoint, componentKeys=self.key, resolutions="WONTFIX") + json_data["issues"] = issue_data + log.debug("%s has these notable issues %s", str(self), str(json_data["issues"])) settings_dict = settings.get_bulk(endpoint=self.endpoint, component=self, settings_list=settings_list, include_not_set=False) # json_data.update({s.to_json() for s in settings_dict.values() if include_inherited or not s.inherited})