-
Notifications
You must be signed in to change notification settings - Fork 48
/
testing_farm.py
89 lines (76 loc) · 3.25 KB
/
testing_farm.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT
import logging
from packit_service.constants import (
INTERNAL_TF_BUILDS_AND_TESTS_NOT_ALLOWED,
INTERNAL_TF_TESTS_NOT_ALLOWED,
)
from packit_service.worker.checker.abstract import ActorChecker, Checker
from packit_service.worker.events.gitlab import MergeRequestGitlabEvent
from packit_service.worker.events.enums import GitlabEventAction
from packit_service.worker.handlers.mixin import (
GetTestingFarmJobHelperMixin,
GetCoprBuildMixin,
GetGithubCommentEventMixin,
)
from packit_service.worker.reporting import BaseCommitStatus
logger = logging.getLogger(__name__)
class IsEventOk(
Checker, GetTestingFarmJobHelperMixin, GetCoprBuildMixin, GetGithubCommentEventMixin
):
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.testing_farm_job_helper.is_test_comment_pr_argument_present():
return self.testing_farm_job_helper.check_comment_pr_argument_and_report()
return not (
self.testing_farm_job_helper.skip_build
and self.testing_farm_job_helper.is_copr_build_comment_event()
)
class IsEventForJob(Checker):
def pre_check(self) -> bool:
if self.data.identifier != self.job_config.identifier:
logger.debug(
f"Skipping reporting, identifiers don't match "
f"(identifier of the test job to report: {self.data.identifier}, "
f"identifier from job config: {self.job_config.identifier})."
)
return False
return True
class CanActorRunJob(ActorChecker, GetTestingFarmJobHelperMixin):
"""For external contributors, we need to be more careful when running jobs.
This is a handler-specific permission check
for a user who trigger the action on a PR.
The job is not allowed for external contributors when using internal TF.
"""
def _pre_check(self) -> bool:
any_internal_test_job_build_required = (
any(
test_job.use_internal_tf and not test_job.skip_build
for test_job in self.testing_farm_job_helper.job_tests_all
)
and self.testing_farm_job_helper.build_required()
)
if (
(self.job_config.use_internal_tf or any_internal_test_job_build_required)
and not self.project.can_merge_pr(self.actor)
and self.actor not in self.service_config.admins
):
message = (
INTERNAL_TF_BUILDS_AND_TESTS_NOT_ALLOWED
if self.testing_farm_job_helper.job_build
else INTERNAL_TF_TESTS_NOT_ALLOWED
)
self.testing_farm_job_helper.report_status_to_tests(
description=message[0].format(actor=self.actor),
state=BaseCommitStatus.neutral,
markdown_content=message[1].format(
packit_comment_command_prefix=self.service_config.comment_command_prefix
),
)
return False
return True