-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathactivity.py
More file actions
57 lines (41 loc) · 1.51 KB
/
activity.py
File metadata and controls
57 lines (41 loc) · 1.51 KB
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
"""
This module is responsible for identifying what the action should be doing
based on the github event type and repository.
The code in main should be as straightforward as possible, we're offloading
the branching logic to this module.
"""
from __future__ import annotations
from enum import Enum
class Activity(Enum):
PROCESS_PR = "process_pr"
POST_COMMENT = "post_comment"
SAVE_COVERAGE_DATA_FILES = "save_coverage_data_files"
class ActivityNotFound(Exception):
pass
class ActivityConfigError(Exception):
pass
def validate_activity(activity: str) -> Activity:
if activity not in [a.value for a in Activity]:
raise ActivityConfigError(f"Invalid activity: {activity}")
return Activity(activity)
def find_activity(
event_name: str,
is_default_branch: bool,
event_type: str | None,
is_pr_merged: bool,
) -> Activity:
"""Find the activity to perform based on the event type and payload."""
if event_name == "workflow_run":
return Activity.POST_COMMENT
if (
(event_name == "push" and is_default_branch)
or event_name == "schedule"
or (event_name == "pull_request" and event_type == "closed")
or event_name == "merge_group"
):
if event_name == "pull_request" and event_type == "closed" and not is_pr_merged:
raise ActivityNotFound
return Activity.SAVE_COVERAGE_DATA_FILES
if event_name not in {"pull_request", "push", "merge_group"}:
raise ActivityNotFound
return Activity.PROCESS_PR