Skip to content

Commit 562717d

Browse files
authored
Merge pull request #1365 from okorach:fix-issues-search-mix-up-component-project
Fix-issues-search-mix-up-component-project
2 parents 476d30e + 820dd4d commit 562717d

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

cli/findings_export.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,21 @@ def __get_component_findings(queue: Queue[tuple[object, ConfigSettings]], write_
300300
write_queue.put([findings_list, False])
301301
else:
302302
new_params = params.copy()
303-
new_params.pop("sarifNoCustomProperties", None)
304-
new_params.pop(options.NBR_THREADS, None)
305-
new_params.pop(options.CSV_SEPARATOR, None)
306-
new_params.pop(options.COMPONENT_TYPE, None)
307-
new_params.pop(options.DATES_WITHOUT_TIME, None)
308-
new_params.pop(options.REPORT_FILE, None)
309-
new_params.pop(options.WITH_LAST_ANALYSIS, None)
310-
new_params.pop(options.WITH_URL, None)
303+
for p in (
304+
"sarifNoCustomProperties",
305+
options.NBR_THREADS,
306+
options.CSV_SEPARATOR,
307+
options.COMPONENT_TYPE,
308+
options.DATES_WITHOUT_TIME,
309+
options.REPORT_FILE,
310+
options.WITH_LAST_ANALYSIS,
311+
options.WITH_URL,
312+
options.HTTP_TIMEOUT,
313+
"http_timeout",
314+
options.LOGFILE,
315+
options.FORMAT,
316+
):
317+
new_params.pop(p, None)
311318
if options.PULL_REQUESTS in new_params:
312319
new_params["pullRequest"] = new_params.pop(options.PULL_REQUESTS)
313320
if options.BRANCHES in new_params:

sonar/hotspots.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ def to_json(self, without_time: bool = False) -> types.ObjectJsonRepr:
135135
data = super().to_json(without_time)
136136
if self.endpoint.version() >= (10, 2, 0):
137137
data["impacts"] = {"SECURITY": "UNDEFINED"}
138-
log.debug("Returning hotspot JSON data = %s", util.json_dump(data))
139138
return data
140139

141140
def refresh(self) -> bool:

sonar/issues.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,9 @@ def __search_all_by_severities(endpoint: pf.Platform, params: ApiParams) -> dict
597597
return issue_list
598598

599599

600-
def __search_all_by_date(endpoint: pf.Platform, params: ApiParams, date_start: date = None, date_stop: date = None) -> dict[str, Issue]:
600+
def __search_all_by_date(
601+
endpoint: pf.Platform, params: ApiParams, date_start: Optional[date] = None, date_stop: Optional[date] = None
602+
) -> dict[str, Issue]:
601603
"""Searches issues splitting by date windows to avoid exceeding the 10K limit"""
602604
new_params = params.copy()
603605
if date_start is None:
@@ -608,11 +610,15 @@ def __search_all_by_date(endpoint: pf.Platform, params: ApiParams, date_start: d
608610
date_stop = get_newest_issue(endpoint=endpoint, params=new_params).replace(hour=0, minute=0, second=0, microsecond=0)
609611
if isinstance(date_stop, datetime):
610612
date_stop = date_stop.date()
611-
log.info("Splitting search by date between [%s - %s]", util.date_to_string(date_start, False), util.date_to_string(date_stop, False))
612-
issue_list = {}
613-
new_params.update(
614-
{"createdAfter": util.date_to_string(date_start, with_time=False), "createdBefore": util.date_to_string(date_stop, with_time=False)}
613+
log.info(
614+
"Project '%s' Splitting search by date between [%s - %s]",
615+
params["project"],
616+
util.date_to_string(date_start, False),
617+
util.date_to_string(date_stop, False),
615618
)
619+
issue_list = {}
620+
new_params["createdAfter"] = util.date_to_string(date_start, with_time=False)
621+
new_params["createdBefore"] = util.date_to_string(date_stop, with_time=False)
616622
try:
617623
issue_list = search(endpoint=endpoint, params=new_params)
618624
except TooManyIssuesError as e:
@@ -631,8 +637,8 @@ def __search_all_by_date(endpoint: pf.Platform, params: ApiParams, date_start: d
631637
issue_list.update(__search_all_by_date(endpoint=endpoint, params=new_params, date_start=date_middle, date_stop=date_stop))
632638
if date_start is not None and date_stop is not None:
633639
log.debug(
634-
"Project %s has %d issues between %s and %s",
635-
new_params[component_filter(endpoint)],
640+
"Project '%s' has %d issues between %s and %s",
641+
params["project"],
636642
len(issue_list),
637643
util.date_to_string(date_start, False),
638644
util.date_to_string(date_stop, False),
@@ -643,7 +649,7 @@ def __search_all_by_date(endpoint: pf.Platform, params: ApiParams, date_start: d
643649
def __search_all_by_project(endpoint: pf.Platform, project_key: str, params: ApiParams = None) -> dict[str, Issue]:
644650
"""Search issues by project"""
645651
new_params = {} if params is None else params.copy()
646-
new_params[component_filter(endpoint)] = project_key
652+
new_params["project"] = project_key
647653
issue_list = {}
648654
log.debug("Searching for issues of project '%s'", project_key)
649655
try:
@@ -693,17 +699,22 @@ def search_all(endpoint: pf.Platform, params: ApiParams = None) -> dict[str, Iss
693699
:rtype: dict{<key>: <Issue>}
694700
"""
695701
issue_list = {}
702+
new_params = params.copy() if params else {}
703+
new_params["ps"] = Issue.MAX_PAGE_SIZE
696704
try:
697-
issue_list = search(endpoint=endpoint, params=params)
705+
issue_list = search(endpoint=endpoint, params=new_params.copy())
698706
except TooManyIssuesError:
699707
log.info(_TOO_MANY_ISSUES_MSG)
700708
comp_filter = component_filter(endpoint)
701-
if params and comp_filter in params:
709+
if params and "project" in params:
710+
key_list = util.csv_to_list(params["project"])
711+
elif params and comp_filter in params:
702712
key_list = util.csv_to_list(params[comp_filter])
703713
else:
704714
key_list = projects.search(endpoint).keys()
705715
for k in key_list:
706-
issue_list.update(__search_all_by_project(endpoint=endpoint, project_key=k, params=params))
716+
issue_list.update(__search_all_by_project(endpoint=endpoint, project_key=k, params=new_params))
717+
log.debug("SEARCH ALL %s returns %d issues", str(params), len(issue_list))
707718
return issue_list
708719

709720

@@ -750,7 +761,7 @@ def search(endpoint: pf.Platform, params: ApiParams = None, raise_error: bool =
750761
:rtype: dict{<key>: <Issue>}
751762
:raises: TooManyIssuesError if more than 10'000 issues found
752763
"""
753-
filters = pre_search_filters(endpoint=endpoint, params=params)
764+
filters = pre_search_filters(endpoint=endpoint, params=params.copy())
754765
if "ps" not in filters:
755766
filters["ps"] = Issue.MAX_PAGE_SIZE
756767

@@ -774,8 +785,9 @@ def search(endpoint: pf.Platform, params: ApiParams = None, raise_error: bool =
774785
if nbr_pages == 1:
775786
return issue_list
776787
q = Queue(maxsize=0)
788+
prepared_params = pre_search_filters(endpoint=endpoint, params=params)
777789
for page in range(2, nbr_pages + 1):
778-
q.put((endpoint, Issue.SEARCH_API, issue_list, filters, page))
790+
q.put((endpoint, Issue.SEARCH_API, issue_list, prepared_params, page))
779791
for i in range(threads):
780792
log.debug("Starting issue search thread %d", i)
781793
worker = Thread(target=__search_thread, args=[q])

0 commit comments

Comments
 (0)