-
Notifications
You must be signed in to change notification settings - Fork 48
/
koji.py
68 lines (59 loc) · 2.36 KB
/
koji.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT
import logging
from packit_service.worker.checker.abstract import Checker
from packit_service.worker.events.enums import GitlabEventAction
from packit_service.worker.events import (
MergeRequestGitlabEvent,
PullRequestGithubEvent,
PushGitHubEvent,
PushGitlabEvent,
PushPagureEvent,
)
from packit_service.constants import (
KOJI_PRODUCTION_BUILDS_ISSUE,
PERMISSIONS_ERROR_WRITE_OR_ADMIN,
)
from packit_service.worker.reporting import BaseCommitStatus
from packit_service.worker.handlers.mixin import GetKojiBuildJobHelperMixin
logger = logging.getLogger(__name__)
class PermissionOnKoji(Checker, GetKojiBuildJobHelperMixin):
def pre_check(self) -> bool:
if (
self.data.event_type == MergeRequestGitlabEvent.__name__
and self.data.event_dict["action"] == GitlabEventAction.closed.value
):
# Not interested in closed merge requests
return False
if self.data.event_type in (
PushGitHubEvent.__name__,
PushGitlabEvent.__name__,
PushPagureEvent.__name__,
):
configured_branch = self.koji_build_helper.job_build_branch
if self.data.git_ref != configured_branch:
logger.info(
f"Skipping build on '{self.data.git_ref}'. "
f"Push configured only for '{configured_branch}'."
)
return False
if self.data.event_type in (
PullRequestGithubEvent.__name__,
MergeRequestGitlabEvent.__name__,
):
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):
self.koji_build_helper.report_status_to_all(
description=PERMISSIONS_ERROR_WRITE_OR_ADMIN,
state=BaseCommitStatus.neutral,
)
return False
if not self.koji_build_helper.is_scratch:
msg = "Non-scratch builds not possible from upstream."
self.koji_build_helper.report_status_to_all(
description=msg,
state=BaseCommitStatus.neutral,
url=KOJI_PRODUCTION_BUILDS_ISSUE,
)
return False
return True