Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix event argument for handlers #510

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 17 additions & 16 deletions packit_service/worker/handlers/github_handlers.py
Expand Up @@ -81,19 +81,20 @@ class AbstractGithubJobHandler(JobHandler, GithubPackageConfigGetter):
class PullRequestGithubCheckDownstreamHandler(AbstractGithubJobHandler):
type = JobType.check_downstream
triggers = [TheJobTriggerType.pull_request]
event: PullRequestEvent

# https://developer.github.com/v3/activity/events/types/#events-api-payload-28

def __init__(
self, config: ServiceConfig, job_config: JobConfig, pr_event: PullRequestEvent
self, config: ServiceConfig, job_config: JobConfig, event: PullRequestEvent
):
super().__init__(config=config, job_config=job_config, event=pr_event)
self.pr_event = pr_event
self.project: GitProject = pr_event.get_project()
super().__init__(config=config, job_config=job_config, event=event)
self.event = event
self.project: GitProject = event.get_project()
self.package_config: PackageConfig = self.get_package_config_from_repo(
self.project, pr_event.base_ref, pr_event.pr_id
self.project, event.base_ref, event.pr_id
)
self.package_config.upstream_project_url = pr_event.project_url
self.package_config.upstream_project_url = event.project_url

def run(self) -> HandlerResults:
self.local_project = LocalProject(
Expand All @@ -103,7 +104,7 @@ def run(self) -> HandlerResults:
self.api = PackitAPI(self.config, self.package_config, self.local_project)

self.api.sync_pr(
pr_id=self.pr_event.pr_id,
pr_id=self.event.pr_id,
dist_git_branch=self.job_config.metadata.get("dist-git-branch", "master"),
# TODO: figure out top upstream commit for source-git here
)
Expand All @@ -113,18 +114,19 @@ def run(self) -> HandlerResults:
class GithubAppInstallationHandler(AbstractGithubJobHandler):
type = JobType.add_to_whitelist
triggers = [TheJobTriggerType.installation]
event: InstallationEvent

# https://developer.github.com/v3/activity/events/types/#events-api-payload-28

def __init__(
self,
config: ServiceConfig,
job_config: Optional[JobConfig],
installation_event: Union[InstallationEvent, Any],
event: Union[InstallationEvent, Any],
):
super().__init__(config=config, job_config=job_config, event=installation_event)
super().__init__(config=config, job_config=job_config, event=event)

self.installation_event = installation_event
self.event = event
self.project = self.config.get_project(
url="https://github.com/packit-service/notifications"
)
Expand All @@ -138,21 +140,20 @@ def run(self) -> HandlerResults:
"""

Installation.create(
installation_id=self.installation_event.installation_id,
event=self.installation_event,
installation_id=self.event.installation_id, event=self.event,
)
# try to add user to whitelist
whitelist = Whitelist(
fas_user=self.config.fas_user, fas_password=self.config.fas_password,
)
account_login = self.installation_event.account_login
account_type = self.installation_event.account_type
if not whitelist.add_account(self.installation_event):
account_login = self.event.account_login
account_type = self.event.account_type
if not whitelist.add_account(self.event):
# Create an issue in our repository, so we are notified when someone install the app
self.project.create_issue(
title=f"{account_type} {account_login} needs to be approved.",
body=(
f"Hi @{self.installation_event.sender_login}, we need to approve you in "
f"Hi @{self.event.sender_login}, we need to approve you in "
"order to start using Packit-as-a-Service. Someone from our team will "
"get back to you shortly.\n\n"
"For more info, please check out the documentation: "
Expand Down
8 changes: 4 additions & 4 deletions packit_service/worker/handlers/testing_farm_handlers.py
Expand Up @@ -58,17 +58,17 @@ def __init__(
self,
config: ServiceConfig,
job_config: Optional[JobConfig],
test_results_event: TestingFarmResultsEvent,
event: TestingFarmResultsEvent,
):
super().__init__(config=config, job_config=job_config, event=test_results_event)
self.project: GitProject = test_results_event.get_project()
super().__init__(config=config, job_config=job_config, event=event)
self.project: GitProject = event.get_project()
self.package_config = self.get_package_config_from_repo(
project=self.project, reference=self.event.git_ref
)
if not self.package_config:
raise ValueError(f"No config file found in {self.project.full_repo_name}")

self.package_config.upstream_project_url = test_results_event.project_url
self.package_config.upstream_project_url = event.project_url

def get_package_config_from_repo(
self,
Expand Down
2 changes: 1 addition & 1 deletion packit_service/worker/jobs.py
Expand Up @@ -308,7 +308,7 @@ def process_message(self, event: dict, topic: str = None) -> Optional[dict]:
# not repository, so package config with jobs is missing
if event_object.trigger == TheJobTriggerType.installation:
handler = GithubAppInstallationHandler(
self.config, job_config=None, installation_event=event_object
self.config, job_config=None, event=event_object
)
job_type = JobType.add_to_whitelist.value
jobs_results[job_type] = handler.run_n_clean()
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_testing_farm.py
Expand Up @@ -171,7 +171,7 @@ def test_testing_farm_response(
test_farm_handler = TestingFarmResultsHandler(
config=flexmock(command_handler_work_dir=flexmock()),
job_config=flexmock(),
test_results_event=TestingFarmResultsEvent(
event=TestingFarmResultsEvent(
pipeline_id="id",
result=tests_result,
environment=flexmock(),
Expand Down