#103 Only add git+ssh:// for git@ repo paths
Merged 4 months ago by tdawson. Opened 4 months ago by sgallagh.
centos/ sgallagh/centpkg fork_urls  into  develop

file modified
+12 -2
@@ -18,8 +18,9 @@ 

  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

  
@@ -198,7 +199,7 @@ 

      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
@@ -229,6 +230,15 @@ 

          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

Patch 1

get_canonical_repo_name: Better handle HTTP errors

Checks if the HTTP error is a 403 and prints a reminder about the Gitlab token.

Signed-off-by: Stephen Gallagher sgallagh@redhat.com

Patch 2

Only add git+ssh:// for git@ repo paths

Fixes an issue introduced by ad46d34

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 sgallagh@redhat.com

LGTM
Thank you for finding and fixing this.

Pull-Request has been merged by tdawson

4 months ago
Metadata