Skip to content

Commit

Permalink
Adjust check of dist-git PRs for Koji builds (#2275)
Browse files Browse the repository at this point in the history
Adjust check of dist-git PRs for Koji builds

If the dist-git push comes from a PR, check that
the specfile was changed in that PR.
Related to #2271
Needs packit/ogr#826
TODO:

 Write new tests or update the old ones to cover new functionality.


RELEASE NOTES BEGIN
We have fixed a bug of not running Koji builds for Packit PRs with multiple commits if the last commit of the PR did not contain the specfile change.
RELEASE NOTES END

Reviewed-by: Nikola Forró
Reviewed-by: Laura Barcziová
Reviewed-by: František Lachman <[email protected]>
Reviewed-by: Maja Massarini
  • Loading branch information
softwarefactory-project-zuul[bot] authored Dec 15, 2023
2 parents 731496a + e9a91cf commit 93e4d9b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packit_service/worker/checker/distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@


class PermissionOnDistgit(Checker, GetPagurePullRequestMixin):
def contains_specfile_change(self):
"""
Check whether the dist-git commit contains
any specfile change (do the check only for pushes from PRs,
with direct pushes we do the filtering in fedmsg).
"""
if not self.pull_request:
return True

pr_id = self.pull_request.id
diff = self.project.get_pr_files_diff(pr_id) or {}
if not any(change.endswith(".spec") for change in diff):
logger.info(f"PR {pr_id} does not contain a specfile change.")
return False
return True

def pre_check(self) -> bool:
if self.data.event_type in (PushPagureEvent.__name__,):
if self.data.git_ref not in (
Expand All @@ -40,6 +56,16 @@ def pre_check(self) -> bool:
return False

if self.data.event_dict["committer"] == "pagure":
if not self.pull_request:
logger.debug(
"Not able to get the pull request "
"(may not be the head commit of the PR)."
)
return False

if not self.contains_specfile_change():
return False

pr_author = self.get_pr_author()
logger.debug(f"PR author: {pr_author}")
if pr_author not in self.job_config.allowed_pr_authors:
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/test_dg_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,11 +925,15 @@ def test_precheck_koji_build_push_pr(
flexmock(PagureProject).should_receive("get_pr_list").and_return(
[
flexmock(
id=5,
author=pr_author,
head_commit="ad0c308af91da45cf40b253cd82f07f63ea9cbbf",
)
]
)
flexmock(PagureProject).should_receive("get_pr_files_diff").with_args(5).and_return(
{"package.spec": []}
)
package_config = (
PackageConfig(
jobs=jobs,
Expand Down

0 comments on commit 93e4d9b

Please sign in to comment.