Skip to content

Commit 6e79b18

Browse files
committed
Fixes #1334
1 parent 48444ed commit 6e79b18

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

sonar/branches.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ def export(self, export_settings: types.ConfigSettings) -> types.ObjectJsonRepr:
220220
:return: The branch new code period definition
221221
:rtype: str
222222
"""
223-
from sonar import issues
223+
from sonar.issues import count as issue_count
224+
from sonar.hotspots import count as hotspot_count
224225

225226
log.debug("Exporting %s", str(self))
226227
data = {settings.NEW_CODE_PERIOD: self.new_code()}
@@ -243,16 +244,26 @@ def export(self, export_settings: types.ConfigSettings) -> types.ObjectJsonRepr:
243244
if export_settings.get("MODE", "") == "MIGRATION":
244245
tpissues = self.count_third_party_issues()
245246
issue_data = {"thirdParty": tpissues if len(tpissues) > 0 else 0}
247+
proj_key = self.concerned_object.key
246248
if self.endpoint.version() >= (10, 0, 0):
247-
issue_data["falsePositives"] = issues.count(
248-
self.endpoint, components=self.concerned_object.key, branch=self.name, issueStatuses="FALSE_POSITIVE"
249-
)
250-
issue_data["accepted"] = issues.count(self.endpoint, components=self.concerned_object.key, branch=self.name, issueStatuses="ACCEPTED")
249+
params = {"components": proj_key, "branch": self.name}
250+
data["issues"] = {
251+
"falsePositives": issue_count(self.endpoint, issueStatuses="FALSE_POSITIVE", **params),
252+
"accepted": issue_count(self.endpoint, issueStatuses="ACCEPTED", **params),
253+
}
254+
params = {"project": proj_key, "branch": self.name}
251255
else:
252-
issue_data["falsePositives"] = issues.count(
253-
self.endpoint, componentKeys=self.concerned_object.key, branch=self.name, resolutions="FALSE-POSITIVE"
254-
)
255-
issue_data["wontFix"] = issues.count(self.endpoint, componentKeys=self.concerned_object.key, branch=self.name, resolutions="WONTFIX")
256+
params = {"componentKeys": proj_key, "branch": self.name}
257+
data["issues"] = {
258+
"falsePositives": issue_count(self.endpoint, resolutions="FALSE-POSITIVE", **params),
259+
"wontFix": issue_count(self.endpoint, resolutions="WONTFIX", **params),
260+
}
261+
params = {"projectKey": proj_key, "branch": self.name}
262+
data["hotspots"] = {
263+
"acknowledged": hotspot_count(self.endpoint, resolution="ACKNOWLEDGED", **params),
264+
"safe": hotspot_count(self.endpoint, resolution="SAFE", **params),
265+
"fixed": hotspot_count(self.endpoint, resolution="FIXED", **params),
266+
}
256267
data["issues"] = issue_data
257268
log.debug("%s has these notable issues %s", str(self), str(data["issues"]))
258269
data = util.remove_nones(data)

sonar/hotspots.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,12 @@ def post_search_filter(hotspots_dict: dict[str, Hotspot], filters: types.ApiPara
491491
filtered_findings.pop(key, None)
492492

493493
return filtered_findings
494+
495+
496+
def count(endpoint: pf.Platform, **kwargs) -> int:
497+
"""Returns number of hotspots of a search"""
498+
params = {} if not kwargs else kwargs.copy()
499+
params["ps"] = 1
500+
nbr_hotspots = len(search(endpoint=endpoint, filters=params))
501+
log.debug("Hotspot counts with filters %s is %d hotspots", str(kwargs), nbr_hotspots)
502+
return nbr_hotspots

sonar/projects.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,8 @@ def export(self, export_settings: types.ConfigSettings, settings_list: dict[str,
953953
:return: All project configuration settings
954954
:rtype: dict
955955
"""
956-
from sonar import issues
956+
from sonar.issues import count as issue_count
957+
from sonar.hotspots import count as hotspot_count
957958

958959
log.info("Exporting %s", str(self))
959960
try:
@@ -999,12 +1000,19 @@ def export(self, export_settings: types.ConfigSettings, settings_list: dict[str,
9991000
tpissues = self.count_third_party_issues()
10001001
issue_data = {"thirdParty": tpissues if len(tpissues) > 0 else 0}
10011002
if self.endpoint.version() >= (10, 0, 0):
1002-
issue_data["falsePositives"] = issues.count(self.endpoint, components=self.key, issueStatuses="FALSE_POSITIVE")
1003-
issue_data["accepted"] = issues.count(self.endpoint, components=self.key, issueStatuses="ACCEPTED")
1003+
issue_data["falsePositives"] = issue_count(self.endpoint, components=self.key, issueStatuses="FALSE_POSITIVE")
1004+
issue_data["accepted"] = issue_count(self.endpoint, components=self.key, issueStatuses="ACCEPTED")
1005+
params = {"project": self.key}
10041006
else:
1005-
issue_data["falsePositives"] = issues.count(self.endpoint, componentKeys=self.key, resolutions="FALSE-POSITIVE")
1006-
issue_data["wontFix"] = issues.count(self.endpoint, componentKeys=self.key, resolutions="WONTFIX")
1007+
issue_data["falsePositives"] = issue_count(self.endpoint, componentKeys=self.key, resolutions="FALSE-POSITIVE")
1008+
issue_data["wontFix"] = issue_count(self.endpoint, componentKeys=self.key, resolutions="WONTFIX")
1009+
params = {"projectKey": self.key}
10071010
json_data["issues"] = issue_data
1011+
json_data["hotspots"] = {
1012+
"acknowledged": hotspot_count(self.endpoint, resolution="ACKNOWLEDGED", **params),
1013+
"safe": hotspot_count(self.endpoint, resolution="SAFE", **params),
1014+
"fixed": hotspot_count(self.endpoint, resolution="FIXED", **params),
1015+
}
10081016
log.debug("%s has these notable issues %s", str(self), str(json_data["issues"]))
10091017

10101018
settings_dict = settings.get_bulk(endpoint=self.endpoint, component=self, settings_list=settings_list, include_not_set=False)

0 commit comments

Comments
 (0)