From ad46d3458143447f3fc6174d243c9f8ff6df3454 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Jun 27 2024 17:51:33 +0000 Subject: 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 --- diff --git a/src/centpkg/utils.py b/src/centpkg/utils.py index a2be10d..4dbf4fa 100644 --- a/src/centpkg/utils.py +++ b/src/centpkg/utils.py @@ -197,9 +197,18 @@ def get_canonical_repo_name(config, repo_url): distgit_section = '{0}.distgit'.format(cli_name) 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_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: 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: # 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] # Chop off a trailing .git if any