Skip to content

Commit 88330de

Browse files
authored
Merge pull request #1302 from okorach:fix-1301
Fixes #1301
2 parents 50e38e6 + 0d08034 commit 88330de

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

sonar/projects.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,13 @@ def get_type(self) -> str:
550550
return "CLI"
551551
return "UNKNOWN"
552552

553+
def last_task(self) -> Optional[tasks.Task]:
554+
"""Returns the last analysis background task of a problem, or none if not found"""
555+
return tasks.search_last(component_key=self.key, endpoint=self.endpoint, type="REPORT")
556+
553557
def scanner(self) -> str:
554558
"""Returns the project type (MAVEN, GRADLE, DOTNET, OTHER, UNKNOWN)"""
555-
last_task = tasks.search_last(component_key=self.key, endpoint=self.endpoint)
559+
last_task = self.last_task()
556560
if not last_task:
557561
return "UNKNOWN"
558562
last_task.concerned_object = self

sonar/tasks.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def audit(self, audit_settings: types.ConfigSettings) -> list[Problem]:
514514
return problems
515515

516516

517-
def search(endpoint: pf.Platform, only_current: bool = False, component_key: str = None) -> list[Task]:
517+
def search(endpoint: pf.Platform, only_current: bool = False, component_key: str = None, **kwargs) -> list[Task]:
518518
"""Searches background tasks
519519
520520
:param Platform endpoint: Reference to the SonarQube platform
@@ -525,6 +525,7 @@ def search(endpoint: pf.Platform, only_current: bool = False, component_key: str
525525
:rtype: list[Task]
526526
"""
527527
params = {"status": ",".join(STATUSES), "additionalFields": "warnings"}
528+
params.update(**kwargs)
528529
if only_current:
529530
params["onlyCurrents"] = "true"
530531
if component_key is not None:
@@ -538,11 +539,12 @@ def search_all_last(endpoint: pf.Platform) -> list[Task]:
538539
return search(endpoint=endpoint, only_current=True)
539540

540541

541-
def search_last(endpoint: pf.Platform, component_key: str) -> Optional[Task]:
542+
def search_last(endpoint: pf.Platform, component_key: str, **params) -> Optional[Task]:
542543
"""Searches for last background task of a component"""
543-
bg_tasks = search(endpoint=endpoint, only_current=True, component_key=component_key)
544+
bg_tasks = search(endpoint=endpoint, only_current=True, component_key=component_key, **params)
544545
if len(bg_tasks) == 0:
545546
# No bgtask was found
547+
log.debug("No background task found for %s", component_key)
546548
return None
547549
return bg_tasks[0]
548550

0 commit comments

Comments
 (0)