Skip to content

Commit

Permalink
fix(events): improve the naming for “push” events
Browse files Browse the repository at this point in the history
As discussed in the PR introducing this refactor, switch from not very
descriptive ‹push.Push› to ‹push.Commit› and in case of GitLab events
also ‹push.TagPush› to ‹push.Tag›.

Signed-off-by: Matej Focko <[email protected]>
  • Loading branch information
mfocko committed Jan 28, 2025
1 parent 55f3c09 commit 2590dac
Show file tree
Hide file tree
Showing 23 changed files with 87 additions and 87 deletions.
10 changes: 5 additions & 5 deletions packit_service/worker/allowlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
koji.Build,
pagure.pr.Comment,
pagure.pr.Synchronize,
pagure.push.Push,
pagure.push.Commit,
testing_farm.Result,
]

Expand Down Expand Up @@ -288,7 +288,7 @@ def _check_unchecked_event(

def _check_release_push_event(
self,
event: Union[github.release.Release, github.push.Push, gitlab.push.Push],
event: Union[github.release.Release, github.push.Commit, gitlab.push.Commit],
project: GitProject,
job_configs: Iterable[JobConfig],
) -> bool:
Expand Down Expand Up @@ -499,7 +499,7 @@ def check_and_report(
Callable,
] = {
( # events that are not checked against allowlist
pagure.push.Push,
pagure.push.Commit,
pagure.pr.Synchronize,
pagure.pr.Comment,
copr.CoprBuild,
Expand All @@ -516,8 +516,8 @@ def check_and_report(
(
github.release.Release,
gitlab.release.Release,
github.push.Push,
gitlab.push.Push,
github.push.Commit,
gitlab.push.Commit,
): self._check_release_push_event,
(
github.pr.Synchronize,
Expand Down
6 changes: 3 additions & 3 deletions packit_service/worker/checker/distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

class LabelsOnDistgitPR(Checker, GetPagurePullRequestMixin):
def pre_check(self) -> bool:
if self.data.event_type not in (pagure.push.Push.event_type(),) or not (
if self.data.event_type not in (pagure.push.Commit.event_type(),) or not (
self.job_config.require.label.present or self.job_config.require.label.absent
):
return True
Expand All @@ -46,7 +46,7 @@ def pre_check(self) -> bool:
class PermissionOnDistgit(Checker, GetPagurePullRequestMixin):
def pre_check(self) -> bool:
if self.data.event_type in (
pagure.push.Push.event_type(),
pagure.push.Commit.event_type(),
koji.BuildTag.event_type(),
) and self.data.git_ref not in (
configured_branches := get_branches(
Expand All @@ -61,7 +61,7 @@ def pre_check(self) -> bool:
)
return False

if self.data.event_type in (pagure.push.Push.event_type(),):
if self.data.event_type in (pagure.push.Commit.event_type(),):
if self.pull_request:
pr_author = self.get_pr_author()
logger.debug(f"PR author: {pr_author}")
Expand Down
6 changes: 3 additions & 3 deletions packit_service/worker/events/event_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ def _add_project_object_and_event(self):
commit_sha=self.commit_sha,
)
elif self.event_type in {
"github.push.Push",
"gitlab.push.Push",
"pagure.push.Push",
"github.push.Commit",
"gitlab.push.Commit",
"pagure.push.Commit",
"github.check.Commit",
}:
(
Expand Down
4 changes: 2 additions & 2 deletions packit_service/worker/events/github/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from packit_service.worker.events.github.abstract import GithubEvent


class Push(AddBranchPushEventToDb, GithubEvent):
class Commit(AddBranchPushEventToDb, GithubEvent):
def __init__(
self,
repo_namespace: str,
Expand All @@ -23,4 +23,4 @@ def __init__(

@classmethod
def event_type(cls) -> str:
return "github.push.Push"
return "github.push.Commit"
8 changes: 4 additions & 4 deletions packit_service/worker/events/gitlab/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from packit_service.worker.events.gitlab.abstract import GitlabEvent


class Push(AddBranchPushEventToDb, GitlabEvent):
class Commit(AddBranchPushEventToDb, GitlabEvent):
def __init__(
self,
repo_namespace: str,
Expand All @@ -25,10 +25,10 @@ def __init__(

@classmethod
def event_type(cls) -> str:
return "gitlab.push.Push"
return "gitlab.push.Commit"


class TagPush(AddBranchPushEventToDb, GitlabEvent):
class Tag(AddBranchPushEventToDb, GitlabEvent):
def __init__(
self,
repo_namespace: str,
Expand All @@ -51,4 +51,4 @@ def __init__(

@classmethod
def event_type(cls) -> str:
return "gitlab.push.TagPush"
return "gitlab.push.Tag"
4 changes: 2 additions & 2 deletions packit_service/worker/events/pagure/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from packit_service.worker.events.pagure.abstract import PagureEvent


class Push(AddBranchPushEventToDb, PagureEvent):
class Commit(AddBranchPushEventToDb, PagureEvent):
def __init__(
self,
repo_namespace: str,
Expand All @@ -28,4 +28,4 @@ def __init__(

@classmethod
def event_type(cls) -> str:
return "pagure.push.Push"
return "pagure.push.Commit"
4 changes: 2 additions & 2 deletions packit_service/worker/handlers/copr.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
@reacts_to(github.release.Release)
@reacts_to(gitlab.release.Release)
@reacts_to(github.pr.Synchronize)
@reacts_to(github.push.Push)
@reacts_to(gitlab.push.Push)
@reacts_to(github.push.Commit)
@reacts_to(gitlab.push.Commit)
@reacts_to(gitlab.mr.Synchronize)
@reacts_to(github.check.Rerun)
@reacts_to(abstract.comment.Commit)
Expand Down
6 changes: 3 additions & 3 deletions packit_service/worker/handlers/distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __exit__(self, type, value, traceback):


@configured_as(job_type=JobType.sync_from_downstream)
@reacts_to(event=pagure.push.Push)
@reacts_to(event=pagure.push.Commit)
class SyncFromDownstream(
JobHandler,
GetProjectToSyncMixin,
Expand Down Expand Up @@ -1109,7 +1109,7 @@ def report_in_issue_repository(self, errors: dict[str, str]) -> None:

@configured_as(job_type=JobType.koji_build)
@run_for_comment(command="koji-build")
@reacts_to(event=pagure.push.Push)
@reacts_to(event=pagure.push.Commit)
@reacts_to(event=pagure.pr.Comment)
class DownstreamKojiBuildHandler(
AbstractDownstreamKojiBuildHandler,
Expand Down Expand Up @@ -1151,7 +1151,7 @@ def get_trigger_type_description(self) -> str:
f"Fedora Koji build was re-triggered "
f"by comment in dist-git PR id {self.data.pr_id}."
)
elif self.data.event_type == pagure.push.Push.event_type():
elif self.data.event_type == pagure.push.Commit.event_type():
trigger_type_description += (
f"Fedora Koji build was triggered by push with sha {self.data.commit_sha}."
)
Expand Down
4 changes: 2 additions & 2 deletions packit_service/worker/handlers/koji.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
@reacts_to(github.release.Release)
@reacts_to(gitlab.release.Release)
@reacts_to(github.pr.Synchronize)
@reacts_to(github.push.Push)
@reacts_to(gitlab.push.Push)
@reacts_to(github.push.Commit)
@reacts_to(gitlab.push.Commit)
@reacts_to(gitlab.mr.Synchronize)
@reacts_to(abstract.comment.PullRequest)
@reacts_to(github.check.Rerun)
Expand Down
4 changes: 2 additions & 2 deletions packit_service/worker/handlers/testing_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
@reacts_to(github.release.Release)
@reacts_to(gitlab.release.Release)
@reacts_to(github.pr.Synchronize)
@reacts_to(github.push.Push)
@reacts_to(gitlab.push.Push)
@reacts_to(github.push.Commit)
@reacts_to(gitlab.push.Commit)
@reacts_to(gitlab.mr.Synchronize)
@reacts_to(abstract.comment.PullRequest)
@reacts_to(github.check.PullRequest)
Expand Down
4 changes: 2 additions & 2 deletions packit_service/worker/helpers/testing_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ def build_required(self) -> bool:
# for comment event requesting copr build
self.metadata.event_type
in (
github.push.Push.event_type(),
github.push.Commit.event_type(),
github.pr.Synchronize.event_type(),
github.commit.Comment.event_type(),
gitlab.push.Push.event_type(),
gitlab.push.Commit.event_type(),
gitlab.mr.Synchronize.event_type(),
gitlab.commit.Comment.event_type(),
)
Expand Down
24 changes: 12 additions & 12 deletions packit_service/worker/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ def parse_event(
github.pr.Synchronize,
github.issue.Comment,
github.installation.Installation,
github.push.Push,
github.push.Commit,
github.release.Release,
gitlab.issue.Comment,
gitlab.mr.Comment,
gitlab.mr.Synchronize,
gitlab.pipeline.Pipeline,
gitlab.push.Push,
gitlab.push.TagPush,
gitlab.push.Commit,
gitlab.push.Tag,
gitlab.release.Release,
koji.Build,
koji.BuildTag,
Expand All @@ -96,7 +96,7 @@ def parse_event(
pagure.pr.Comment,
pagure.pr.Flag,
pagure.pr.Synchronize,
pagure.push.Push,
pagure.push.Commit,
testing_farm.Result,
vm_image.Result,
]
Expand Down Expand Up @@ -411,7 +411,7 @@ def get_gitlab_push_common_data(event) -> tuple:
return actor, project_url, parsed_url, ref, head_commit

@staticmethod
def parse_gitlab_tag_push_event(event) -> Optional[gitlab.push.TagPush]:
def parse_gitlab_tag_push_event(event) -> Optional[gitlab.push.Tag]:
"""
Look into the provided event and see if it's one for a new push to the gitlab branch.
https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#tag-events
Expand Down Expand Up @@ -440,7 +440,7 @@ def parse_gitlab_tag_push_event(event) -> Optional[gitlab.push.TagPush]:
f"url={project_url}.",
)

return gitlab.push.TagPush(
return gitlab.push.Tag(
repo_namespace=parsed_url.namespace,
repo_name=parsed_url.repo,
actor=actor,
Expand All @@ -452,7 +452,7 @@ def parse_gitlab_tag_push_event(event) -> Optional[gitlab.push.TagPush]:
)

@staticmethod
def parse_gitlab_push_event(event) -> Optional[gitlab.push.Push]:
def parse_gitlab_push_event(event) -> Optional[gitlab.push.Commit]:
"""
Look into the provided event and see if it's one for a new push to the gitlab branch.
https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#push-events
Expand All @@ -473,7 +473,7 @@ def parse_gitlab_push_event(event) -> Optional[gitlab.push.Push]:
logger.info(e)
return None

return gitlab.push.Push(
return gitlab.push.Commit(
repo_namespace=parsed_url.namespace,
repo_name=parsed_url.repo,
git_ref=ref,
Expand All @@ -482,7 +482,7 @@ def parse_gitlab_push_event(event) -> Optional[gitlab.push.Push]:
)

@staticmethod
def parse_github_push_event(event) -> Optional[github.push.Push]:
def parse_github_push_event(event) -> Optional[github.push.Commit]:
"""
Look into the provided event and see if it's one for a new push to the github branch.
"""
Expand Down Expand Up @@ -525,7 +525,7 @@ def parse_github_push_event(event) -> Optional[github.push.Push]:

repo_url = nested_get(event, "repository", "html_url")

return github.push.Push(
return github.push.Commit(
repo_namespace=repo_namespace,
repo_name=repo_name,
git_ref=ref,
Expand Down Expand Up @@ -1165,7 +1165,7 @@ def parse_release_event(event) -> Optional[github.release.Release]:
return github.release.Release(repo_namespace, repo_name, release_ref, https_url)

@staticmethod
def parse_pagure_push_event(event) -> Optional[pagure.push.Push]:
def parse_pagure_push_event(event) -> Optional[pagure.push.Commit]:
"""this corresponds to dist-git event when someone pushes new commits"""
topic = event.get("topic")
if topic != "org.fedoraproject.prod.pagure.git.receive":
Expand Down Expand Up @@ -1198,7 +1198,7 @@ def parse_pagure_push_event(event) -> Optional[pagure.push.Push]:

dg_pr_id = nested_get(event, "pull_request_id")

return pagure.push.Push(
return pagure.push.Commit(
repo_namespace=dg_repo_namespace,
repo_name=dg_repo_name,
git_ref=dg_branch,
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def github_pr_event(github_pr_webhook) -> events.github.pr.Synchronize:


@pytest.fixture(scope="module")
def github_push_event(github_push_webhook) -> events.github.push.Push:
def github_push_event(github_push_webhook) -> events.github.push.Commit:
return Parser.parse_github_push_event(github_push_webhook)


Expand All @@ -523,7 +523,7 @@ def distgit_push_packit():


@pytest.fixture(scope="module")
def distgit_push_event(distgit_push_packit) -> events.pagure.push.Push:
def distgit_push_event(distgit_push_packit) -> events.pagure.push.Commit:
return Parser.parse_pagure_push_event(distgit_push_packit)


Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_koji_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_koji_build_error_msg(distgit_push_packit):
db_project_event = (
flexmock().should_receive("get_project_event_object").and_return(db_project_object).mock()
)
flexmock(pagure.push.Push).should_receive("db_project_object").and_return(
flexmock(pagure.push.Commit).should_receive("db_project_object").and_return(
db_project_object,
)
flexmock(GitBranchModel).should_receive("get_or_create").and_return(
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/events/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_parse_pr(github_pr_webhook):
def test_parse_github_push(github_push_branch):
event_object = Parser.parse_event(github_push_branch)

assert isinstance(event_object, push.Push)
assert isinstance(event_object, push.Commit)
assert event_object.repo_namespace == "packit-service"
assert event_object.repo_name == "hello-world"
assert event_object.commit_sha == "04885ff850b0fa0e206cd09db73565703d48f99b"
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_parse_github_push(github_push_branch):
def test_parse_github_push_branch(github_push_branch):
event_object = Parser.parse_event(github_push_branch)

assert isinstance(event_object, push.Push)
assert isinstance(event_object, push.Commit)
assert event_object.repo_namespace == "packit-service"
assert event_object.repo_name == "hello-world"
assert event_object.commit_sha == "04885ff850b0fa0e206cd09db73565703d48f99b"
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/events/test_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_parse_gitlab_release(gitlab_release):
def test_parse_gitlab_tag_push(gitlab_tag_push):
event_object = Parser.parse_event(gitlab_tag_push)

assert isinstance(event_object, push.TagPush)
assert isinstance(event_object, push.Tag)
assert event_object.repo_namespace == "fedora/src"
assert event_object.repo_name == "python-teamcity-messages"
assert event_object.commit_sha == "6147b3de219ecdda30ba727cf74a0414ca1e618a"
Expand Down Expand Up @@ -287,7 +287,7 @@ def test_parse_gitlab_issue_comment(gitlab_issue_comment):
def test_parse_gitlab_push(gitlab_push):
event_object = Parser.parse_event(gitlab_push)

assert isinstance(event_object, push.Push)
assert isinstance(event_object, push.Commit)
assert event_object.repo_namespace == "testing/packit"
assert event_object.repo_name == "hello-there"
assert event_object.commit_sha == "cb2859505e101785097e082529dced35bbee0c8f"
Expand Down Expand Up @@ -315,7 +315,7 @@ def test_parse_gitlab_push(gitlab_push):
def test_parse_gitlab_push_many_commits(gitlab_push_many_commits):
event_object = Parser.parse_event(gitlab_push_many_commits)

assert isinstance(event_object, push.Push)
assert isinstance(event_object, push.Commit)
assert event_object.repo_namespace == "packit-service/rpms"
assert event_object.repo_name == "open-vm-tools"
assert event_object.commit_sha == "15af92227f9e965b392e85ba2f08a41a5aeb278a"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/events/test_pagure.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_parse_pagure_pull_request_comment(pagure_pr_comment_added):
def test_distgit_pagure_push(distgit_commit):
event_object = Parser.parse_event(distgit_commit)

assert isinstance(event_object, push.Push)
assert isinstance(event_object, push.Commit)
assert event_object.repo_namespace == "rpms"
assert event_object.repo_name == "buildah"
assert event_object.commit_sha == "abcd"
Expand Down
Loading

0 comments on commit 2590dac

Please sign in to comment.