From b9069bf2b725454436e97b92e48afb9c093a1e99 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Mon, 16 Sep 2024 18:16:02 +0100 Subject: [PATCH 1/2] Handle whitespace when calculating usernames --- cherry_picker/cherry_picker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index f2046ee..08edeff 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -196,7 +196,7 @@ def sorted_branches(self): @property def username(self): cmd = ["git", "config", "--get", f"remote.{self.pr_remote}.url"] - result = self.run_cmd(cmd, required_real_result=True) + result = self.run_cmd(cmd, required_real_result=True).strip("\n") # implicit ssh URIs use : to separate host from user, others just use / username = result.replace(":", "/").rstrip("/").split("/")[-2] return username From efc4c86465558847474e769500ec29d6bdfb8840 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Tue, 17 Sep 2024 01:59:11 +0100 Subject: [PATCH 2/2] Add test, strip all whitespace --- cherry_picker/cherry_picker.py | 2 +- cherry_picker/test_cherry_picker.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 08edeff..423c76f 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -196,7 +196,7 @@ def sorted_branches(self): @property def username(self): cmd = ["git", "config", "--get", f"remote.{self.pr_remote}.url"] - result = self.run_cmd(cmd, required_real_result=True).strip("\n") + result = self.run_cmd(cmd, required_real_result=True).strip() # implicit ssh URIs use : to separate host from user, others just use / username = result.replace(":", "/").rstrip("/").split("/")[-2] return username diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index 5138c83..9ce5cce 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -351,6 +351,10 @@ def test_get_pr_url(config): b"https://github.com/mock_user/cpython.git", b"https://github.com/mock_user/cpython", b"https://github.com/mock_user/cpython/", + # test trailing whitespace + b"https://github.com/mock_user/cpython.git\n", + b"https://github.com/mock_user/cpython\n", + b"https://github.com/mock_user/cpython/\n", ], ) def test_username(url, config):