Skip to content

Commit

Permalink
Deduplicate koji_build jobs when doing explicit matching (#2587)
Browse files Browse the repository at this point in the history
Deduplicate koji_build jobs when doing explicit matching

Fixes #2565.

Reviewed-by: Laura Barcziová
  • Loading branch information
softwarefactory-project-zuul[bot] authored Oct 18, 2024
2 parents a4a3ecd + 25f93a3 commit 89c111a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 9 deletions.
39 changes: 30 additions & 9 deletions packit_service/worker/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,16 @@ def check_explicit_matching(self) -> List[JobConfig]:
Returns:
List of job configs.
"""
matching_jobs = []

def compare_jobs_without_triggers(a, b):
# check if two jobs are the same or differ only in trigger
ad = dict(a.__dict__)
ad.pop("trigger")
bd = dict(b.__dict__)
bd.pop("trigger")
return ad == bd

matching_jobs: List[JobConfig] = []
if isinstance(self.event, PullRequestCommentPagureEvent):
for job in self.event.packages_config.get_job_views():
if (
Expand All @@ -650,9 +659,15 @@ def check_explicit_matching(self) -> List[JobConfig]:
and self.event.job_config_trigger_type
== JobConfigTriggerType.pull_request
):
# 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)
# 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)
elif (
job.type == JobType.pull_from_upstream
and job.trigger == JobConfigTriggerType.release
Expand All @@ -671,11 +686,17 @@ def check_explicit_matching(self) -> List[JobConfig]:
and self.event.job_config_trigger_type
== JobConfigTriggerType.release
):
# A koji_build/bodhi_update can be re-triggered by a
# comment in a issue in the repository issues
# after a failed release event
# (which has created the issue)
matching_jobs.append(job)
# 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/bodhi_update can be re-triggered by a
# comment in a issue in the repository issues
# after a failed release event
# (which has created the issue)
matching_jobs.append(job)
elif isinstance(self.event, KojiBuildTagEvent):
# create a virtual job config
job_config = JobConfig(
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3328,6 +3328,45 @@ def __init__(self):
],
{},
),
pytest.param(
PullRequestCommentPagureEvent,
JobConfigTriggerType.pull_request,
[
JobConfig(
type=JobType.koji_build,
trigger=JobConfigTriggerType.commit,
sidetag_group="test",
packages={"package": CommonPackageConfig()},
),
JobConfig(
type=JobType.koji_build,
trigger=JobConfigTriggerType.koji_build,
sidetag_group="test",
packages={"package": CommonPackageConfig()},
),
JobConfig(
type=JobType.bodhi_update,
trigger=JobConfigTriggerType.koji_build,
sidetag_group="test",
packages={"package": CommonPackageConfig()},
),
],
[
JobConfig(
type=JobType.koji_build,
trigger=JobConfigTriggerType.commit,
sidetag_group="test",
packages={"package": CommonPackageConfig()},
),
JobConfig(
type=JobType.bodhi_update,
trigger=JobConfigTriggerType.koji_build,
sidetag_group="test",
packages={"package": CommonPackageConfig()},
),
],
{},
),
],
)
def test_get_jobs_matching_trigger(
Expand Down

0 comments on commit 89c111a

Please sign in to comment.