diff --git a/release-pr/src/neon_release_pr/git.py b/release-pr/src/neon_release_pr/git.py index 97915cee..8d6c639f 100644 --- a/release-pr/src/neon_release_pr/git.py +++ b/release-pr/src/neon_release_pr/git.py @@ -175,7 +175,10 @@ def github_repo(origin_url: str | None) -> str | None: if origin_url is None: return None - match = re.search(r"github.com[:\d/]+?(?P[^/]+?/[^/]+?)(\.git)?$", origin_url) + match = re.search( + r"github[^:/\s]*\.com[^:/\s]*(?::\d+)?[:\/](?P[^/]+?/[^/]+?)(\.git)?$", + origin_url, + ) assert match, ( "There should be exactly one repo owner/name match in the url for remote origin" diff --git a/release-pr/tests/test_origin_url_regex.py b/release-pr/tests/test_origin_url_regex.py index f4691b99..ff702ff8 100644 --- a/release-pr/tests/test_origin_url_regex.py +++ b/release-pr/tests/test_origin_url_regex.py @@ -2,10 +2,23 @@ def test_round_trip_parse_then_generate(): - for url in [ - "https://github.com/databricks-eng/hadron.git", - "git@github.com:neondatabase/neon.git", - "ssh://git@github.com:22/neondatabase/neon.git", - "https://github.com/databricks-eng/hadron", - ]: - assert git.github_repo(url) is not None, f"No match for url {url}" + test_cases = [ + ("https://github.com/databricks-eng/hadron.git", "databricks-eng/hadron"), + ("git@github.com:neondatabase/neon.git", "neondatabase/neon"), + ("ssh://git@github.com:22/neondatabase/neon.git", "neondatabase/neon"), + ("https://github.com/databricks-eng/hadron", "databricks-eng/hadron"), + ( + "git@github-neon.com:neondatabase/dev-actions.git", + "neondatabase/dev-actions", + ), + ("git@github.com-emu:databricks-eng/hadron.git", "databricks-eng/hadron"), + ( + "ssh://git@github-neon.com:22/neondatabase/dev-actions.git", + "neondatabase/dev-actions", + ), + ("git@github.com-emu:databricks-eng/hadron.git", "databricks-eng/hadron"), + ] + for url, expected_repo in test_cases: + assert git.github_repo(url) == expected_repo, ( + f"Expected {expected_repo} for url {url}" + )