From a04975571cad46c5e4d21ed53ac0f49089cb1c99 Mon Sep 17 00:00:00 2001
From: Antoine Lambert <anlambert@softwareheritage.org>
Date: Tue, 26 Sep 2023 13:42:37 +0200
Subject: [PATCH] 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.
---
 swh/lister/gitweb/lister.py            | 10 +++-------
 swh/lister/gitweb/tests/test_lister.py |  4 ++++
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/swh/lister/gitweb/lister.py b/swh/lister/gitweb/lister.py
index 8d0d81b8..1710ba79 100644
--- a/swh/lister/gitweb/lister.py
+++ b/swh/lister/gitweb/lister.py
@@ -167,13 +167,9 @@ def try_to_determine_git_repository(repository_url: str) -> Optional[str]:
     """
     result = None
     parsed_url = urlparse(repository_url)
-    params = parse_qs(parsed_url.query).get("p")
-    if params:
-        repo = params[0]
-        if repo and repo.endswith(";a=summary"):
-            repo = repo.rstrip(";a=summary")
-
-        result = f"git://{parsed_url.netloc}/{repo}"
+    repo = parse_qs(parsed_url.query, separator=";").get("p")
+    if repo:
+        result = f"git://{parsed_url.netloc}/{repo[0]}"
     return result
 
 
diff --git a/swh/lister/gitweb/tests/test_lister.py b/swh/lister/gitweb/tests/test_lister.py
index 1c83e7dc..dbb5ecbf 100644
--- a/swh/lister/gitweb/tests/test_lister.py
+++ b/swh/lister/gitweb/tests/test_lister.py
@@ -138,6 +138,10 @@ def test_lister_gitweb_get_origin_from_repo_failing(
             "https://git.shadowcat.co.uk?p=File-Slurp.git;a=summary",
             "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),
     ],
 )
-- 
GitLab