Skip to content
Snippets Groups Projects
Commit a0497557 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

gitweb: Remove invalid use of str.rstrip

rstrip is not a method to remove a string suffix so use another
way to extract gitweb project name.

It fixes the computation of some gitweb origin URLs.

Related to swh/infra/sysadm-environment#5050.
parent aa7b3fa7
No related branches found
Tags v5.9.2
1 merge request!504gitweb: Remove invalid use of str.rstrip
Pipeline #4413 passed
...@@ -167,13 +167,9 @@ def try_to_determine_git_repository(repository_url: str) -> Optional[str]: ...@@ -167,13 +167,9 @@ def try_to_determine_git_repository(repository_url: str) -> Optional[str]:
""" """
result = None result = None
parsed_url = urlparse(repository_url) parsed_url = urlparse(repository_url)
params = parse_qs(parsed_url.query).get("p") repo = parse_qs(parsed_url.query, separator=";").get("p")
if params: if repo:
repo = params[0] result = f"git://{parsed_url.netloc}/{repo[0]}"
if repo and repo.endswith(";a=summary"):
repo = repo.rstrip(";a=summary")
result = f"git://{parsed_url.netloc}/{repo}"
return result return result
......
...@@ -138,6 +138,10 @@ def test_lister_gitweb_get_origin_from_repo_failing( ...@@ -138,6 +138,10 @@ def test_lister_gitweb_get_origin_from_repo_failing(
"https://git.shadowcat.co.uk?p=File-Slurp.git;a=summary", "https://git.shadowcat.co.uk?p=File-Slurp.git;a=summary",
"git://git.shadowcat.co.uk/File-Slurp.git", "git://git.shadowcat.co.uk/File-Slurp.git",
), ),
(
"https://git.example.org?p=baaaa;a=summary",
"git://git.example.org/baaaa",
),
("https://domain.org/foobar", None), ("https://domain.org/foobar", None),
], ],
) )
......
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