Skip to content

Commit

Permalink
fix(events): rename from ‹Synchronize› to ‹Action›
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Focko <[email protected]>
  • Loading branch information
mfocko committed Jan 28, 2025
1 parent 2590dac commit b5ff71c
Show file tree
Hide file tree
Showing 27 changed files with 130 additions and 132 deletions.
12 changes: 6 additions & 6 deletions packit_service/worker/allowlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
koji.Task,
koji.Build,
pagure.pr.Comment,
pagure.pr.Synchronize,
pagure.pr.Action,
pagure.push.Commit,
testing_farm.Result,
]
Expand Down Expand Up @@ -314,9 +314,9 @@ def _check_release_push_event(
def _check_pr_event(
self,
event: Union[
github.pr.Synchronize,
github.pr.Action,
github.pr.Comment,
gitlab.mr.Synchronize,
gitlab.mr.Action,
gitlab.mr.Comment,
],
project: GitProject,
Expand Down Expand Up @@ -500,7 +500,7 @@ def check_and_report(
] = {
( # events that are not checked against allowlist
pagure.push.Commit,
pagure.pr.Synchronize,
pagure.pr.Action,
pagure.pr.Comment,
copr.CoprBuild,
testing_farm.Result,
Expand All @@ -520,9 +520,9 @@ def check_and_report(
gitlab.push.Commit,
): self._check_release_push_event,
(
github.pr.Synchronize,
github.pr.Action,
github.pr.Comment,
gitlab.mr.Synchronize,
gitlab.mr.Action,
gitlab.mr.Comment,
): self._check_pr_event,
(
Expand Down
2 changes: 1 addition & 1 deletion packit_service/worker/checker/copr.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def pre_check(
self,
) -> bool:
if (
self.data.event_type == gitlab.mr.Synchronize.event_type()
self.data.event_type == gitlab.mr.Action.event_type()
and self.data.event_dict["action"] == gitlab.enums.Action.closed.value
):
# Not interested in closed merge requests
Expand Down
6 changes: 3 additions & 3 deletions packit_service/worker/checker/koji.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def pre_check(self) -> bool:
class PermissionOnKoji(Checker, GetKojiBuildJobHelperMixin):
def pre_check(self) -> bool:
if (
self.data.event_type == gitlab.mr.Synchronize.event_type()
self.data.event_type == gitlab.mr.Action.event_type()
and self.data.event_dict["action"] == gitlab.enums.Action.closed.value
):
# Not interested in closed merge requests
return False

if self.data.event_type in (
github.pr.Synchronize.event_type(),
gitlab.mr.Synchronize.event_type(),
github.pr.Action.event_type(),
gitlab.mr.Action.event_type(),
):
user_can_merge_pr = self.project.can_merge_pr(self.data.actor)
if not (user_can_merge_pr or self.data.actor in self.service_config.admins):
Expand Down
2 changes: 1 addition & 1 deletion packit_service/worker/checker/testing_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class IsEventOk(
):
def pre_check(self) -> bool:
if (
self.data.event_type == gitlab.mr.Synchronize.event_type()
self.data.event_type == gitlab.mr.Action.event_type()
and self.data.event_dict["action"] == gitlab.enums.Action.closed.value
):
# Not interested in closed merge requests
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 @@ -152,9 +152,9 @@ def _add_project_object_and_event(self):
# TODO, do a better job
# Probably, try to recreate original classes.
if self.event_type in {
"github.pr.Synchronize",
"pagure.pr.Synchronize",
"gitlab.mr.Synchronize",
"github.pr.Action",
"pagure.pr.Action",
"gitlab.mr.Action",
"github.pr.Comment",
"pagure.pr.Comment",
"gitlab.mr.Comment",
Expand Down
4 changes: 2 additions & 2 deletions packit_service/worker/events/github/pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from packit_service.worker.events.github.abstract import GithubEvent


class Synchronize(AddPullRequestEventToDb, GithubEvent):
class Action(AddPullRequestEventToDb, GithubEvent):
def __init__(
self,
action: PullRequestAction,
Expand Down Expand Up @@ -43,7 +43,7 @@ def __init__(

@classmethod
def event_type(cls) -> str:
return "github.pr.Synchronize"
return "github.pr.Action"

def get_dict(self, default_dict: Optional[dict] = None) -> dict:
result = super().get_dict()
Expand Down
10 changes: 5 additions & 5 deletions packit_service/worker/events/gitlab/mr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
)

from .abstract import GitlabEvent
from .enums import Action
from .enums import Action as GitlabAction


class Synchronize(AddPullRequestEventToDb, GitlabEvent):
class Action(AddPullRequestEventToDb, GitlabEvent):
def __init__(
self,
action: Action,
action: GitlabAction,
actor: str,
object_id: int,
object_iid: int,
Expand Down Expand Up @@ -62,7 +62,7 @@ def __init__(

@classmethod
def event_type(cls) -> str:
return "gitlab.mr.Synchronize"
return "gitlab.mr.Action"

def get_dict(self, default_dict: Optional[dict] = None) -> dict:
result = super().get_dict()
Expand All @@ -79,7 +79,7 @@ def get_base_project(self) -> GitProject:
class Comment(AbstractPRCommentEvent, GitlabEvent):
def __init__(
self,
action: Action,
action: GitlabAction,
object_id: int,
object_iid: int,
source_repo_namespace: str,
Expand Down
4 changes: 2 additions & 2 deletions packit_service/worker/events/pagure/pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def repo_name(self) -> Optional[str]:
return self.repo_url.repo if self.repo_url else None


class Synchronize(AddPullRequestEventToDb, PagureEvent):
class Action(AddPullRequestEventToDb, PagureEvent):
def __init__(
self,
action: PullRequestAction,
Expand Down Expand Up @@ -176,7 +176,7 @@ def __init__(

@classmethod
def event_type(cls) -> str:
return "pagure.pr.Synchronize"
return "pagure.pr.Action"

def get_dict(self, default_dict: Optional[dict] = None) -> dict:
result = super().get_dict()
Expand Down
4 changes: 2 additions & 2 deletions packit_service/worker/handlers/copr.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@
@run_for_check_rerun(prefix="rpm-build")
@reacts_to(github.release.Release)
@reacts_to(gitlab.release.Release)
@reacts_to(github.pr.Synchronize)
@reacts_to(github.pr.Action)
@reacts_to(github.push.Commit)
@reacts_to(gitlab.push.Commit)
@reacts_to(gitlab.mr.Synchronize)
@reacts_to(gitlab.mr.Action)
@reacts_to(github.check.Rerun)
@reacts_to(abstract.comment.Commit)
@reacts_to(abstract.comment.PullRequest)
Expand Down
2 changes: 1 addition & 1 deletion packit_service/worker/handlers/distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ def run(self) -> TaskResults:
return super().run()


@reacts_to_as_fedora_ci(event=pagure.pr.Synchronize)
@reacts_to_as_fedora_ci(event=pagure.pr.Action)
class DownstreamKojiScratchBuildHandler(
RetriableJobHandler, ConfigFromUrlMixin, LocalProjectMixin, PackitAPIWithDownstreamMixin
):
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 @@ -81,10 +81,10 @@
@run_for_check_rerun(prefix="koji-build")
@reacts_to(github.release.Release)
@reacts_to(gitlab.release.Release)
@reacts_to(github.pr.Synchronize)
@reacts_to(github.pr.Action)
@reacts_to(github.push.Commit)
@reacts_to(gitlab.push.Commit)
@reacts_to(gitlab.mr.Synchronize)
@reacts_to(gitlab.mr.Action)
@reacts_to(abstract.comment.PullRequest)
@reacts_to(github.check.Rerun)
class KojiBuildHandler(
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 @@ -72,10 +72,10 @@
@run_for_check_rerun(prefix="testing-farm")
@reacts_to(github.release.Release)
@reacts_to(gitlab.release.Release)
@reacts_to(github.pr.Synchronize)
@reacts_to(github.pr.Action)
@reacts_to(github.push.Commit)
@reacts_to(gitlab.push.Commit)
@reacts_to(gitlab.mr.Synchronize)
@reacts_to(gitlab.mr.Action)
@reacts_to(abstract.comment.PullRequest)
@reacts_to(github.check.PullRequest)
@reacts_to(github.check.Commit)
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 @@ -334,10 +334,10 @@ def build_required(self) -> bool:
self.metadata.event_type
in (
github.push.Commit.event_type(),
github.pr.Synchronize.event_type(),
github.pr.Action.event_type(),
github.commit.Comment.event_type(),
gitlab.push.Commit.event_type(),
gitlab.mr.Synchronize.event_type(),
gitlab.mr.Action.event_type(),
gitlab.commit.Comment.event_type(),
)
or self.is_copr_build_comment_event()
Expand Down
2 changes: 1 addition & 1 deletion packit_service/worker/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def process(self) -> list[TaskResults]:
# should we comment about not processing if the comment is not
# on the issue created by us or not in packit/notifications?
elif (
isinstance(self.event, (pagure.pr.Synchronize, koji.Task))
isinstance(self.event, (pagure.pr.Action, koji.Task))
and self.event.db_project_object
and (url := self.event.db_project_object.project.project_url)
and url in self.service_config.enabled_projects_for_fedora_ci
Expand Down
18 changes: 9 additions & 9 deletions packit_service/worker/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ def parse_event(
github.check.PullRequest,
github.check.Release,
github.pr.Comment,
github.pr.Synchronize,
github.pr.Action,
github.issue.Comment,
github.installation.Installation,
github.push.Commit,
github.release.Release,
gitlab.issue.Comment,
gitlab.mr.Comment,
gitlab.mr.Synchronize,
gitlab.mr.Action,
gitlab.pipeline.Pipeline,
gitlab.push.Commit,
gitlab.push.Tag,
Expand All @@ -95,7 +95,7 @@ def parse_event(
openscanhub.task.Started,
pagure.pr.Comment,
pagure.pr.Flag,
pagure.pr.Synchronize,
pagure.pr.Action,
pagure.push.Commit,
testing_farm.Result,
vm_image.Result,
Expand Down Expand Up @@ -158,7 +158,7 @@ def parse_event(
return None

@staticmethod
def parse_mr_event(event) -> Optional[gitlab.mr.Synchronize]:
def parse_mr_event(event) -> Optional[gitlab.mr.Action]:
"""Look into the provided event and see if it's one for a new gitlab MR."""
if event.get("object_kind") != "merge_request":
return None
Expand Down Expand Up @@ -220,7 +220,7 @@ def parse_mr_event(event) -> Optional[gitlab.mr.Synchronize]:
description = nested_get(event, "object_attributes", "description")
url = nested_get(event, "object_attributes", "url")

return gitlab.mr.Synchronize(
return gitlab.mr.Action(
action=gitlab.enums.Action[action],
actor=actor,
object_id=object_id,
Expand All @@ -241,7 +241,7 @@ def parse_mr_event(event) -> Optional[gitlab.mr.Synchronize]:
)

@staticmethod
def parse_pr_event(event) -> Optional[github.pr.Synchronize]:
def parse_pr_event(event) -> Optional[github.pr.Action]:
"""Look into the provided event and see if it's one for a new github PR."""
if not event.get("pull_request"):
return None
Expand Down Expand Up @@ -293,7 +293,7 @@ def parse_pr_event(event) -> Optional[github.pr.Synchronize]:

commit_sha = nested_get(event, "pull_request", "head", "sha")
https_url = event["repository"]["html_url"]
return github.pr.Synchronize(
return github.pr.Action(
action=PullRequestAction[action],
pr_id=pr_id,
base_repo_namespace=base_repo_namespace,
Expand Down Expand Up @@ -1673,7 +1673,7 @@ def parse_pagure_pull_request_comment_event(
@staticmethod
def parse_pagure_pull_request_event(
event,
) -> Optional[pagure.pr.Synchronize]:
) -> Optional[pagure.pr.Action]:
if (topic := event.get("topic", "")) not in (
"org.fedoraproject.prod.pagure.pull-request.new",
"org.fedoraproject.prod.pagure.pull-request.updated",
Expand All @@ -1700,7 +1700,7 @@ def parse_pagure_pull_request_event(
commit_sha = event["pullrequest"]["commit_stop"]
target_branch = event["pullrequest"]["branch"]

return pagure.pr.Synchronize(
return pagure.pr.Action(
action=PullRequestAction[action],
pr_id=pr_id,
base_repo_namespace=base_repo_namespace,
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def github_vm_image_build_comment():


@pytest.fixture(scope="module")
def github_pr_event(github_pr_webhook) -> events.github.pr.Synchronize:
def github_pr_event(github_pr_webhook) -> events.github.pr.Action:
return Parser.parse_pr_event(github_pr_webhook)


Expand All @@ -528,7 +528,7 @@ def distgit_push_event(distgit_push_packit) -> events.pagure.push.Commit:


@pytest.fixture(scope="module")
def gitlab_mr_event(gitlab_mr_webhook) -> events.gitlab.mr.Synchronize:
def gitlab_mr_event(gitlab_mr_webhook) -> events.gitlab.mr.Action:
return Parser.parse_mr_event(gitlab_mr_webhook)


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 @@ -131,7 +131,7 @@ def test_parse_release(github_release_webhook):
def test_parse_pr(github_pr_webhook):
event_object = Parser.parse_event(github_pr_webhook)

assert isinstance(event_object, pr.Synchronize)
assert isinstance(event_object, pr.Action)
assert event_object.action == PullRequestAction.opened
assert event_object.pr_id == 342
assert event_object.base_repo_namespace == "lbarcziova"
Expand Down Expand Up @@ -222,7 +222,7 @@ def test_parse_github_push_branch(github_push_branch):
def test_get_project_pr(github_pr_webhook, mock_config):
event_object = Parser.parse_event(github_pr_webhook)

assert isinstance(event_object, pr.Synchronize)
assert isinstance(event_object, pr.Action)

assert isinstance(event_object.project, GithubProject)
assert isinstance(event_object.project.service, GithubService)
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 @@ -124,7 +124,7 @@ def test_parse_gitlab_tag_push(gitlab_tag_push):
def test_parse_mr(merge_request):
event_object = Parser.parse_event(merge_request)

assert isinstance(event_object, mr.Synchronize)
assert isinstance(event_object, mr.Action)
assert event_object.action == enums.Action.opened
assert event_object.object_id == 58759529
assert event_object.identifier == "1"
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_parse_mr(merge_request):

def test_parse_mr_action(merge_request_update):
event_object = Parser.parse_event(merge_request_update)
assert isinstance(event_object, mr.Synchronize)
assert isinstance(event_object, mr.Action)
assert event_object.action == enums.Action.update
assert event_object.commit_sha == "45e272a57335e4e308f3176df6e9226a9e7805a9"
assert event_object.oldrev == "94ccba9f986629e24b432c11d9c7fd20bb2ea51d"
Expand All @@ -183,7 +183,7 @@ def test_parse_mr_action(merge_request_update):

def test_parse_mr_closed(merge_request_closed):
event_object = Parser.parse_event(merge_request_closed)
assert isinstance(event_object, mr.Synchronize)
assert isinstance(event_object, mr.Action)
assert event_object.action == enums.Action.closed


Expand Down
Loading

0 comments on commit b5ff71c

Please sign in to comment.