Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Github url parse error for some scenarios #3683

Merged
merged 8 commits into from
Nov 6, 2023
3 changes: 2 additions & 1 deletion cumulusci/utils/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def parse_repo_url(url: str) -> Tuple[str, str, str]:
Returns (owner, name, host)
"""
url_parts = re.split("/|@|:", url.rstrip("/"))
url_parts = list(filter(None, url_parts))

name = url_parts[-1]
if name.endswith(".git"):
Expand All @@ -81,6 +82,6 @@ def parse_repo_url(url: str) -> Tuple[str, str, str]:

host = url_parts[-3]
# Need to consider "https://api.github.com/repos/owner/repo/" pattern
if "http" in url_parts[0] and len(url_parts) > 6:
if "http" in url_parts[0] and len(url_parts) > 4 and not host.endswith(".com"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgrandhi This may work if hostname ends with .com, but if the user having hostname ends with different name then this may fail. Can we use regex instead of hard coding the value here?

host = url_parts[-4]
return (owner, name, host)
7 changes: 7 additions & 0 deletions cumulusci/utils/tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ def test_construct_release_branch_name():
),
("https://github.com/owner/repo_name/", "owner", "repo_name", "github.com"),
("https://github.com/owner/repo_name.git", "owner", "repo_name", "github.com"),
(
"https://user@github.com/owner/repo_name.git",
"owner",
"repo_name",
"github.com",
),
(
"https://git.ent.example.com/org/private_repo.git",
"org",
"private_repo",
"git.ent.example.com",
),
("git@github.com:owner/repo_name.git", "owner", "repo_name", "github.com"),
("git@github.com:/owner/repo_name.git", "owner", "repo_name", "github.com"),
("git@github.com:owner/repo_name", "owner", "repo_name", "github.com"),
(
"git@api.github.com/owner/repo_name/",
Expand Down
Loading