From 7f6c1148cad26f6b02f63a8fbeac49e144046706 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Mon, 28 Oct 2024 10:43:50 +0100 Subject: [PATCH] fix: reference GitHub Installation event explicitly Signed-off-by: Matej Focko --- alembic/versions/c6250555a36c_.py | 4 ++-- packit_service/worker/allowlist.py | 6 +++--- packit_service/worker/handlers/forges.py | 6 +++--- packit_service/worker/jobs.py | 4 ++-- packit_service/worker/parser.py | 8 ++++---- tests/unit/events/test_github.py | 4 ++-- tests_openshift/conftest.py | 6 +++--- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/alembic/versions/c6250555a36c_.py b/alembic/versions/c6250555a36c_.py index d3e3fdfd3..218f3534c 100644 --- a/alembic/versions/c6250555a36c_.py +++ b/alembic/versions/c6250555a36c_.py @@ -30,7 +30,7 @@ from alembic import op from packit_service.constants import ALLOWLIST_CONSTANTS -from packit_service.worker.events import InstallationEvent +from packit_service.worker.events import github # revision identifiers, used by Alembic. revision = "c6250555a36c" @@ -224,7 +224,7 @@ def db(cls) -> PersistentDict: class RedisInstallation(RedisModel): table_name = "github_installation" - event_data: InstallationEvent + event_data: github.installation.Installation class RedisBuild(RedisModel): diff --git a/packit_service/worker/allowlist.py b/packit_service/worker/allowlist.py index 31926c453..35909d4dd 100644 --- a/packit_service/worker/allowlist.py +++ b/packit_service/worker/allowlist.py @@ -27,7 +27,6 @@ AbstractCoprBuildEvent, CheckRerunEvent, EventData, - InstallationEvent, IssueCommentEvent, IssueCommentGitlabEvent, KojiTaskEvent, @@ -44,6 +43,7 @@ PushPagureEvent, ReleaseEvent, TestingFarmResultsEvent, + github, ) from packit_service.worker.events.comment import CommitCommentEvent from packit_service.worker.events.gitlab import ReleaseGitlabEvent @@ -61,7 +61,7 @@ PullRequestCommentPagureEvent, AbstractCoprBuildEvent, TestingFarmResultsEvent, - InstallationEvent, + github.installation.Installation, KojiTaskEvent, KojiBuildEvent, CheckRerunEvent, @@ -518,7 +518,7 @@ def check_and_report( PullRequestCommentPagureEvent, AbstractCoprBuildEvent, TestingFarmResultsEvent, - InstallationEvent, + github.installation.Installation, KojiTaskEvent, KojiBuildEvent, KojiBuildTagEvent, diff --git a/packit_service/worker/handlers/forges.py b/packit_service/worker/handlers/forges.py index a3c925a6a..188859c80 100644 --- a/packit_service/worker/handlers/forges.py +++ b/packit_service/worker/handlers/forges.py @@ -26,8 +26,8 @@ from packit_service.worker.checker.abstract import Checker from packit_service.worker.checker.forges import IsIssueInNotificationRepoChecker from packit_service.worker.events import ( - InstallationEvent, IssueCommentEvent, + github, ) from packit_service.worker.handlers.abstract import ( JobHandler, @@ -44,7 +44,7 @@ logger = logging.getLogger(__name__) -@reacts_to(event=InstallationEvent) +@reacts_to(event=github.installation.Installation) class GithubAppInstallationHandler( JobHandler, ConfigFromEventMixin, @@ -66,7 +66,7 @@ def __init__( event=event, ) - self.installation_event = InstallationEvent.from_event_dict(event) + self.installation_event = github.installation.Installation.from_event_dict(event) self.account_type = self.installation_event.account_type self.account_login = self.installation_event.account_login self.sender_login = self.installation_event.sender_login diff --git a/packit_service/worker/jobs.py b/packit_service/worker/jobs.py index ecf951650..fb753224a 100644 --- a/packit_service/worker/jobs.py +++ b/packit_service/worker/jobs.py @@ -34,9 +34,9 @@ CheckRerunEvent, Event, EventData, - InstallationEvent, IssueCommentEvent, PullRequestCommentPagureEvent, + github, ) from packit_service.worker.events.comment import ( AbstractCommentEvent, @@ -221,7 +221,7 @@ def process(self) -> list[TaskResults]: # installation is handled differently b/c app is installed to GitHub account # not repository, so package config with jobs is missing - if isinstance(self.event, InstallationEvent): + if isinstance(self.event, github.installation.Installation): GithubAppInstallationHandler.get_signature( event=self.event, job=None, diff --git a/packit_service/worker/parser.py b/packit_service/worker/parser.py index 0c09ee872..14705cb5f 100644 --- a/packit_service/worker/parser.py +++ b/packit_service/worker/parser.py @@ -36,7 +36,6 @@ CheckRerunReleaseEvent, CoprBuildEndEvent, CoprBuildStartEvent, - InstallationEvent, IssueCommentEvent, IssueCommentGitlabEvent, KojiTaskEvent, @@ -56,6 +55,7 @@ TagPushGitlabEvent, TestingFarmResultsEvent, VMImageBuildResultEvent, + github, ) from packit_service.worker.events.comment import CommitCommentEvent from packit_service.worker.events.enums import ( @@ -98,7 +98,7 @@ def parse_event( ) -> Optional[ Union[ PullRequestGithubEvent, - InstallationEvent, + github.installation.Installation, ReleaseEvent, TestingFarmResultsEvent, PullRequestCommentGithubEvent, @@ -1125,7 +1125,7 @@ def parse_check_rerun_event( return event @staticmethod - def parse_installation_event(event) -> Optional[InstallationEvent]: + def parse_installation_event(event) -> Optional[github.installation.Installation]: """Look into the provided event and see if it is Github App installation details.""" # Check if installation key in JSON isn't enough, we have to check the account as well if not nested_get(event, "installation", "account"): @@ -1157,7 +1157,7 @@ def parse_installation_event(event) -> Optional[InstallationEvent]: sender_id = event["sender"]["id"] sender_login = event["sender"]["login"] - return InstallationEvent( + return github.installation.Installation( installation_id, account_login, account_id, diff --git a/tests/unit/events/test_github.py b/tests/unit/events/test_github.py index 9ba458a31..06255ab22 100644 --- a/tests/unit/events/test_github.py +++ b/tests/unit/events/test_github.py @@ -23,12 +23,12 @@ CheckRerunCommitEvent, CheckRerunPullRequestEvent, CheckRerunReleaseEvent, - InstallationEvent, IssueCommentEvent, PullRequestCommentGithubEvent, PullRequestGithubEvent, PushGitHubEvent, ReleaseEvent, + github, ) from packit_service.worker.events.comment import CommitCommentEvent from packit_service.worker.events.enums import ( @@ -105,7 +105,7 @@ def commit_comment(): def test_parse_installation(github_installation): event_object = Parser.parse_event(github_installation) - assert isinstance(event_object, InstallationEvent) + assert isinstance(event_object, github.installation.Installation) assert event_object.installation_id == 1708454 assert event_object.account_login == "packit-service" assert event_object.account_id == 46870917 diff --git a/tests_openshift/conftest.py b/tests_openshift/conftest.py index e417ab673..b32de1506 100644 --- a/tests_openshift/conftest.py +++ b/tests_openshift/conftest.py @@ -53,7 +53,7 @@ TFTTestRunTargetModel, sa_session_transaction, ) -from packit_service.worker.events import InstallationEvent +from packit_service.worker.events import github class SampleValues: @@ -1382,7 +1382,7 @@ def new_allowlist_entry(clean_before_and_after): @pytest.fixture() def installation_events(): return [ - InstallationEvent( + github.installation.Installation( installation_id=3767734, account_login="teg", account_id=5409, @@ -1393,7 +1393,7 @@ def installation_events(): sender_id=5409, sender_login="teg", ), - InstallationEvent( + github.installation.Installation( installation_id=6813698, account_login="Pac23", account_id=11048203,