Skip to content
Snippets Groups Projects
Commit 98fe7fe8 authored by vlorentz's avatar vlorentz
Browse files

Fix _sanitize_github_url removing suffixes too greedily

.rstrip() is not .removesuffix()
parent 6a5ad761
No related branches found
Tags v2.16.1
No related merge requests found
......@@ -16,6 +16,7 @@ from swh.core.github.utils import (
)
KNOWN_GH_REPO = "https://github.com/user/repo"
KNOWN_GH_REPO2 = "https://github.com/user/reposit"
@pytest.mark.parametrize(
......@@ -26,6 +27,11 @@ KNOWN_GH_REPO = "https://github.com/user/repo"
("user/repo/", KNOWN_GH_REPO),
("user/repo", KNOWN_GH_REPO),
("user/repo/.git", KNOWN_GH_REPO),
("user/reposit.git", KNOWN_GH_REPO2),
("user/reposit.git/", KNOWN_GH_REPO2),
("user/reposit/", KNOWN_GH_REPO2),
("user/reposit", KNOWN_GH_REPO2),
("user/reposit/.git", KNOWN_GH_REPO2),
("unknown/page", None), # unknown gh origin returns None
("user/with/deps", None), # url kind is not dealt with
],
......
......@@ -32,9 +32,14 @@ def _url_github_api(user_repo: str) -> str:
return f"https://api.github.com/repos/{user_repo}"
_SANITIZATION_RE = re.compile(r"^(.*?)/?(\.git)?/?$")
def _sanitize_github_url(url: str) -> str:
"""Sanitize github url."""
return url.lower().rstrip("/").rstrip(".git").rstrip("/")
m = _SANITIZATION_RE.match(url.lower())
assert m is not None, url # impossible, but mypy doesn't know it
return m.group(1)
def get_canonical_github_origin_url(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment