Repository: python/cherry-picker

Issue:
Username detection fails with a trailing slash
I have my remote origin set to ``https://github.com/AA-Turner/cpython/``.

```ps1con
PS> git remote -v
origin  https://github.com/AA-Turner/cpython/ (fetch)
origin  https://github.com/AA-Turner/cpython/ (push)
upstream        https://github.com/python/cpython/ (fetch)
upstream        https://github.com/python/cpython/ (push)
```

``cherry_picker`` runs ``git config --get remote.origin.url``, which returns the above url, and then runs ``username = result.replace(":", "/").split("/")[-2]``. This returns ``cpython``, which means that I have to manually edit the URL on every backport.

``cherry_picker`` should instead trim any trailing slash.

A

Discussion:

Patch:
diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py
index 66bde15..3e59f39 100755
--- a/cherry_picker/cherry_picker.py
+++ b/cherry_picker/cherry_picker.py
@@ -198,7 +198,7 @@ class CherryPicker:
         cmd = ["git", "config", "--get", f"remote.{self.pr_remote}.url"]
         result = self.run_cmd(cmd, required_real_result=True)
         # implicit ssh URIs use : to separate host from user, others just use /
-        username = result.replace(":", "/").split("/")[-2]
+        username = result.replace(":", "/").rstrip("/").split("/")[-2]
         return username
 
     def get_cherry_pick_branch(self, maint_branch):


Test patch:
diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py
index bffb11d..3a9f670 100644
--- a/cherry_picker/test_cherry_picker.py
+++ b/cherry_picker/test_cherry_picker.py
@@ -343,10 +343,13 @@ def test_get_pr_url(config):
     [
         b"git@github.com:mock_user/cpython.git",
         b"git@github.com:mock_user/cpython",
+        b"git@github.com:mock_user/cpython/",
         b"ssh://git@github.com/mock_user/cpython.git",
         b"ssh://git@github.com/mock_user/cpython",
+        b"ssh://git@github.com/mock_user/cpython/",
         b"https://github.com/mock_user/cpython.git",
         b"https://github.com/mock_user/cpython",
+        b"https://github.com/mock_user/cpython/",
     ],
 )
 def test_username(url, config):