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 ssh to http conversion for azure devops repos #185

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions clearml_agent/helper/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,15 @@ def remote_branch_name(branch):
return branch

# parse scp-like git ssh URLs, e.g: git@host:user/project.git
# or [email protected]:v3/org/project/repo
SSH_URL_GIT_SYNTAX = re.compile(
r"""
^
(?:(?P<user>{regular}*?)@)?
(?:ssh\.)?
(?P<host>{regular}*?)
:
(?:v3/)?
(?P<path>{regular}.*)?
$
""".format(
Expand Down Expand Up @@ -253,6 +256,14 @@ def get_username(user_, password=None):
match = cls.SSH_URL_GIT_SYNTAX.match(url)
if match:
user, host, path = match.groups()

# handle the dev.azure format by inserting _git between project and repo
# as format is https://dev.azure.com/{organization}/{project}/_git/{repo}
if "azure" in host:
path_components = path.split("/")
path_components.insert(-1, "_git")
path = "/".join(path_components)

return (
furl()
.set(scheme="https", username=get_username(user), host=host, path=path)
Expand Down
1 change: 1 addition & 0 deletions tests/package/ssh_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
("ftp://example.com/a/b/", None),
("github.com:foo/bar.git", "https://github.com/foo/bar.git"),
("[email protected]:foo/bar.git", "https://github.com/foo/bar.git"),
("[email protected]:v3/org/project/repo", "https://dev.azure.com/org/project/_git/repo"),
("bitbucket.org:foo/bar.git", "https://bitbucket.org/foo/bar.git"),
("[email protected]:foo/bar.git", "https://bitbucket.org/foo/bar.git"),
("ssh://bitbucket.org/foo/bar.git", "https://bitbucket.org/foo/bar.git"),
Expand Down