Skip to content

Commit ff1c83e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ac2675f commit ff1c83e

File tree

5 files changed

+84
-38
lines changed

5 files changed

+84
-38
lines changed

coverage_comment/activity.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ class Activity(Enum):
1818
POST_COMMENT = "post_comment"
1919
SAVE_COVERAGE_DATA_FILES = "save_coverage_data_files"
2020

21+
2122
class ActivityNotFound(Exception):
2223
pass
2324

25+
2426
class ActivityConfigError(Exception):
2527
pass
2628

29+
2730
def find_activity_from_config(
2831
event_name: str,
2932
config: settings.Config,
@@ -36,11 +39,16 @@ def find_activity_from_config(
3639
if event_name in config.EVENTS_AS_COMMENT:
3740
activities.append(Activity.POST_COMMENT)
3841
if len(activities) > 1:
39-
raise ActivityConfigError(f"Event {event_name} is specified in multiple EVENTS_AS_* variables: {', '.join([activity.value for activity in activities])}")
42+
raise ActivityConfigError(
43+
f"Event {event_name} is specified in multiple EVENTS_AS_* variables: {', '.join([activity.value for activity in activities])}"
44+
)
4045
if len(activities) == 0:
41-
raise ActivityNotFound(f"Event {event_name} is not specified in any of the EVENTS_AS_* variables")
46+
raise ActivityNotFound(
47+
f"Event {event_name} is not specified in any of the EVENTS_AS_* variables"
48+
)
4249
return activities[0]
4350

51+
4452
def find_activity(
4553
event_name: str,
4654
is_default_branch: bool,

coverage_comment/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ def action(
8888
)
8989
except activity_module.ActivityNotFound:
9090
log.error(
91-
'This action\'s default behavior is to determine the appropriate '
92-
'mode based on the current branch, whether or not it\'s in a pull '
93-
'request, and if that pull request is open or closed. This '
94-
'frequently results in the correct action taking place, but is '
95-
'only a heuristic. If you need more precise control, you should '
91+
"This action's default behavior is to determine the appropriate "
92+
"mode based on the current branch, whether or not it's in a pull "
93+
"request, and if that pull request is open or closed. This "
94+
"frequently results in the correct action taking place, but is "
95+
"only a heuristic. If you need more precise control, you should "
9696
'specify the "EVENTS_AS_PR", "EVENTS_AS_COVERAGE", and '
9797
'"EVENTS_AS_COMMENT" parameters as described in the documentation.'
9898
)

coverage_comment/settings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ def FINAL_COVERAGE_DATA_BRANCH(self):
193193

194194
@property
195195
def event_activities_specified(self) -> bool:
196-
return bool(self.EVENTS_AS_COVERAGE) or bool(self.EVENTS_AS_PR) or bool(self.EVENTS_AS_COMMENT)
196+
return (
197+
bool(self.EVENTS_AS_COVERAGE)
198+
or bool(self.EVENTS_AS_PR)
199+
or bool(self.EVENTS_AS_COMMENT)
200+
)
197201

198202
# We need to type environ as a MutableMapping because that's what
199203
# os.environ is, and just saying `dict[str, str]` is not enough to make

tests/unit/test_activity.py

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
("workflow_run", True, None, False, activity.Activity.POST_COMMENT),
1313
("push", True, None, False, activity.Activity.SAVE_COVERAGE_DATA_FILES),
1414
("push", False, None, False, activity.Activity.PROCESS_PR),
15-
("pull_request", True, "closed", True, activity.Activity.SAVE_COVERAGE_DATA_FILES),
15+
(
16+
"pull_request",
17+
True,
18+
"closed",
19+
True,
20+
activity.Activity.SAVE_COVERAGE_DATA_FILES,
21+
),
1622
("pull_request", True, None, False, activity.Activity.PROCESS_PR),
1723
("pull_request", False, None, False, activity.Activity.PROCESS_PR),
1824
("schedule", False, None, False, activity.Activity.SAVE_COVERAGE_DATA_FILES),
@@ -50,58 +56,75 @@ def test_find_activity_pr_closed_not_merged():
5056
is_pr_merged=False,
5157
)
5258

59+
5360
BASE_ENV = {
54-
'GITHUB_BASE_REF': "",
55-
'GITHUB_TOKEN': "foo",
56-
'GITHUB_REPOSITORY': "owner/repo",
57-
'GITHUB_REF': "master",
58-
'GITHUB_EVENT_NAME': "pull_request",
59-
'GITHUB_PR_RUN_ID': 123,
60-
'GITHUB_STEP_SUMMARY': "step_summary",
61+
"GITHUB_BASE_REF": "",
62+
"GITHUB_TOKEN": "foo",
63+
"GITHUB_REPOSITORY": "owner/repo",
64+
"GITHUB_REF": "master",
65+
"GITHUB_EVENT_NAME": "pull_request",
66+
"GITHUB_PR_RUN_ID": 123,
67+
"GITHUB_STEP_SUMMARY": "step_summary",
6168
}
6269

70+
6371
def test_find_activity_from_config__as_pr():
64-
config = Config.from_environ(BASE_ENV | {
65-
"EVENTS_AS_PR": "pull_request",
66-
"EVENTS_AS_COMMENT": "workflow_dispatch,workflow_call",
67-
"EVENTS_AS_COVERAGE": "push,merge_queue",
68-
})
72+
config = Config.from_environ(
73+
BASE_ENV
74+
| {
75+
"EVENTS_AS_PR": "pull_request",
76+
"EVENTS_AS_COMMENT": "workflow_dispatch,workflow_call",
77+
"EVENTS_AS_COVERAGE": "push,merge_queue",
78+
}
79+
)
6980
result = activity.find_activity_from_config(
7081
event_name="pull_request",
7182
config=config,
7283
)
7384
assert result == activity.Activity.PROCESS_PR
7485

86+
7587
def test_find_activity_from_config__as_comment():
76-
config = Config.from_environ(BASE_ENV | {
77-
"EVENTS_AS_PR": "pull_request",
78-
"EVENTS_AS_COMMENT": "workflow_dispatch,workflow_call",
79-
"EVENTS_AS_COVERAGE": "push,merge_queue",
80-
})
88+
config = Config.from_environ(
89+
BASE_ENV
90+
| {
91+
"EVENTS_AS_PR": "pull_request",
92+
"EVENTS_AS_COMMENT": "workflow_dispatch,workflow_call",
93+
"EVENTS_AS_COVERAGE": "push,merge_queue",
94+
}
95+
)
8196
result = activity.find_activity_from_config(
8297
event_name="workflow_dispatch",
8398
config=config,
8499
)
85100
assert result == activity.Activity.POST_COMMENT
86101

102+
87103
def test_find_activity_from_config__as_coverage():
88-
config = Config.from_environ(BASE_ENV | {
89-
"EVENTS_AS_PR": "pull_request",
90-
"EVENTS_AS_COMMENT": "workflow_dispatch,workflow_call",
91-
"EVENTS_AS_COVERAGE": "push,merge_queue",
92-
})
104+
config = Config.from_environ(
105+
BASE_ENV
106+
| {
107+
"EVENTS_AS_PR": "pull_request",
108+
"EVENTS_AS_COMMENT": "workflow_dispatch,workflow_call",
109+
"EVENTS_AS_COVERAGE": "push,merge_queue",
110+
}
111+
)
93112
result = activity.find_activity_from_config(
94113
event_name="push",
95114
config=config,
96115
)
97116
assert result == activity.Activity.SAVE_COVERAGE_DATA_FILES
98117

118+
99119
def test_find_activity_from_config__multiple_activities():
100-
config = Config.from_environ(BASE_ENV | {
101-
"EVENTS_AS_PR": "pull_request",
102-
"EVENTS_AS_COMMENT": "workflow_dispatch,workflow_call",
103-
"EVENTS_AS_COVERAGE": "pull_request",
104-
})
120+
config = Config.from_environ(
121+
BASE_ENV
122+
| {
123+
"EVENTS_AS_PR": "pull_request",
124+
"EVENTS_AS_COMMENT": "workflow_dispatch,workflow_call",
125+
"EVENTS_AS_COVERAGE": "pull_request",
126+
}
127+
)
105128
with pytest.raises(activity.ActivityConfigError):
106129
activity.find_activity_from_config(
107130
event_name="pull_request",

tests/unit/test_settings.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_config__from_environ__missing():
2525
with pytest.raises(settings.MissingEnvironmentVariable):
2626
settings.Config.from_environ({})
2727

28+
2829
BASE_OK_ENV = {
2930
"GITHUB_BASE_REF": "master",
3031
"GITHUB_TOKEN": "foo",
@@ -50,6 +51,7 @@ def test_config__from_environ__missing():
5051
"FORCE_WORKFLOW_RUN": "false",
5152
}
5253

54+
5355
def test_config__from_environ__base_ok():
5456
config = settings.Config.from_environ(BASE_OK_ENV)
5557
assert config == settings.Config(
@@ -78,8 +80,13 @@ def test_config__from_environ__base_ok():
7880
)
7981
assert config.event_activities_specified is False
8082

83+
8184
def test_config__from_environ__with_single_events_ok():
82-
ENV = BASE_OK_ENV | {"EVENTS_AS_PR": "pull_request", "EVENTS_AS_COMMENT": "workflow_dispatch", "EVENTS_AS_COVERAGE": "push"}
85+
ENV = BASE_OK_ENV | {
86+
"EVENTS_AS_PR": "pull_request",
87+
"EVENTS_AS_COMMENT": "workflow_dispatch",
88+
"EVENTS_AS_COVERAGE": "push",
89+
}
8390
config = settings.Config.from_environ(ENV)
8491
assert config.EVENTS_AS_PR == ["pull_request"]
8592
assert config.EVENTS_AS_COMMENT == ["workflow_dispatch"]
@@ -88,7 +95,11 @@ def test_config__from_environ__with_single_events_ok():
8895

8996

9097
def test_config__from_environ__with_multiple_events_ok():
91-
ENV = BASE_OK_ENV | {"EVENTS_AS_PR": "pull_request,push", "EVENTS_AS_COMMENT": "workflow_dispatch,workflow_call", "EVENTS_AS_COVERAGE": "push,merge_queue"}
98+
ENV = BASE_OK_ENV | {
99+
"EVENTS_AS_PR": "pull_request,push",
100+
"EVENTS_AS_COMMENT": "workflow_dispatch,workflow_call",
101+
"EVENTS_AS_COVERAGE": "push,merge_queue",
102+
}
92103
config = settings.Config.from_environ(ENV)
93104
assert config.EVENTS_AS_PR == ["pull_request", "push"]
94105
assert config.EVENTS_AS_COMMENT == ["workflow_dispatch", "workflow_call"]

0 commit comments

Comments
 (0)