Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion release-pr/src/neon_release_pr/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<repo>[^/]+?/[^/]+?)(\.git)?$", origin_url)
match = re.search(
r"github[^:/\s]*\.com[^:/\s]*(?::\d+)?[:\/](?P<repo>[^/]+?/[^/]+?)(\.git)?$",
origin_url,
)

assert match, (
"There should be exactly one repo owner/name match in the url for remote origin"
Expand Down
27 changes: 20 additions & 7 deletions release-pr/tests/test_origin_url_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)