Skip to content

Commit 4f95ed0

Browse files
daniel-anyaewjoachim
authored andcommitted
Small fixes to dev-env script
1 parent 9735132 commit 4f95ed0

File tree

7 files changed

+70
-23
lines changed

7 files changed

+70
-23
lines changed

coverage_comment/activity.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@ def find_activity(
2222
if event_name == "workflow_run":
2323
return "post_comment"
2424

25-
if (event_name == "push" and is_default_branch) or (event_name == "pull_request" and event_action == "merged" and is_default_branch) or event_name == "schedule":
25+
if (
26+
(event_name == "push" and is_default_branch)
27+
or (
28+
event_name == "pull_request"
29+
and event_action == "merged"
30+
and is_default_branch
31+
)
32+
or event_name == "schedule"
33+
):
2634
return "save_coverage_data_files"
2735

2836
if event_name not in {"pull_request", "push"}:

coverage_comment/github.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def get_repository_info(
4646
default_branch=response.default_branch, visibility=response.visibility
4747
)
4848

49+
4950
def extract_github_host(api_url: str) -> str:
5051
"""
5152
Extracts the base GitHub web host URL from a GitHub API URL.
@@ -61,15 +62,15 @@ def extract_github_host(api_url: str) -> str:
6162
try:
6263
parsed_url = urlparse(api_url)
6364
scheme = parsed_url.scheme
64-
netloc = parsed_url.netloc # This includes the domain and potentially the port
65+
netloc = parsed_url.netloc # This includes the domain and potentially the port
6566

6667
# Special case for GitHub.com API
67-
if netloc == 'api.github.com':
68-
host_domain = 'github.com'
68+
if netloc == "api.github.com":
69+
host_domain = "github.com"
6970
# Special case for GitHub.com with port (less common but good practice)
70-
elif netloc.startswith('api.github.com:'):
71+
elif netloc.startswith("api.github.com:"):
7172
# Remove 'api.' prefix but keep the port
72-
host_domain = netloc.replace('api.', '', 1)
73+
host_domain = netloc.replace("api.", "", 1)
7374
# General case for GitHub Enterprise (netloc is already the host:port)
7475
else:
7576
host_domain = netloc
@@ -82,6 +83,7 @@ def extract_github_host(api_url: str) -> str:
8283
log.error(f"Error parsing URL {api_url}: {e}")
8384
return ""
8485

86+
8587
def download_artifact(
8688
github: github_client.GitHub,
8789
repository: str,

coverage_comment/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from __future__ import annotations
22

33
import functools
4+
import json
45
import logging
56
import os
67
import sys
7-
import json
88

99
import httpx
1010

@@ -74,7 +74,7 @@ def action(
7474
event_action = None
7575

7676
if event_path and os.path.exists(event_path):
77-
with open(event_path, "r") as event_file:
77+
with open(event_path) as event_file:
7878
event_payload = json.load(event_file)
7979
is_merged_pr_action = event_payload.get("pull_request", {}).get("merged", False)
8080
if is_merged_pr_action:

coverage_comment/storage.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ def get_raw_file_url(
155155
# seconds.
156156

157157

158-
def get_repo_file_url(github_host: str, repository: str, branch: str, path: str = "/") -> str:
158+
def get_repo_file_url(
159+
github_host: str, repository: str, branch: str, path: str = "/"
160+
) -> str:
159161
"""
160162
Computes the GitHub Web UI URL for a given path:
161163
If the path is empty or ends with a slash, it will be interpreted as a folder,
@@ -177,4 +179,3 @@ def get_html_report_url(github_host: str, repository: str, branch: str) -> str:
177179
if github_host.endswith("github.com"):
178180
return f"https://htmlpreview.github.io/?{readme_url}"
179181
return readme_url
180-

dev-env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function create-repo(){
4747
repo_dirname=$(basename ${GITHUB_REPOSITORY})
4848
mv "${repo_dirname}/"{*,.*} .
4949
rmdir "${repo_dirname}"
50-
git pull --ff-only origin master
50+
git pull --ff-only origin main
5151
}
5252

5353
function delete-repo(){
@@ -142,7 +142,7 @@ function help(){
142142
echo " coverage_comment" >&2
143143
echo " Launch the action locally (no argument)" >&2
144144
echo " pytest" >&2
145-
echo " Launch the the tests on the example repo (generates the coverage data that the action uses)" >&2
145+
echo " Launch the tests on the example repo (generates the coverage data that the action uses)" >&2
146146
echo "" >&2
147147

148148
echo "Change configuration:" >&2

tests/unit/test_activity.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
)
2020
def test_find_activity(event_name, event_action, is_default_branch, expected_activity):
2121
result = activity.find_activity(
22-
event_name=event_name, event_action=event_action, is_default_branch=is_default_branch
22+
event_name=event_name,
23+
event_action=event_action,
24+
is_default_branch=is_default_branch,
2325
)
2426
assert result == expected_activity
2527

tests/unit/test_storage.py

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,16 @@ def test_get_datafile_contents(gh, session):
157157
"github_host, is_public, expected",
158158
[
159159
("https://github.com", False, "https://github.com/foo/bar/raw/baz/qux"),
160-
("https://github.com", True, "https://raw.githubusercontent.com/foo/bar/baz/qux"),
161-
("https://github.mycompany.com", True, "https://github.mycompany.com/foo/bar/raw/baz/qux"),
160+
(
161+
"https://github.com",
162+
True,
163+
"https://raw.githubusercontent.com/foo/bar/baz/qux",
164+
),
165+
(
166+
"https://github.mycompany.com",
167+
True,
168+
"https://github.mycompany.com/foo/bar/raw/baz/qux",
169+
),
162170
],
163171
)
164172
def test_get_raw_file_url(github_host, is_public, expected):
@@ -177,17 +185,32 @@ def test_get_raw_file_url(github_host, is_public, expected):
177185
[
178186
("https://github.com", "", "https://github.com/foo/bar/tree/baz"),
179187
("https://github.com", "/", "https://github.com/foo/bar/tree/baz"),
180-
("https://github.com", "qux", "https://github.com/foo/bar/blob/baz/qux"), # blob
188+
(
189+
"https://github.com",
190+
"qux",
191+
"https://github.com/foo/bar/blob/baz/qux",
192+
), # blob
181193
("https://github.com", "qux/", "https://github.com/foo/bar/tree/baz/qux"),
182-
("https://github.mycompany.com", "/qux", "https://github.mycompany.com/foo/bar/blob/baz/qux"), # blob
183-
("https://github.mycompany.com", "/qux/", "https://github.mycompany.com/foo/bar/tree/baz/qux"),
194+
(
195+
"https://github.mycompany.com",
196+
"/qux",
197+
"https://github.mycompany.com/foo/bar/blob/baz/qux",
198+
), # blob
199+
(
200+
"https://github.mycompany.com",
201+
"/qux/",
202+
"https://github.mycompany.com/foo/bar/tree/baz/qux",
203+
),
184204
],
185205
)
186206
def test_get_repo_file_url(github_host, path, expected):
187-
result = storage.get_repo_file_url(github_host=github_host, repository="foo/bar", branch="baz", path=path)
207+
result = storage.get_repo_file_url(
208+
github_host=github_host, repository="foo/bar", branch="baz", path=path
209+
)
188210

