Skip to content

Commit

Permalink
Choose only jobs with sidetag group for koji-tag command (#2636)
Browse files Browse the repository at this point in the history
Choose only jobs with sidetag group for koji-tag command

The check is also in the handler, but doing it here prevents multiple The task was accepted messages.

Reviewed-by: Maja Massarini
Reviewed-by: Nikola Forró
  • Loading branch information
softwarefactory-project-zuul[bot] authored Nov 12, 2024
2 parents 10ec228 + 44eb67a commit 6ccf229
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
37 changes: 23 additions & 14 deletions packit_service/worker/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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 commit 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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3065,7 +3065,7 @@ def __init__(self):
packages={"package": CommonPackageConfig()},
),
],
{},
{"comment": "test"},
),
pytest.param(
PullRequestCommentPagureEvent,
Expand Down Expand Up @@ -3094,7 +3094,7 @@ def __init__(self):
packages={"package": CommonPackageConfig()},
),
],
{},
{"comment": "test"},
),
pytest.param(
CheckRerunPullRequestEvent,
Expand Down Expand Up @@ -3370,7 +3370,7 @@ def __init__(self):
packages={"package": CommonPackageConfig()},
),
],
{},
{"comment": "test"},
),
],
)
Expand Down

0 comments on commit 6ccf229

Please sign in to comment.