From b64446b04ef6ead018d677f0f4834d3a34122e39 Mon Sep 17 00:00:00 2001 From: Laura Barcziova Date: Thu, 14 Nov 2024 14:09:51 +0100 Subject: [PATCH 1/2] Update dashboard result URLs creation Follow-up on packit/dashboard#435, the previous URLs have been still working thanks to redirects. --- packit_service/service/urls.py | 14 +++++++------- tests/integration/test_listen_to_fedmsg.py | 2 +- tests/integration/test_pr_comment.py | 4 ++-- tests/unit/test_copr_build.py | 10 +++++----- tests/unit/test_testing_farm.py | 6 +++--- tests/unit/test_views.py | 4 ++-- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packit_service/service/urls.py b/packit_service/service/urls.py index 367cd488e..6a97c0629 100644 --- a/packit_service/service/urls.py +++ b/packit_service/service/urls.py @@ -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: diff --git a/tests/integration/test_listen_to_fedmsg.py b/tests/integration/test_listen_to_fedmsg.py index 797171a3a..a773cfc2b 100644 --- a/tests/integration/test_listen_to_fedmsg.py +++ b/tests/integration/test_listen_to_fedmsg.py @@ -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, diff --git a/tests/integration/test_pr_comment.py b/tests/integration/test_pr_comment.py index a3c9c8054..2b207d330 100644 --- a/tests/integration/test_pr_comment.py +++ b/tests/integration/test_pr_comment.py @@ -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, @@ -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, diff --git a/tests/unit/test_copr_build.py b/tests/unit/test_copr_build.py index c0d3fc03c..326f58b48 100644 --- a/tests/unit/test_copr_build.py +++ b/tests/unit/test_copr_build.py @@ -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", @@ -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") @@ -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, @@ -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, @@ -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( diff --git a/tests/unit/test_testing_farm.py b/tests/unit/test_testing_farm.py index aba720285..3b95e8c12 100644 --- a/tests/unit/test_testing_farm.py +++ b/tests/unit/test_testing_farm.py @@ -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"}, @@ -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) @@ -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) diff --git a/tests/unit/test_views.py b/tests/unit/test_views.py index e65344de0..fc0280b67 100644 --- a/tests/unit/test_views.py +++ b/tests/unit/test_views.py @@ -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): @@ -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): From d5a6697c9d629862fa091001ce849f7fd93d9543 Mon Sep 17 00:00:00 2001 From: Laura Barcziova Date: Thu, 14 Nov 2024 14:11:31 +0100 Subject: [PATCH 2/2] Report dashboard scan URL for OSH scans --- packit_service/service/urls.py | 4 ++++ .../worker/handlers/open_scan_hub.py | 11 +++++------ packit_service/worker/helpers/open_scan_hub.py | 5 +++-- tests/unit/test_open_scan_hub.py | 18 ++++++++++++------ 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/packit_service/service/urls.py b/packit_service/service/urls.py index 6a97c0629..faec20308 100644 --- a/packit_service/service/urls.py +++ b/packit_service/service/urls.py @@ -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_) diff --git a/packit_service/worker/handlers/open_scan_hub.py b/packit_service/worker/handlers/open_scan_hub.py index 9cde7b2c0..4a02dd7cb 100644 --- a/packit_service/worker/handlers/open_scan_hub.py +++ b/packit_service/worker/handlers/open_scan_hub.py @@ -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 ( @@ -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() @@ -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) @@ -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: @@ -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, ) diff --git a/packit_service/worker/helpers/open_scan_hub.py b/packit_service/worker/helpers/open_scan_hub.py index cafde7af2..13423c1f6 100644 --- a/packit_service/worker/helpers/open_scan_hub.py +++ b/packit_service/worker/helpers/open_scan_hub.py @@ -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, ) @@ -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}") diff --git a/tests/unit/test_open_scan_hub.py b/tests/unit/test_open_scan_hub.py index a20c0e415..5b9b9ef02 100644 --- a/tests/unit/test_open_scan_hub.py +++ b/tests/unit/test_open_scan_hub.py @@ -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, @@ -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." @@ -265,20 +269,22 @@ 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 -> @@ -286,7 +292,7 @@ def test_handle_scan_task_finished( 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()