Skip to content

Commit fdeca0d

Browse files
authored
Fix getting GitHub owner for remote origin with https:// (#141)
1 parent 2ab9240 commit fdeca0d

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ exclude = [
1414
"^run_release.py$",
1515
"^sbom.py$",
1616
"^tests/test_release_tag.py$",
17+
"^tests/test_run_release.py$",
1718
"^tests/test_sbom.py$",
1819
"^windows-release/purge.py$",
1920
]

run_release.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,17 @@ def execute_command(command: str) -> None:
738738
execute_command(f"find {destination} -type f -exec chmod 664 {{}} \\;")
739739

740740

741+
def extract_github_owner(url: str) -> str:
742+
if https_match := re.match(r"(https://)?github\.com/([^/]+)/", url):
743+
return https_match.group(2)
744+
elif ssh_match := re.match(r"^git@github\.com:([^/]+)/", url):
745+
return ssh_match.group(1)
746+
else:
747+
raise ReleaseException(
748+
f"Could not parse GitHub owner from 'origin' remote URL: {url}"
749+
)
750+
751+
741752
def start_build_of_source_and_docs(db: DbfilenameShelf) -> None:
742753
# Get the git commit SHA for the tag
743754
commit_sha = (
@@ -757,14 +768,7 @@ def start_build_of_source_and_docs(db: DbfilenameShelf) -> None:
757768
.decode()
758769
.strip()
759770
)
760-
if https_match := re.match(r"github\.com/([^/]+)/", origin_remote_url):
761-
origin_remote_github_owner = https_match.group(1)
762-
elif ssh_match := re.match(r"^git@github\.com:([^/]+)/", origin_remote_url):
763-
origin_remote_github_owner = ssh_match.group(1)
764-
else:
765-
raise ReleaseException(
766-
f"Could not parse GitHub owner from 'origin' remote URL: {origin_remote_url}"
767-
)
771+
origin_remote_github_owner = extract_github_owner(origin_remote_url)
768772
# We ask for human verification at this point since this commit SHA is 'locked in'
769773
print()
770774
print(

tests/test_run_release.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
3+
import run_release
4+
5+
6+
@pytest.mark.parametrize(
7+
["url", "expected"],
8+
[
9+
("github.com/hugovk/cpython.git", "hugovk"),
10+
("[email protected]:hugovk/cpython.git", "hugovk"),
11+
("https://github.com/hugovk/cpython.git", "hugovk"),
12+
],
13+
)
14+
def test_extract_github_owner(url: str, expected: str) -> None:
15+
assert run_release.extract_github_owner(url) == expected
16+
17+
18+
def test_invalid_extract_github_owner() -> None:
19+
with pytest.raises(
20+
run_release.ReleaseException,
21+
match="Could not parse GitHub owner from 'origin' remote URL: "
22+
"https://example.com",
23+
):
24+
run_release.extract_github_owner("https://example.com")

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ env_list =
99
skip_install = true
1010
deps =
1111
-r dev-requirements.txt
12+
-r requirements.txt
1213
commands =
1314
{envpython} -m pytest \
1415
tests/ \

0 commit comments

Comments
 (0)