From 04fa8a9a8641c1d84f0feba6b16e5d6a29215c75 Mon Sep 17 00:00:00 2001 From: Mads Oestergaard Date: Mon, 29 Jan 2024 14:39:22 +0100 Subject: [PATCH 1/2] Fix ssh to http conversion for azure devops repos --- clearml_agent/helper/repo.py | 11 +++++++++++ tests/package/ssh_conversion.py | 1 + 2 files changed, 12 insertions(+) diff --git a/clearml_agent/helper/repo.py b/clearml_agent/helper/repo.py index 8d1e427..403a60b 100644 --- a/clearml_agent/helper/repo.py +++ b/clearml_agent/helper/repo.py @@ -225,6 +225,7 @@ def remote_branch_name(branch): (?:(?P{regular}*?)@)? (?P{regular}*?) : + (?:v3/)? # present in azure ssh urls (?P{regular}.*)? $ """.format( @@ -253,6 +254,16 @@ def get_username(user_, password=None): match = cls.SSH_URL_GIT_SYNTAX.match(url) if match: user, host, path = match.groups() + + # handle special azure cases + if "ssh" and "azure" in host: + host = host.replace("ssh.", "") + + # azure http url is different than ssh url + # the format is https://dev.azure.com/{organization}/{project}/_git/{repo} + path_components = path.split("/") + path = "/".join(path_components[:-1]) + "/_git/" + path_components[-1] + return ( furl() .set(scheme="https", username=get_username(user), host=host, path=path) diff --git a/tests/package/ssh_conversion.py b/tests/package/ssh_conversion.py index 7f2084c..8aef238 100644 --- a/tests/package/ssh_conversion.py +++ b/tests/package/ssh_conversion.py @@ -16,6 +16,7 @@ ("ftp://example.com/a/b/", None), ("github.com:foo/bar.git", "https://github.com/foo/bar.git"), ("git@github.com:foo/bar.git", "https://github.com/foo/bar.git"), + ("git@ssh.dev.azure.com:v3/org/project/repo", "https://dev.azure.com/org/project/_git/repo"), ("bitbucket.org:foo/bar.git", "https://bitbucket.org/foo/bar.git"), ("hg@bitbucket.org:foo/bar.git", "https://bitbucket.org/foo/bar.git"), ("ssh://bitbucket.org/foo/bar.git", "https://bitbucket.org/foo/bar.git"), From f640eb67078283cb16e66c629c76375ab3e1fdee Mon Sep 17 00:00:00 2001 From: Mads Oestergaard Date: Fri, 2 Feb 2024 10:50:52 +0100 Subject: [PATCH 2/2] Move ssh filter into regex and use list.insert in path --- clearml_agent/helper/repo.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/clearml_agent/helper/repo.py b/clearml_agent/helper/repo.py index 403a60b..833951b 100644 --- a/clearml_agent/helper/repo.py +++ b/clearml_agent/helper/repo.py @@ -219,13 +219,15 @@ def remote_branch_name(branch): return branch # parse scp-like git ssh URLs, e.g: git@host:user/project.git + # or git@ssh.dev.azure.com:v3/org/project/repo SSH_URL_GIT_SYNTAX = re.compile( r""" ^ (?:(?P{regular}*?)@)? + (?:ssh\.)? (?P{regular}*?) : - (?:v3/)? # present in azure ssh urls + (?:v3/)? (?P{regular}.*)? $ """.format( @@ -255,14 +257,12 @@ def get_username(user_, password=None): if match: user, host, path = match.groups() - # handle special azure cases - if "ssh" and "azure" in host: - host = host.replace("ssh.", "") - - # azure http url is different than ssh url - # the format is https://dev.azure.com/{organization}/{project}/_git/{repo} + # 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 = "/".join(path_components[:-1]) + "/_git/" + path_components[-1] + path_components.insert(-1, "_git") + path = "/".join(path_components) return ( furl()