From ad46d3458143447f3fc6174d243c9f8ff6df3454 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Jun 27 2024 17:51:33 +0000 Subject: [PATCH 1/2] 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 From 54ee6b4db2d21e235154474e5cb24390a70eaad1 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Jun 27 2024 18:28:35 +0000 Subject: [PATCH 2/2] Remove overzealous Catch block We've identified most of the ways that this can fail and accounted for them, so let's stop catching all errors and let them fail the execution and get reported if they come up. Signed-off-by: Stephen Gallagher --- diff --git a/src/centpkg/utils.py b/src/centpkg/utils.py index 4dbf4fa..3fa35ea 100644 --- a/src/centpkg/utils.py +++ b/src/centpkg/utils.py @@ -235,11 +235,6 @@ def get_canonical_repo_name(config, repo_url): # they haven't supplied a token or it is expired. raise rpkgError("Insufficient Gitlab API permissions. Missing token?") - except Exception as e: - # For any other exception, just fall back to using the last segment - # 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 return canonical_repo_name.rsplit('.git', 1)[0]