From 8c605fd2ee1cb66f0e5e0455f52c49812e3b2b16 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Jul 10 2024 12:51:08 +0000 Subject: [PATCH 1/2] get_canonical_repo_name: Better handle HTTP errors Signed-off-by: Stephen Gallagher --- diff --git a/src/centpkg/utils.py b/src/centpkg/utils.py index 3fa35ea..9806613 100644 --- a/src/centpkg/utils.py +++ b/src/centpkg/utils.py @@ -18,8 +18,9 @@ import re import requests import sys from datetime import date, datetime +from http import HTTPStatus from pyrpkg import rpkgError -from requests.exceptions import ConnectionError +from requests.exceptions import ConnectionError, HTTPError from configparser import NoOptionError, NoSectionError from urllib.parse import quote_plus, urlparse @@ -229,6 +230,15 @@ def get_canonical_repo_name(config, repo_url): rv_json = rv.json() canonical_repo_name = rv_json['forked_from_project']['name'] + + except HTTPError as e: + # We got a 4xx or 5xx error code from the URL lookup + if e.response.status_code == HTTPStatus.FORBIDDEN: + raise rpkgError("Insufficient Gitlab API permissions. Missing token?") + + # Other errors are unexpected, so re-raise them + raise + except KeyError as e: # There was no 'forked_from_project' key, likely meaning the # user lacked permissions to read the API. Usually this means From edbd72d5306c6bd072c4e0fccd72976ccd2b805e Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Jul 10 2024 13:48:45 +0000 Subject: [PATCH 2/2] Only add git+ssh:// for git@ repo paths Fixes an issue introduced by ad46d3458143447f3fc6174d243c9f8ff6df3454 Apparently, under some circumstances, rpkg will store the "repo name" as only the path field when using HTTPS remotes. As a result, we were incorrectly treating those paths as an SSH URI since they had no scheme when parsed by urllib.parse.urlparse(). This resulted in the first part of the path being treated as the "netloc" and being trimmed out. This naturally meant that the lookup against Gitlab for the fork parent would fail. This patch adds a check to ensure that the git+ssh:// scheme is only added if the repo_url starts with "git@". Signed-off-by: Stephen Gallagher --- diff --git a/src/centpkg/utils.py b/src/centpkg/utils.py index 9806613..4a420f9 100644 --- a/src/centpkg/utils.py +++ b/src/centpkg/utils.py @@ -199,7 +199,7 @@ def get_canonical_repo_name(config, repo_url): distgit_api_base_url = config_get_safely(dist_git_config, distgit_section, "apibaseurl") parsed_repo_url = urlparse(repo_url) - if not parsed_repo_url.scheme: + if not parsed_repo_url.scheme and repo_url.startswith("git@"): # 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