From 14a359a255c312313ab9a7aec1c3eb1d38458a3e Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Fri, 12 Dec 2025 14:09:49 +0100 Subject: [PATCH] Make PullReqest.parse_id() more permissive by accepting trailing whitespaces --- osc/gitea_api/pr.py | 4 ++-- tests/test_gitea_api_pr.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/osc/gitea_api/pr.py b/osc/gitea_api/pr.py index 953b3245..262fa879 100644 --- a/osc/gitea_api/pr.py +++ b/osc/gitea_api/pr.py @@ -29,9 +29,9 @@ class PullRequest(GiteaModel): """ Split /# or /! into individual components and return them in a tuple. """ - match = re.match(r"^([^/]+)/([^/]+)[#!]([0-9]+)$", pr_id) + match = re.match(r"^([^/]+)/([^/]+)[#!]([0-9]+)\s*$", pr_id) if not match: - match = re.match(r"^([^/]+)/([^/]+)/pulls/([0-9]+)$", pr_id) + match = re.match(r"^([^/]+)/([^/]+)/pulls/([0-9]+)\s*$", pr_id) if not match: raise ValueError(f"Invalid pull request id: {pr_id}") diff --git a/tests/test_gitea_api_pr.py b/tests/test_gitea_api_pr.py index a99d46a6..aa0b6d2f 100644 --- a/tests/test_gitea_api_pr.py +++ b/tests/test_gitea_api_pr.py @@ -167,7 +167,7 @@ class TestGiteaApiPullRequestUrlParsing(unittest.TestCase): class TestGiteaApiPullRequestReferences(unittest.TestCase): PR_BODY = """ PR: foo/bar!1 -PR: foo/bar#2 +PR: foo/bar#2\r text PR: bar/baz#3 text @@ -190,7 +190,7 @@ text actual = PullRequest.add_pr_references(self.PR_BODY, [('xxx', 'xxx', 4), ('yyy', 'yyy', 5)]) expected = """ PR: foo/bar!1 -PR: foo/bar#2 +PR: foo/bar#2\r text PR: bar/baz#3 PR: xxx/xxx!4 @@ -207,7 +207,7 @@ text actual = PullRequest.add_pr_references(self.PR_BODY + "\nPR: a/b#123", [('xxx', 'xxx', 4), ('yyy', 'yyy', 5)]) expected = """ PR: foo/bar!1 -PR: foo/bar#2 +PR: foo/bar#2\r text PR: bar/baz#3 text