189211
assert result == expected
190212

213+
191214
@pytest.mark.parametrize(
192215
"github_host",
193216
[
@@ -196,17 +219,28 @@ def test_get_repo_file_url(github_host, path, expected):
196219
],
197220
)
198221
def test_get_repo_file_url__no_path(github_host):
199-
result = storage.get_repo_file_url(github_host=github_host, repository="foo/bar", branch="baz")
222+
result = storage.get_repo_file_url(
223+
github_host=github_host, repository="foo/bar", branch="baz"
224+
)
200225

201226
assert result == f"{github_host}/foo/bar/tree/baz"
202227

228+
203229
@pytest.mark.parametrize(
204230
"github_host, expected",
205231
[
206-
("https://github.com", "https://htmlpreview.github.io/?https://github.com/foo/bar/blob/baz/htmlcov/index.html"),
207-
("https://github.mycompany.com", "https://github.mycompany.com/foo/bar/blob/baz/htmlcov/index.html"),
232+
(
233+
"https://github.com",
234+
"https://htmlpreview.github.io/?https://github.com/foo/bar/blob/baz/htmlcov/index.html",
235+
),
236+
(
237+
"https://github.mycompany.com",
238+
"https://github.mycompany.com/foo/bar/blob/baz/htmlcov/index.html",
239+
),
208240
],
209241
)
210242
def test_get_html_report_url(github_host, expected):
211-
result = storage.get_html_report_url(github_host=github_host, repository="foo/bar", branch="baz")
243+
result = storage.get_html_report_url(
244+
github_host=github_host, repository="foo/bar", branch="baz"
245+
)
212246
assert result == expected

0 commit comments

Comments
 (0)