From 3a00c9d2d5f85ed3b597430c53645b2e02c61005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Mon, 11 Nov 2024 18:36:12 +0100 Subject: [PATCH 1/2] Choose only jobs with sidetag group for koji-tag command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nikola Forró --- packit_service/worker/jobs.py | 37 ++++++++++++++++++++++------------- tests/unit/test_jobs.py | 6 +++--- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/packit_service/worker/jobs.py b/packit_service/worker/jobs.py index ecf951650..7f7822167 100644 --- a/packit_service/worker/jobs.py +++ b/packit_service/worker/jobs.py @@ -659,6 +659,14 @@ def compare_jobs_without_triggers(a, b): bd.pop("trigger") return ad == bd + def event_is_koji_tag_command(): + commands = get_packit_commands_from_comment( + self.event.comment, self.service_config.comment_command_prefix + ) + if not commands: + return False + return commands[0] == "koji-tag" + matching_jobs: list[JobConfig] = [] if isinstance(self.event, PullRequestCommentPagureEvent): for job in self.event.packages_config.get_job_views(): @@ -668,13 +676,16 @@ def compare_jobs_without_triggers(a, b): in (JobConfigTriggerType.commit, JobConfigTriggerType.koji_build) and self.event.job_config_trigger_type == JobConfigTriggerType.pull_request ): - # avoid having duplicate koji_build jobs - if job.type != JobType.koji_build or not any( - j for j in matching_jobs if compare_jobs_without_triggers(job, j) - ): - # A koji_build or bodhi_update job with comment or koji_build trigger - # can be re-triggered by a Pagure comment in a PR - matching_jobs.append(job) + if job.type == JobType.koji_build: + # avoid having duplicate koji_build jobs + if any(j for j in matching_jobs if compare_jobs_without_triggers(job, j)): + continue + # in case of koji-tag command, match only koji_build jobs with sidetag group + if event_is_koji_tag_command() and not job.sidetag_group: + continue + # A koji_build or bodhi_update job with comment or koji_build trigger + # can be re-triggered by a Pagure comment in a PR + matching_jobs.append(job) elif ( job.type == JobType.pull_from_upstream and job.trigger == JobConfigTriggerType.release @@ -690,14 +701,12 @@ def compare_jobs_without_triggers(a, b): and job.trigger in (JobConfigTriggerType.commit, JobConfigTriggerType.koji_build) and self.event.job_config_trigger_type == JobConfigTriggerType.release - # avoid having duplicate koji_build jobs - and ( - job.type != JobType.koji_build - or not any( - j for j in matching_jobs if compare_jobs_without_triggers(job, j) - ) - ) ): + # avoid having duplicate koji_build jobs + if job.type == JobType.koji_build and any( + j for j in matching_jobs if compare_jobs_without_triggers(job, j) + ): + continue # A koji_build/bodhi_update can be re-triggered by a # comment in a issue in the repository issues # after a failed release event diff --git a/tests/unit/test_jobs.py b/tests/unit/test_jobs.py index cda483980..cd4631663 100644 --- a/tests/unit/test_jobs.py +++ b/tests/unit/test_jobs.py @@ -3065,7 +3065,7 @@ def __init__(self): packages={"package": CommonPackageConfig()}, ), ], - {}, + {"comment": "test"}, ), pytest.param( PullRequestCommentPagureEvent, @@ -3094,7 +3094,7 @@ def __init__(self): packages={"package": CommonPackageConfig()}, ), ], - {}, + {"comment": "test"}, ), pytest.param( CheckRerunPullRequestEvent, @@ -3370,7 +3370,7 @@ def __init__(self): packages={"package": CommonPackageConfig()}, ), ], - {}, + {"comment": "test"}, ), ], ) From 44eb67ad50f0e684ddf67918ea87e5db3588910e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Mon, 11 Nov 2024 18:38:13 +0100 Subject: [PATCH 2/2] Fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nikola Forró --- packit_service/worker/jobs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packit_service/worker/jobs.py b/packit_service/worker/jobs.py index 7f7822167..3ad461152 100644 --- a/packit_service/worker/jobs.py +++ b/packit_service/worker/jobs.py @@ -683,7 +683,7 @@ def event_is_koji_tag_command(): # in case of koji-tag command, match only koji_build jobs with sidetag group if event_is_koji_tag_command() and not job.sidetag_group: continue - # A koji_build or bodhi_update job with comment or koji_build trigger + # A koji_build or bodhi_update job with commit or koji_build trigger # can be re-triggered by a Pagure comment in a PR matching_jobs.append(job) elif (