diff --git a/packit_service/models.py b/packit_service/models.py index 8f916f8ee..aa91d2768 100644 --- a/packit_service/models.py +++ b/packit_service/models.py @@ -2312,7 +2312,7 @@ def create( build.web_url = web_url build.target = target build.task_accepted_time = task_accepted_time - build.identifier = identifier or "" + build.identifier = identifier session.add(build) copr_build_group.copr_build_targets.append(build) diff --git a/packit_service/worker/events/comment.py b/packit_service/worker/events/comment.py index a7400f952..aa03c5581 100644 --- a/packit_service/worker/events/comment.py +++ b/packit_service/worker/events/comment.py @@ -94,7 +94,16 @@ def comment_object(self) -> Optional[Comment]: @property def build_targets_override(self) -> Optional[set[tuple[str, str]]]: - if not self._build_targets_override and "rebuild-failed" in self.comment: + # If we do not override the failing builds for the retest-failed comment + # we will later submit all tests. + # Overriding builds for the retest-failed comment will let the test jobs + # see that something has failed and only for those targets the + # tests will be submitted. + if ( + not self._build_targets_override + and "rebuild-failed" in self.comment + or "retest-failed" in self.comment + ): self._build_targets_override = ( super().get_all_build_targets_by_status( statuses_to_filter_with=[BuildStatus.failure], diff --git a/packit_service/worker/events/github.py b/packit_service/worker/events/github.py index eb2babb1e..7e44b8af0 100644 --- a/packit_service/worker/events/github.py +++ b/packit_service/worker/events/github.py @@ -236,24 +236,16 @@ def __init__( ) self.job_identifier = job_identifier - def _parse_target_and_identifier(self, target_string: str) -> tuple[str, str]: - """Parse target and identifier from check name target string.""" - if ":" in target_string: - target, identifier = target_string.split(":") - else: - target, identifier = target_string, "" - return target, identifier - @property def build_targets_override(self) -> Optional[set[tuple[str, str]]]: if self.check_name_job in {"rpm-build", "production-build", "koji-build"}: - return {self._parse_target_and_identifier(self.check_name_target)} + return {(self.check_name_target, self.job_identifier)} return None @property def tests_targets_override(self) -> Optional[set[tuple[str, str]]]: if self.check_name_job == "testing-farm": - return {self._parse_target_and_identifier(self.check_name_target)} + return {(self.check_name_target, self.job_identifier)} return None @property diff --git a/packit_service/worker/handlers/copr.py b/packit_service/worker/handlers/copr.py index bc724ccf6..112ae4aa6 100644 --- a/packit_service/worker/handlers/copr.py +++ b/packit_service/worker/handlers/copr.py @@ -480,7 +480,7 @@ def handle_testing_farm(self): in self.copr_build_helper.build_targets_for_test_job(job_config) ): event_dict["tests_targets_override"] = [ - (target, job_config.identifier or "") + (target, job_config.identifier) for target in self.copr_build_helper.build_target2test_targets_for_test_job( self.copr_event.chroot, job_config, diff --git a/packit_service/worker/handlers/mixin.py b/packit_service/worker/handlers/mixin.py index 88629e4bb..67c7ac3bd 100644 --- a/packit_service/worker/handlers/mixin.py +++ b/packit_service/worker/handlers/mixin.py @@ -432,7 +432,7 @@ def copr_build_helper(self) -> CoprBuildJobHelper: # when reporting state of SRPM build built in Copr build_targets_override = ( { - (build.target, build.identifier or "") + (build.target, build.identifier) for build in CoprBuildTargetModel.get_all_by_build_id( str(self.copr_event.build_id), ) diff --git a/packit_service/worker/helpers/build/build_helper.py b/packit_service/worker/helpers/build/build_helper.py index d7ca46a78..6302b3c11 100644 --- a/packit_service/worker/helpers/build/build_helper.py +++ b/packit_service/worker/helpers/build/build_helper.py @@ -274,7 +274,7 @@ def build_targets_for_test_job(self, test_job_config: JobConfig) -> set[str]: [ target for (target, identifier) in self.build_targets_override - if identifier == (test_job_config.identifier or "") + if identifier == test_job_config.identifier ] ) @@ -285,8 +285,7 @@ def build_targets_for_test_job(self, test_job_config: JobConfig) -> set[str]: for t in [ target for (target, identifier) in self.tests_targets_override - if identifier - == (test_job_config.identifier if test_job_config.identifier else "") + if identifier == test_job_config.identifier ] ) @@ -326,7 +325,7 @@ def tests_targets_for_test_job(self, test_job_config: JobConfig) -> set[str]: if self.build_targets_override: logger.debug(f"Build targets override: {self.build_targets_override}") for target, identifier in self.build_targets_override: - if identifier == (test_job_config.identifier if test_job_config.identifier else ""): + if identifier == test_job_config.identifier: targets_override.update( self.build_target2test_targets_for_test_job(target, test_job_config), ) @@ -337,8 +336,7 @@ def tests_targets_for_test_job(self, test_job_config: JobConfig) -> set[str]: [ target for target, identifier in self.tests_targets_override - if identifier - == (test_job_config.identifier if test_job_config.identifier else "") + if identifier == test_job_config.identifier ] ) diff --git a/tests/data/webhooks/github/checkrun_rerequested_with_identifier.json b/tests/data/webhooks/github/checkrun_rerequested_with_identifier.json new file mode 100644 index 000000000..a6168dc82 --- /dev/null +++ b/tests/data/webhooks/github/checkrun_rerequested_with_identifier.json @@ -0,0 +1,284 @@ +{ + "action": "rerequested", + "check_run": { + "id": 33642804556, + "name": "testing-farm:fedora-rawhide-x86_64:lint-rawhide", + "node_id": "CR_kwDOCwFO9M8AAAAH1UR1TA", + "head_sha": "b8167b97e3cf94f19aa70037708894e0bff7ac95", + "external_id": "123456", + "url": "https://api.github.com/repos/packit/hello-world/check-runs/33642804556", + "html_url": "https://github.com/packit/hello-world/runs/33642804556", + "details_url": "https://dashboard.stg.packit.dev/jobs/testing-farm/41181", + "status": "completed", + "conclusion": "failure", + "started_at": "2024-11-28T08:15:56Z", + "completed_at": "2024-11-28T08:15:56Z", + "output": { + "title": "Tests failed ...", + "summary": "| Name/Job | URL |\n| --- | --- |\n| Dashboard | https://dashboard.stg.packit.dev/jobs/testing-farm/41181 |\n| Testing Farm | https://artifacts.dev.testing-farm.io/7e58098a-227d-489b-a22b-cde36fda7858 |\n\n\n\n---\n*Curious how Packit handles the Release field during propose-downstream? Take a look [here](https://packit.dev/posts/release-field-handling/) to know more.*", + "text": null, + "annotations_count": 0, + "annotations_url": "https://api.github.com/repos/packit/hello-world/check-runs/33642804556/annotations" + }, + "check_suite": { + "id": 31430964947, + "node_id": "CS_kwDOCwFO9M8AAAAHUW520w", + "head_branch": null, + "head_sha": "b8167b97e3cf94f19aa70037708894e0bff7ac95", + "status": "queued", + "conclusion": null, + "url": "https://api.github.com/repos/packit/hello-world/check-suites/31430964947", + "before": null, + "after": null, + "pull_requests": [], + "app": { + "id": 29180, + "client_id": "Iv1.44a7cbb2c22dc368", + "slug": "packit-as-a-service", + "node_id": "MDM6QXBwMjkxODA=", + "owner": { + "login": "packit", + "id": 46870917, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjQ2ODcwOTE3", + "avatar_url": "https://avatars.githubusercontent.com/u/46870917?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/packit", + "html_url": "https://github.com/packit", + "followers_url": "https://api.github.com/users/packit/followers", + "following_url": "https://api.github.com/users/packit/following{/other_user}", + "gists_url": "https://api.github.com/users/packit/gists{/gist_id}", + "starred_url": "https://api.github.com/users/packit/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/packit/subscriptions", + "organizations_url": "https://api.github.com/users/packit/orgs", + "repos_url": "https://api.github.com/users/packit/repos", + "events_url": "https://api.github.com/users/packit/events{/privacy}", + "received_events_url": "https://api.github.com/users/packit/received_events", + "type": "Organization", + "user_view_type": "public", + "site_admin": false + }, + "name": "Packit-as-a-Service-stg", + "description": "Packit service (staging). This is a development version! Use only at your own risk. For stable use of packit, use the official app - https://github.com/marketplace/packit-as-a-service", + "external_url": "https://stg.packit.dev", + "html_url": "https://github.com/apps/packit-as-a-service-stg", + "created_at": "2019-04-17T17:25:29Z", + "updated_at": "2024-10-14T10:24:20Z", + "permissions": { + "checks": "write", + "contents": "read", + "issues": "write", + "metadata": "read", + "pull_requests": "write", + "statuses": "write" + }, + "events": [ + "check_run", + "commit_comment", + "issue_comment", + "pull_request", + "push", + "release" + ] + }, + "created_at": "2024-11-28T08:06:27Z", + "updated_at": "2024-11-28T08:17:16Z" + }, + "app": { + "id": 29180, + "client_id": "Iv1.44a7cbb2c22dc368", + "slug": "packit-as-a-service", + "node_id": "MDM6QXBwMjkxODA=", + "owner": { + "login": "packit", + "id": 46870917, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjQ2ODcwOTE3", + "avatar_url": "https://avatars.githubusercontent.com/u/46870917?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/packit", + "html_url": "https://github.com/packit", + "followers_url": "https://api.github.com/users/packit/followers", + "following_url": "https://api.github.com/users/packit/following{/other_user}", + "gists_url": "https://api.github.com/users/packit/gists{/gist_id}", + "starred_url": "https://api.github.com/users/packit/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/packit/subscriptions", + "organizations_url": "https://api.github.com/users/packit/orgs", + "repos_url": "https://api.github.com/users/packit/repos", + "events_url": "https://api.github.com/users/packit/events{/privacy}", + "received_events_url": "https://api.github.com/users/packit/received_events", + "type": "Organization", + "user_view_type": "public", + "site_admin": false + }, + "name": "Packit-as-a-Service-stg", + "description": "Packit service (staging). This is a development version! Use only at your own risk. For stable use of packit, use the official app - https://github.com/marketplace/packit-as-a-service", + "external_url": "https://stg.packit.dev", + "html_url": "https://github.com/apps/packit-as-a-service-stg", + "created_at": "2019-04-17T17:25:29Z", + "updated_at": "2024-10-14T10:24:20Z", + "permissions": { + "checks": "write", + "contents": "read", + "issues": "write", + "metadata": "read", + "pull_requests": "write", + "statuses": "write" + }, + "events": [ + "check_run", + "commit_comment", + "issue_comment", + "pull_request", + "push", + "release" + ] + }, + "pull_requests": [] + }, + "repository": { + "id": 184635124, + "node_id": "MDEwOlJlcG9zaXRvcnkxODQ2MzUxMjQ=", + "name": "hello-world", + "full_name": "packit/hello-world", + "private": false, + "owner": { + "login": "packit", + "id": 46870917, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjQ2ODcwOTE3", + "avatar_url": "https://avatars.githubusercontent.com/u/46870917?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/packit", + "html_url": "https://github.com/packit", + "followers_url": "https://api.github.com/users/packit/followers", + "following_url": "https://api.github.com/users/packit/following{/other_user}", + "gists_url": "https://api.github.com/users/packit/gists{/gist_id}", + "starred_url": "https://api.github.com/users/packit/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/packit/subscriptions", + "organizations_url": "https://api.github.com/users/packit/orgs", + "repos_url": "https://api.github.com/users/packit/repos", + "events_url": "https://api.github.com/users/packit/events{/privacy}", + "received_events_url": "https://api.github.com/users/packit/received_events", + "type": "Organization", + "user_view_type": "public", + "site_admin": false + }, + "html_url": "https://github.com/packit/hello-world", + "description": "The most progresive command-line tool in the world.", + "fork": false, + "url": "https://api.github.com/repos/packit/hello-world", + "forks_url": "https://api.github.com/repos/packit/hello-world/forks", + "keys_url": "https://api.github.com/repos/packit/hello-world/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/packit/hello-world/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/packit/hello-world/teams", + "hooks_url": "https://api.github.com/repos/packit/hello-world/hooks", + "issue_events_url": "https://api.github.com/repos/packit/hello-world/issues/events{/number}", + "events_url": "https://api.github.com/repos/packit/hello-world/events", + "assignees_url": "https://api.github.com/repos/packit/hello-world/assignees{/user}", + "branches_url": "https://api.github.com/repos/packit/hello-world/branches{/branch}", + "tags_url": "https://api.github.com/repos/packit/hello-world/tags", + "blobs_url": "https://api.github.com/repos/packit/hello-world/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/packit/hello-world/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/packit/hello-world/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/packit/hello-world/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/packit/hello-world/statuses/{sha}", + "languages_url": "https://api.github.com/repos/packit/hello-world/languages", + "stargazers_url": "https://api.github.com/repos/packit/hello-world/stargazers", + "contributors_url": "https://api.github.com/repos/packit/hello-world/contributors", + "subscribers_url": "https://api.github.com/repos/packit/hello-world/subscribers", + "subscription_url": "https://api.github.com/repos/packit/hello-world/subscription", + "commits_url": "https://api.github.com/repos/packit/hello-world/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/packit/hello-world/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/packit/hello-world/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/packit/hello-world/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/packit/hello-world/contents/{+path}", + "compare_url": "https://api.github.com/repos/packit/hello-world/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/packit/hello-world/merges", + "archive_url": "https://api.github.com/repos/packit/hello-world/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/packit/hello-world/downloads", + "issues_url": "https://api.github.com/repos/packit/hello-world/issues{/number}", + "pulls_url": "https://api.github.com/repos/packit/hello-world/pulls{/number}", + "milestones_url": "https://api.github.com/repos/packit/hello-world/milestones{/number}", + "notifications_url": "https://api.github.com/repos/packit/hello-world/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/packit/hello-world/labels{/name}", + "releases_url": "https://api.github.com/repos/packit/hello-world/releases{/id}", + "deployments_url": "https://api.github.com/repos/packit/hello-world/deployments", + "created_at": "2019-05-02T18:54:46Z", + "updated_at": "2023-01-31T17:16:23Z", + "pushed_at": "2024-11-28T05:17:29Z", + "git_url": "git://github.com/packit/hello-world.git", + "ssh_url": "git@github.com:packit/hello-world.git", + "clone_url": "https://github.com/packit/hello-world.git", + "svn_url": "https://github.com/packit/hello-world", + "homepage": null, + "size": 187, + "stargazers_count": 4, + "watchers_count": 4, + "language": "Python", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "has_discussions": false, + "forks_count": 23, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 98, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [], + "visibility": "public", + "forks": 23, + "open_issues": 98, + "watchers": 4, + "default_branch": "main", + "custom_properties": {} + }, + "organization": { + "login": "packit", + "id": 46870917, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjQ2ODcwOTE3", + "url": "https://api.github.com/orgs/packit", + "repos_url": "https://api.github.com/orgs/packit/repos", + "events_url": "https://api.github.com/orgs/packit/events", + "hooks_url": "https://api.github.com/orgs/packit/hooks", + "issues_url": "https://api.github.com/orgs/packit/issues", + "members_url": "https://api.github.com/orgs/packit/members{/member}", + "public_members_url": "https://api.github.com/orgs/packit/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/46870917?v=4", + "description": "Packit service: package it in an automated way." + }, + "sender": { + "login": "majamassarini", + "id": 2678400, + "node_id": "MDQ6VXNlcjI2Nzg0MDA=", + "avatar_url": "https://avatars.githubusercontent.com/u/2678400?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/majamassarini", + "html_url": "https://github.com/majamassarini", + "followers_url": "https://api.github.com/users/majamassarini/followers", + "following_url": "https://api.github.com/users/majamassarini/following{/other_user}", + "gists_url": "https://api.github.com/users/majamassarini/gists{/gist_id}", + "starred_url": "https://api.github.com/users/majamassarini/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/majamassarini/subscriptions", + "organizations_url": "https://api.github.com/users/majamassarini/orgs", + "repos_url": "https://api.github.com/users/majamassarini/repos", + "events_url": "https://api.github.com/users/majamassarini/events{/privacy}", + "received_events_url": "https://api.github.com/users/majamassarini/received_events", + "type": "User", + "user_view_type": "public", + "site_admin": false + }, + "installation": { + "id": 1924121, + "node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMTkyNDEyMQ==" + } +} diff --git a/tests/integration/test_check_rerun.py b/tests/integration/test_check_rerun.py index 8aa705219..bae5e23cd 100644 --- a/tests/integration/test_check_rerun.py +++ b/tests/integration/test_check_rerun.py @@ -305,7 +305,7 @@ def test_check_rerun_pr_testing_farm_handler( processing_results, ) assert json.dumps(event_dict) - assert event_dict["tests_targets_override"] == [("fedora-rawhide-x86_64", "")] + assert event_dict["tests_targets_override"] == [("fedora-rawhide-x86_64", None)] results = run_testing_farm_handler( package_config=package_config, event=event_dict, @@ -363,7 +363,7 @@ def test_check_rerun_pr_koji_build_handler( processing_results, ) assert json.dumps(event_dict) - assert event_dict["build_targets_override"] == [("f34", "")] + assert event_dict["build_targets_override"] == [("f34", None)] results = run_koji_build_handler( package_config=package_config, @@ -438,7 +438,7 @@ def test_check_rerun_pr_koji_build_handler_old_job_name( processing_results, ) assert json.dumps(event_dict) - assert event_dict["build_targets_override"] == [("f34", "")] + assert event_dict["build_targets_override"] == [("f34", None)] results = run_koji_build_handler( package_config=package_config, @@ -521,7 +521,7 @@ def test_check_rerun_push_testing_farm_handler( event_dict, job, job_config, package_config = get_parameters_from_results( processing_results, ) - assert event_dict["tests_targets_override"] == [("fedora-rawhide-x86_64", "")] + assert event_dict["tests_targets_override"] == [("fedora-rawhide-x86_64", None)] assert json.dumps(event_dict) results = run_testing_farm_handler( package_config=package_config, @@ -581,7 +581,7 @@ def test_check_rerun_push_koji_build_handler( event_dict, job, job_config, package_config = get_parameters_from_results( processing_results, ) - assert event_dict["build_targets_override"] == [("f34", "")] + assert event_dict["build_targets_override"] == [("f34", None)] assert json.dumps(event_dict) results = run_koji_build_handler( @@ -640,7 +640,7 @@ def test_check_rerun_release_koji_build_handler( event_dict, job, job_config, package_config = get_parameters_from_results( processing_results, ) - assert event_dict["build_targets_override"] == [("f34", "")] + assert event_dict["build_targets_override"] == [("f34", None)] assert json.dumps(event_dict) results = run_koji_build_handler( diff --git a/tests/integration/test_listen_to_fedmsg.py b/tests/integration/test_listen_to_fedmsg.py index ba966bdce..85d17d263 100644 --- a/tests/integration/test_listen_to_fedmsg.py +++ b/tests/integration/test_listen_to_fedmsg.py @@ -818,7 +818,7 @@ def test_copr_build_end_testing_farm(copr_build_end, copr_build_pr): flexmock(CoprBuildTargetModel).should_receive("get_all_by").and_return( [copr_build_pr], ) - event_dict["tests_targets_override"] = [("fedora-rawhide-x86_64", "")] + event_dict["tests_targets_override"] = [("fedora-rawhide-x86_64", None)] run_testing_farm_handler( package_config=package_config, event=event_dict, @@ -2084,7 +2084,7 @@ def test_copr_build_end_failed_testing_farm(copr_build_end, copr_build_pr): job_config=job_config, ) - event_dict["tests_targets_override"] = [("fedora-rawhide-x86_64", "")] + event_dict["tests_targets_override"] = [("fedora-rawhide-x86_64", None)] run_testing_farm_handler( package_config=package_config, event=event_dict, @@ -2270,7 +2270,7 @@ def test_copr_build_end_failed_testing_farm_no_json(copr_build_end, copr_build_p job_config=job_config, ) - event_dict["tests_targets_override"] = [("fedora-rawhide-x86_64", "")] + event_dict["tests_targets_override"] = [("fedora-rawhide-x86_64", None)] task = run_testing_farm_handler.__wrapped__.__func__ task( flexmock( @@ -2695,7 +2695,7 @@ def test_srpm_build_end(srpm_build_end, pc_build_pr, srpm_build_model): ) flexmock(CoprBuildTargetModel).should_receive("get_all_by_build_id").and_return( [ - flexmock(target="fedora-33-x86_64", identifier="") + flexmock(target="fedora-33-x86_64", identifier=None) .should_receive("set_status") .with_args(BuildStatus.pending) .mock(), @@ -2762,7 +2762,7 @@ def test_srpm_build_end_failure(srpm_build_end, pc_build_pr, srpm_build_model): Client(config={"username": "packit", "copr_url": "https://dummy.url"}), ) flexmock(CoprBuildTargetModel).should_receive("get_all_by_build_id").and_return( - [flexmock(target="fedora-33-x86_64", identifier="")], + [flexmock(target="fedora-33-x86_64", identifier=None)], ) ( flexmock(CoprBuildJobHelper) @@ -2825,7 +2825,7 @@ def test_srpm_build_start(srpm_build_start, pc_build_pr, srpm_build_model): Client(config={"username": "packit", "copr_url": "https://dummy.url"}), ) flexmock(CoprBuildTargetModel).should_receive("get_all_by_build_id").and_return( - [flexmock(target="fedora-33-x86_64", identifier="")], + [flexmock(target="fedora-33-x86_64", identifier=None)], ) flexmock(Pushgateway).should_receive("push").times(2).and_return() diff --git a/tests/integration/test_pr_comment.py b/tests/integration/test_pr_comment.py index 7ef27a0a0..5cf02e6e3 100644 --- a/tests/integration/test_pr_comment.py +++ b/tests/integration/test_pr_comment.py @@ -1787,27 +1787,43 @@ def test_retest_failed( ) flexmock(GithubProject).should_receive("is_private").and_return(False) flexmock(celery_group).should_receive("apply_async").once() - flexmock(CoprHelper).should_receive("get_valid_build_targets").times(3).and_return( + flexmock(CoprHelper).should_receive("get_valid_build_targets").times(4).and_return( {"test-target"}, ) flexmock(TestingFarmJobHelper).should_receive("get_latest_copr_build").and_return( flexmock(status=BuildStatus.success), ) + build_model = flexmock( + CoprBuildTargetModel, + status=TestingFarmResult.failed, + target="some_build_target", + ) model = flexmock( TFTTestRunTargetModel, status=TestingFarmResult.failed, target="some_tf_target", ) + flexmock(build_model).should_receive("get_all_by_commit_target").with_args( + commit_sha="12345", + ).and_return(build_model) flexmock(model).should_receive("get_all_by_commit_target").with_args( commit_sha="12345", ).and_return(model) + flexmock(AbstractForgeIndependentEvent).should_receive( + "get_all_build_targets_by_status", + ).with_args( + statuses_to_filter_with=[BuildStatus.failure], + ).and_return( + {("some_build_target", None)}, + ) + flexmock(AbstractForgeIndependentEvent).should_receive( "get_all_tf_targets_by_status", ).with_args( statuses_to_filter_with=[TestingFarmResult.failed, TestingFarmResult.error], ).and_return( - {("some_tf_target", "")}, + {("some_tf_target", None)}, ) flexmock(packit_service.models).should_receive( "filter_most_recent_target_names_by_status", @@ -1815,7 +1831,7 @@ def test_retest_failed( models=[model], statuses_to_filter_with=[TestingFarmResult.failed, TestingFarmResult.error], ).and_return( - {("some_target", "")}, + {("some_target", None)}, ) flexmock(Pushgateway).should_receive("push").times(3).and_return() @@ -1832,7 +1848,7 @@ def test_retest_failed( event_dict, job, job_config, package_config = get_parameters_from_results( processing_results, ) - assert event_dict["tests_targets_override"] == [("some_tf_target", "")] + assert event_dict["tests_targets_override"] == [("some_tf_target", None)] assert json.dumps(event_dict) run_testing_farm_handler( diff --git a/tests/unit/events/test_github.py b/tests/unit/events/test_github.py index e5d0c2437..e38cf6d19 100644 --- a/tests/unit/events/test_github.py +++ b/tests/unit/events/test_github.py @@ -88,6 +88,14 @@ def check_rerun(): return json.load(outfile) +@pytest.fixture() +def check_rerun_with_identifier(): + with open( + DATA_DIR / "webhooks" / "github" / "checkrun_rerequested_with_identifier.json", + ) as outfile: + return json.load(outfile) + + @pytest.fixture() def github_pr_comment_created(): with open( @@ -279,7 +287,7 @@ def test_parse_check_rerun_commit(check_rerun): ).once() assert event_object.packages_config assert event_object.build_targets_override is None - assert event_object.tests_targets_override == {("fedora-rawhide-x86_64", "")} + assert event_object.tests_targets_override == {("fedora-rawhide-x86_64", None)} assert event_object.actor == "lbarcziova" @@ -321,7 +329,7 @@ def test_parse_check_rerun_pull_request(check_rerun): ).once() assert event_object.packages_config assert event_object.build_targets_override is None - assert event_object.tests_targets_override == {("fedora-rawhide-x86_64", "")} + assert event_object.tests_targets_override == {("fedora-rawhide-x86_64", None)} def test_parse_check_rerun_release(check_rerun): @@ -347,10 +355,27 @@ def test_parse_check_rerun_release(check_rerun): assert event_object.check_name_job == "testing-farm" assert event_object.check_name_target == "fedora-rawhide-x86_64" assert event_object.build_targets_override is None - assert event_object.tests_targets_override == {("fedora-rawhide-x86_64", "")} + assert event_object.tests_targets_override == {("fedora-rawhide-x86_64", None)} assert event_object.actor == "lbarcziova" +def test_parse_check_rerun_with_identifier(check_rerun_with_identifier): + trigger = flexmock(ProjectEventModel, event_id=1234) + pr_model = PullRequestModel(pr_id=12) + flexmock(ProjectEventModel).should_receive("get_by_id").with_args( + 123456, + ).and_return(trigger) + flexmock(trigger).should_receive("get_project_event_object").and_return(pr_model) + + event_object = Parser.parse_event(check_rerun_with_identifier) + + assert isinstance(event_object, CheckRerunPullRequestEvent) + assert event_object.check_name_job == "testing-farm" + assert event_object.check_name_target == "fedora-rawhide-x86_64" + assert event_object.build_targets_override is None + assert event_object.tests_targets_override == {("fedora-rawhide-x86_64", "lint-rawhide")} + + def test_parse_pr_comment_created(github_pr_comment_created): event_object = Parser.parse_event(github_pr_comment_created) diff --git a/tests/unit/test_build_helper.py b/tests/unit/test_build_helper.py index 651721978..18adf99a2 100644 --- a/tests/unit/test_build_helper.py +++ b/tests/unit/test_build_helper.py @@ -906,7 +906,7 @@ def test_deduced_copr_targets(): ), ], JobConfigTriggerType.pull_request, - {("fedora-32-x86_64", "")}, + {("fedora-32-x86_64", None)}, None, {"fedora-32-x86_64"}, [{"fedora-32-x86_64"}], @@ -926,7 +926,7 @@ def test_deduced_copr_targets(): ), ], JobConfigTriggerType.pull_request, - {("fedora-32-x86_64", "")}, + {("fedora-32-x86_64", None)}, None, {"fedora-32-x86_64"}, [{"fedora-32-x86_64"}], @@ -946,7 +946,7 @@ def test_deduced_copr_targets(): ), ], JobConfigTriggerType.pull_request, - {("fedora-33-x86_64", "")}, + {("fedora-33-x86_64", None)}, None, set(), [set()], @@ -969,7 +969,7 @@ def test_deduced_copr_targets(): ], JobConfigTriggerType.pull_request, None, - {("centos-7-x86_64", "")}, + {("centos-7-x86_64", None)}, {"epel-7-x86_64"}, None, [{"centos-7-x86_64"}], @@ -990,7 +990,7 @@ def test_deduced_copr_targets(): ), ], JobConfigTriggerType.pull_request, - {("epel-7-x86_64", "")}, + {("epel-7-x86_64", None)}, None, {"epel-7-x86_64"}, None, @@ -1011,7 +1011,7 @@ def test_deduced_copr_targets(): ], JobConfigTriggerType.pull_request, None, - {("centos-stream-8-x86_64", "")}, + {("centos-stream-8-x86_64", None)}, {"centos-stream-8-x86_64"}, None, [{"centos-stream-8-x86_64"}], @@ -1036,7 +1036,7 @@ def test_deduced_copr_targets(): ], JobConfigTriggerType.pull_request, None, - {("centos-stream-8-x86_64", "")}, + {("centos-stream-8-x86_64", None)}, {"centos-stream-8-x86_64"}, [{"centos-stream-8-x86_64"}], [{"centos-stream-8-x86_64"}], @@ -1055,7 +1055,7 @@ def test_deduced_copr_targets(): ), ], JobConfigTriggerType.pull_request, - {("epel-7-x86_64", "")}, + {("epel-7-x86_64", None)}, None, {"epel-7-x86_64"}, None, @@ -1076,7 +1076,7 @@ def test_deduced_copr_targets(): ], JobConfigTriggerType.pull_request, None, - {("centos-7-x86_64", "")}, + {("centos-7-x86_64", None)}, {"epel-7-x86_64"}, None, [{"centos-7-x86_64"}], @@ -1095,7 +1095,7 @@ def test_deduced_copr_targets(): ), ], JobConfigTriggerType.pull_request, - {("epel-7-ppc64le", "")}, + {("epel-7-ppc64le", None)}, None, {"epel-7-ppc64le"}, None, @@ -1116,7 +1116,7 @@ def test_deduced_copr_targets(): ], JobConfigTriggerType.pull_request, None, - {("centos-7-ppc64le", "")}, + {("centos-7-ppc64le", None)}, {"epel-7-ppc64le"}, None, [{"centos-7-ppc64le"}], @@ -1144,7 +1144,7 @@ def test_deduced_copr_targets(): ), ], JobConfigTriggerType.pull_request, - {("fedora-rawhide-x86_64", "")}, + {("fedora-rawhide-x86_64", None)}, None, {"fedora-rawhide-x86_64"}, None, @@ -1309,7 +1309,7 @@ def test_build_targets_overrides( ), ], JobConfigTriggerType.pull_request, - {("fedora-32-x86_64", "")}, + {("fedora-32-x86_64", None)}, None, {"fedora-32-x86_64"}, id="target_in_config_for_both", @@ -1330,7 +1330,7 @@ def test_build_targets_overrides( ], JobConfigTriggerType.pull_request, None, - {("centos-7-x86_64", "")}, + {("centos-7-x86_64", None)}, {"centos-7-x86_64"}, id="build_test_mapping_test_overrides", ), @@ -1349,7 +1349,7 @@ def test_build_targets_overrides( ), ], JobConfigTriggerType.pull_request, - {("epel-7-x86_64", "")}, + {("epel-7-x86_64", None)}, None, {"centos-7-x86_64", "rhel-7-x86_64"}, id="build_test_mapping_build_overrides", @@ -1368,7 +1368,7 @@ def test_build_targets_overrides( ], JobConfigTriggerType.pull_request, None, - {("centos-stream-8-x86_64", "")}, + {("centos-stream-8-x86_64", None)}, {"centos-stream-8-x86_64"}, id="targets_in_tests_no_mapping", ), @@ -1391,7 +1391,7 @@ def test_build_targets_overrides( ], JobConfigTriggerType.pull_request, None, - {("centos-stream-8-x86_64", "")}, + {("centos-stream-8-x86_64", None)}, {"centos-stream-8-x86_64"}, id="targets_in_build_no_mapping", ), @@ -1408,7 +1408,7 @@ def test_build_targets_overrides( ), ], JobConfigTriggerType.pull_request, - {("epel-7-x86_64", "")}, + {("epel-7-x86_64", None)}, None, {"centos-7-x86_64"}, id="default_mapping_build_override", @@ -1427,7 +1427,7 @@ def test_build_targets_overrides( ], JobConfigTriggerType.pull_request, None, - {("centos-7-x86_64", "")}, + {("centos-7-x86_64", None)}, {"centos-7-x86_64"}, id="default_mapping_test_override", ), @@ -1444,7 +1444,7 @@ def test_build_targets_overrides( ), ], JobConfigTriggerType.pull_request, - {("epel-7-ppc64le", "")}, + {("epel-7-ppc64le", None)}, None, {"centos-7-ppc64le"}, id="default_mapping_build_override_different_arch", @@ -1463,7 +1463,7 @@ def test_build_targets_overrides( ], JobConfigTriggerType.pull_request, None, - {("centos-7-ppc64le", "")}, + {("centos-7-ppc64le", None)}, {"centos-7-ppc64le"}, id="default_mapping_test_override_different_arch", ), @@ -1480,7 +1480,7 @@ def test_build_targets_overrides( ), ], JobConfigTriggerType.pull_request, - {("fedora-rawhide-x86_64", "")}, + {("fedora-rawhide-x86_64", None)}, None, set(), id="build-target-not-in-test", @@ -1918,7 +1918,7 @@ def test_copr_test_target2build_target(job_config, test_target, build_target): ), ], JobConfigTriggerType.pull_request, - {("f32", "")}, + {("f32", None)}, {"f32"}, id="target_in_config", ), @@ -1935,7 +1935,7 @@ def test_copr_test_target2build_target(job_config, test_target, build_target): ), ], JobConfigTriggerType.pull_request, - {("f33", "")}, + {("f33", None)}, set(), id="target_not_in_config", ), diff --git a/tests/unit/test_koji_build.py b/tests/unit/test_koji_build.py index b7ea4935c..34206ec9e 100644 --- a/tests/unit/test_koji_build.py +++ b/tests/unit/test_koji_build.py @@ -518,7 +518,7 @@ def test_koji_build_targets_override( _targets=["bright-future", "dark-past"], scratch=True, db_project_event=db_project_event, - build_targets_override={("bright-future", "")}, + build_targets_override={("bright-future", None)}, ) flexmock(koji_build).should_receive("get_all_koji_targets").and_return( ["dark-past", "bright-future"],