mirror of
https://git.centos.org/centos/centpkg.git
synced 2025-02-23 08:12:55 +00:00
Fix autodetection of repo name with SSH remote
There are two valid forms of SSH protocol git remotes, but we were only expecting the [git+]ssh:// form. The urllib.parse.urlparse() routine was thus failing to determine the scheme and was treating the entire URL as the path to pass to the Gitlab API. As a result, it was throwing a 404 exception that we were catching and ignoring. This patch checks for a missing scheme component and if it finds one, it transfers the remote into the other URL form for parsing purposes. Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
This commit is contained in:
parent
0debb6fbc1
commit
ad46d34581
1 changed files with 12 additions and 3 deletions
|
@ -197,9 +197,18 @@ def get_canonical_repo_name(config, repo_url):
|
||||||
distgit_section = '{0}.distgit'.format(cli_name)
|
distgit_section = '{0}.distgit'.format(cli_name)
|
||||||
distgit_api_base_url = config_get_safely(dist_git_config, distgit_section, "apibaseurl")
|
distgit_api_base_url = config_get_safely(dist_git_config, distgit_section, "apibaseurl")
|
||||||
|
|
||||||
# Make sure the fork comes from the same Gitlab instance
|
|
||||||
parsed_repo_url = urlparse(repo_url)
|
parsed_repo_url = urlparse(repo_url)
|
||||||
parsed_base_url = urlparse(distgit_api_base_url)
|
if not parsed_repo_url.scheme:
|
||||||
|
# Some git checkouts are in the form of git@gitlab.com/...
|
||||||
|
# If it's missing the scheme, it will treat the entire URL as the path
|
||||||
|
# so we'll fake up the scheme for this situation
|
||||||
|
# https://www.git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository
|
||||||
|
# implies that no scheme is equivalent to git+ssh://
|
||||||
|
# When making that conversion, we also have to replace the leading ':'
|
||||||
|
# with a slash.
|
||||||
|
faked_url = "git+ssh://{0}".format(repo_url.replace(":", "/", 1))
|
||||||
|
parsed_repo_url = urlparse(faked_url)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
distgit_token = config_get_safely(dist_git_config, distgit_section, 'token')
|
distgit_token = config_get_safely(dist_git_config, distgit_section, 'token')
|
||||||
|
@ -228,7 +237,7 @@ def get_canonical_repo_name(config, repo_url):
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# For any other exception, just fall back to using the last segment
|
# For any other exception, just fall back to using the last segment
|
||||||
# of the URL path.
|
# of the URL path and hope it's correct
|
||||||
canonical_repo_name = parsed_repo_url.path.split('/')[-1]
|
canonical_repo_name = parsed_repo_url.path.split('/')[-1]
|
||||||
|
|
||||||
# Chop off a trailing .git if any
|
# Chop off a trailing .git if any
|
||||||
|
|
Loading…
Add table
Reference in a new issue