Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report dashboard scan URL for OSH scans #2640

Merged
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
18 changes: 11 additions & 7 deletions packit_service/service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ def _get_url_for_dashboard_results(job_type: str, id_: int) -> str:
Args:
job_type (str): Type of results. Represents route on dashboard.

Specifically: `srpm-builds`, `copr-builds`, `koji-builds`, `testing-farm`
or `propose-downstream`.
id_ (int): Packit ID of the build.
Specifically: `srpm`, `copr`, `koji`, `testing-farm`,
`propose-downstream`, `pull-from-upstream` or `openscanhub`.
id_ (int): Packit ID of the item.

Returns:
URL to the results of `id_` entry of type `type`.
"""
return f"{DASHBOARD_URL}/results/{job_type}/{id_}"
return f"{DASHBOARD_URL}/jobs/{job_type}/{id_}"


def get_srpm_build_info_url(id_: int) -> str:
return _get_url_for_dashboard_results("srpm-builds", id_)
return _get_url_for_dashboard_results("srpm", id_)


def get_copr_build_info_url(id_: int) -> str:
return _get_url_for_dashboard_results("copr-builds", id_)
return _get_url_for_dashboard_results("copr", id_)


def get_koji_build_info_url(id_: int) -> str:
return _get_url_for_dashboard_results("koji-builds", id_)
return _get_url_for_dashboard_results("koji", id_)


def get_testing_farm_info_url(id_: int) -> str:
Expand All @@ -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
2 changes: 1 addition & 1 deletion tests/integration/test_listen_to_fedmsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ def test_copr_build_end_testing_farm(copr_build_end, copr_build_pr):
flexmock(StatusReporter).should_receive("report").with_args(
state=BaseCommitStatus.running,
description="Tests have been submitted ...",
url="https://dashboard.localhost/results/testing-farm/5",
url="https://dashboard.localhost/jobs/testing-farm/5",
check_names=EXPECTED_TESTING_FARM_CHECK_NAME,
markdown_content=None,
links_to_external_services=None,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_pr_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ def test_pr_test_command_handler_skip_build_option(
flexmock(StatusReporter).should_receive("report").with_args(
description="Tests have been submitted ...",
state=BaseCommitStatus.running,
url="https://dashboard.localhost/results/testing-farm/5",
url="https://dashboard.localhost/jobs/testing-farm/5",
check_names="testing-farm:fedora-rawhide-x86_64",
markdown_content=None,
links_to_external_services=None,
Expand Down Expand Up @@ -2311,7 +2311,7 @@ def test_pr_test_command_handler_multiple_builds(
flexmock(StatusReporter).should_receive("report").with_args(
description="Tests have been submitted ...",
state=BaseCommitStatus.running,
url="https://dashboard.localhost/results/testing-farm/5",
url="https://dashboard.localhost/jobs/testing-farm/5",
check_names="testing-farm:fedora-rawhide-x86_64",
markdown_content=None,
links_to_external_services=None,
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_copr_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def test_report_pending_build_and_test_on_build_submission(
flexmock(CoprBuildJobHelper).should_receive("report_status_to_build").with_args(
description="SRPM build in Copr was submitted...",
state=BaseCommitStatus.running,
url="/results/srpm-builds/1",
url="/jobs/srpm/1",
).once()
flexmock(CoprBuildJobHelper).should_receive(
"report_status_to_all_test_jobs",
Expand All @@ -537,7 +537,7 @@ def test_report_pending_build_and_test_on_build_submission(
if sync_test_job_statuses_with_builds
else BaseCommitStatus.pending
),
url="/results/srpm-builds/1",
url="/jobs/srpm/1",
).once()

helper.report_running_build_and_test_on_build_submission("copr-url")
Expand Down Expand Up @@ -569,7 +569,7 @@ def test_handle_rpm_build_start(github_pr_event, sync_test_job_statuses_with_bui
).with_args(
description="Starting RPM build...",
state=BaseCommitStatus.running,
url="/results/copr-builds/1",
url="/jobs/copr/1",
chroot=chroot,
markdown_content=None,
update_feedback_time=None,
Expand All @@ -579,7 +579,7 @@ def test_handle_rpm_build_start(github_pr_event, sync_test_job_statuses_with_bui
).with_args(
description="Starting RPM build...",
state=BaseCommitStatus.running,
url="/results/copr-builds/1",
url="/jobs/copr/1",
chroot=chroot,
markdown_content=None,
links_to_external_services=None,
Expand All @@ -591,7 +591,7 @@ def test_handle_rpm_build_start(github_pr_event, sync_test_job_statuses_with_bui
).with_args(
description="Starting RPM build...",
state=BaseCommitStatus.running,
url="/results/copr-builds/1",
url="/jobs/copr/1",
chroot=chroot,
).once()
flexmock(CoprBuildJobHelper).should_receive(
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
6 changes: 3 additions & 3 deletions tests/unit/test_testing_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_testing_farm_response(
flexmock(StatusReporter).should_receive("report").with_args(
description=status_message,
state=status_status,
url="https://dashboard.localhost/results/testing-farm/123",
url="https://dashboard.localhost/jobs/testing-farm/123",
check_names="testing-farm:fedora-rawhide-x86_64",
markdown_content=None,
links_to_external_services={"Testing Farm": "some url"},
Expand Down Expand Up @@ -1383,7 +1383,7 @@ def test_trigger_build(copr_build, wait_for_build):
description="The latest build has not finished yet, "
"waiting until it finishes before running tests for it.",
target=target,
url="https://dashboard.localhost/results/copr-builds/1",
url="https://dashboard.localhost/jobs/copr/1",
)

flexmock(CoprHelper).should_receive("get_valid_build_targets").and_return(targets)
Expand Down Expand Up @@ -1467,7 +1467,7 @@ def test_trigger_build_manual_tests_dont_report():
description="The latest build has not finished yet. "
"Please retrigger the tests once it has finished.",
target=target,
url="https://dashboard.localhost/results/copr-builds/1",
url="https://dashboard.localhost/jobs/copr/1",
)

flexmock(CoprHelper).should_receive("get_valid_build_targets").and_return(targets)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_get_logs(client):
)

logs_url = get_copr_build_info_url(1)
assert logs_url == "https://localhost/results/copr-builds/1"
assert logs_url == "https://localhost/jobs/copr/1"


def test_get_srpm_logs(client):
Expand All @@ -114,7 +114,7 @@ def test_get_srpm_logs(client):
flexmock(SRPMBuildModel).should_receive("get_by_id").and_return(srpm_build_mock)

logs_url = get_srpm_build_info_url(2)
assert logs_url == "https://localhost/results/srpm-builds/2"
assert logs_url == "https://localhost/jobs/srpm/2"


def test_system_api(client):
Expand Down
Loading