Skip to content

Commit 3a75dee

Browse files
committed
Update regex pattern for remote URLs
1 parent 16df442 commit 3a75dee

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/labels/utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import re
23
import shlex
34
import subprocess
@@ -8,7 +9,7 @@
89

910

1011
REMOTE_REGEX = re.compile(
11-
r"^(https|git)(:\/\/|@)github\.com[\/:](?P<owner>[^\/:]+)\/(?P<name>.+).git$"
12+
r"^(https|git)(:\/\/|@)github\.com[\/:](?P<owner>[^\/:]+)\/(?P<name>.*?)(\.git)?$"
1213
)
1314

1415

@@ -18,6 +19,8 @@ def load_repository_info(remote_name: str = "origin") -> typing.Optional[Reposit
1819
HTTPS url format -> 'https://github.com/owner/name.git'
1920
SSH url format -> '[email protected]:owner/name.git'
2021
"""
22+
logger = logging.getLogger("labels")
23+
logger.debug(f"Load repository information for '{remote_name}'.")
2124

2225
proc = subprocess.run(
2326
shlex.split(f"git remote get-url {remote_name}"),
@@ -26,11 +29,14 @@ def load_repository_info(remote_name: str = "origin") -> typing.Optional[Reposit
2629
)
2730

2831
if proc.returncode != 0:
32+
logger.debug(f"Error running git remote get-url.")
2933
return None
3034

31-
match = REMOTE_REGEX.match(proc.stdout.strip())
35+
remote_url = proc.stdout.strip()
36+
match = REMOTE_REGEX.match(remote_url)
3237

3338
if match is None:
39+
logger.debug(f"No match for remote URL: {remote_url}.")
3440
return None
3541

3642
return Repository(owner=match.group("owner"), name=match.group("name"))

tests/test_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
[
99
"[email protected]:pytest-dev/pytest.git\n",
1010
"https://github.com/pytest-dev/pytest.git\n",
11+
"[email protected]/pytest-dev/pytest\n",
12+
"https://github.com/pytest-dev/pytest\n",
1113
],
12-
ids=["ssh", "https"],
14+
ids=["ssh", "https", "ssh_no_git", "https_no_git"],
1315
)
1416
def test_load_repository_info(mock_repo_info):
1517
"""Test that load_repository_info() works for both SSH and HTTPS URLs."""

0 commit comments

Comments
 (0)