Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sonar/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,13 @@ def get_type(self) -> str:
return "CLI"
return "UNKNOWN"

def last_task(self) -> Optional[tasks.Task]:
"""Returns the last analysis background task of a problem, or none if not found"""
return tasks.search_last(component_key=self.key, endpoint=self.endpoint, type="REPORT")

def scanner(self) -> str:
"""Returns the project type (MAVEN, GRADLE, DOTNET, OTHER, UNKNOWN)"""
last_task = tasks.search_last(component_key=self.key, endpoint=self.endpoint)
last_task = self.last_task()
if not last_task:
return "UNKNOWN"
last_task.concerned_object = self
Expand Down
8 changes: 5 additions & 3 deletions sonar/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def audit(self, audit_settings: types.ConfigSettings) -> list[Problem]:
return problems


def search(endpoint: pf.Platform, only_current: bool = False, component_key: str = None) -> list[Task]:
def search(endpoint: pf.Platform, only_current: bool = False, component_key: str = None, **kwargs) -> list[Task]:
"""Searches background tasks

:param Platform endpoint: Reference to the SonarQube platform
Expand All @@ -525,6 +525,7 @@ def search(endpoint: pf.Platform, only_current: bool = False, component_key: str
:rtype: list[Task]
"""
params = {"status": ",".join(STATUSES), "additionalFields": "warnings"}
params.update(**kwargs)
if only_current:
params["onlyCurrents"] = "true"
if component_key is not None:
Expand All @@ -538,11 +539,12 @@ def search_all_last(endpoint: pf.Platform) -> list[Task]:
return search(endpoint=endpoint, only_current=True)


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

Expand Down