Skip to content

Commit

Permalink
Report dashboard scan URL for OSH scans
Browse files Browse the repository at this point in the history
  • Loading branch information
lbarcziova committed Nov 14, 2024
1 parent b64446b commit d5a6697
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
4 changes: 4 additions & 0 deletions packit_service/service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ def get_propose_downstream_info_url(id_: int) -> str:

def get_pull_from_upstream_info_url(id_: int) -> str:
return _get_url_for_dashboard_results("pull-from-upstream", id_)


def get_openscanhub_info_url(id_: int) -> str:
return _get_url_for_dashboard_results("openscanhub", id_)
11 changes: 5 additions & 6 deletions packit_service/worker/handlers/open_scan_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
)

from packit_service.models import OSHScanStatus
from packit_service.service.urls import get_openscanhub_info_url
from packit_service.worker.checker.abstract import Checker
from packit_service.worker.checker.open_scan_hub import RawhideX86Target
from packit_service.worker.events import (
Expand Down Expand Up @@ -151,7 +152,7 @@ def get_issues_added_url(

def run(self) -> TaskResults:
self.check_scan_and_build()

external_links = {"OpenScanHub task": self.event.scan.url}
if self.event.status == OpenScanHubTaskFinishedEvent.Status.success:
state = BaseCommitStatus.success
number_of_new_findings = self.get_number_of_new_findings_identified()
Expand All @@ -162,15 +163,14 @@ def run(self) -> TaskResults:
f"{base_description} We were not able to analyse the findings; "
f"please check the URL."
)
external_links = {"Added issues": self.get_issues_added_url()}
external_links.update({"Added issues": self.get_issues_added_url()})
elif number_of_new_findings > 0:
description = (
f"{base_description} {number_of_new_findings} new findings identified."
)
external_links = {"Added issues": self.get_issues_added_url()}
external_links.update({"Added issues": self.get_issues_added_url()})
else:
description = f"{base_description} No new findings identified."
external_links = {}

self.event.scan.set_status(OSHScanStatus.succeeded)
self.event.scan.set_issues_added_url(self.event.issues_added_url)
Expand All @@ -179,7 +179,6 @@ def run(self) -> TaskResults:
else:
state = BaseCommitStatus.neutral
description = f"Scan in OpenScanHub is finished in a {self.event.status} state."
external_links = {}
if self.event.status == OpenScanHubTaskFinishedEvent.Status.cancel:
self.event.scan.set_status(OSHScanStatus.canceled)
else:
Expand All @@ -188,7 +187,7 @@ def run(self) -> TaskResults:
self.get_helper().report(
state=state,
description=description,
url=self.event.scan.url,
url=get_openscanhub_info_url(self.event.scan.id),
links_to_external_services=external_links,
)

Expand Down
5 changes: 3 additions & 2 deletions packit_service/worker/helpers/open_scan_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
OSHScanStatus,
SRPMBuildModel,
)
from packit_service.service.urls import get_copr_build_info_url
from packit_service.service.urls import get_copr_build_info_url, get_openscanhub_info_url
from packit_service.utils import (
download_file,
)
Expand Down Expand Up @@ -131,7 +131,8 @@ def handle_scan(self):
"Scan in OpenScanHub submitted successfully. "
"Check the URL for more details."
),
url=url,
url=get_openscanhub_info_url(scan.id),
links_to_external_services={"OpenScanHub task": url},
)
except IntegrityError as ex:
logger.info(f"OpenScanHub already submitted: {ex}")
Expand Down
18 changes: 12 additions & 6 deletions tests/unit/test_open_scan_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def prepare_openscanhub_db_and_handler(

flexmock(celery_group).should_receive("apply_async")
scan_mock = flexmock(
id=123,
copr_build_target=db_build,
url="https://openscanhub.fedoraproject.org/task/17514/",
set_issues_added_url=lambda _: None,
Expand Down Expand Up @@ -256,6 +257,9 @@ def test_handle_scan_task_finished(
assert len(processing_results) == num_of_handlers

if processing_results:
links_to_external_services = {
"OpenScanHub task": "https://openscanhub.fedoraproject.org/task/17514/"
}
if scan_status == OpenScanHubTaskFinishedEvent.Status.success:
state = BaseCommitStatus.success
description = "Scan in OpenScanHub is finished. " "2 new findings identified."
Expand All @@ -265,28 +269,30 @@ def test_handle_scan_task_finished(
flexmock(OpenScanHubTaskFinishedHandler).should_receive(
"get_number_of_new_findings_identified"
).and_return(2)
links_to_external_services = {
"Added issues": ("https://openscanhub.fedoraproject.org/task/15649/log/added.html"),
}
links_to_external_services.update(
{
"Added issues": (
"https://openscanhub.fedoraproject.org/task/15649/log/added.html"
),
}
)
elif scan_status == OpenScanHubTaskFinishedEvent.Status.cancel:
state = BaseCommitStatus.neutral
description = f"Scan in OpenScanHub is finished in a {scan_status} state."
links_to_external_services = {}
flexmock(scan_mock).should_receive("set_status").with_args(
"canceled",
).once()
else:
state = BaseCommitStatus.neutral
description = f"Scan in OpenScanHub is finished in a {scan_status} state."
links_to_external_services = {}
flexmock(scan_mock).should_receive("set_status").with_args("failed").once()
if num_of_handlers == 1:
# one handler is always skipped because it is for fedora-stable ->
# no rawhide build
flexmock(OpenScanHubHelper).should_receive("report").with_args(
state=state,
description=description,
url="https://openscanhub.fedoraproject.org/task/17514/",
url="/jobs/openscanhub/123",
links_to_external_services=links_to_external_services,
).once().and_return()

Expand Down

0 comments on commit d5a6697

Please sign in to comment.