diff --git a/cherry_picker/__init__.py b/cherry_picker/__init__.py index 9dfa236..843751f 100644 --- a/cherry_picker/__init__.py +++ b/cherry_picker/__init__.py @@ -1,4 +1,5 @@ """Backport CPython changes from main to maintenance branches.""" + from __future__ import annotations import importlib.metadata diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 5ff8615..715557f 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -261,7 +261,12 @@ def get_commit_message(self, commit_sha): click.echo(err.output) raise CherryPickException(f"Error getting commit message for {commit_sha}") if self.config["fix_commit_msg"]: - return message.replace("#", "GH-") + # Only replace "#" with "GH-" with the following conditions: + # * "#" is separated from the previous word + # * "#" is followed by at least 5-digit number that + # does not start with 0 + # * the number is separated from the following word + return re.sub(r"\B#(?=[1-9][0-9]{4,}\b)", "GH-", message) else: return message diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index 3a9f670..0876440 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -367,12 +367,16 @@ def test_get_updated_commit_message(config): "origin", "22a594a0047d7706537ff2ac676cdc0f1dcb329c", branches, config=config ) with mock.patch( - "subprocess.check_output", return_value=b"bpo-123: Fix Spam Module (#113)" + "subprocess.check_output", + return_value=b"bpo-123: Fix#12345 #1234 #12345Number Sign (#01234) (#11345)", ): actual_commit_message = cp.get_commit_message( "22a594a0047d7706537ff2ac676cdc0f1dcb329c" ) - assert actual_commit_message == "bpo-123: Fix Spam Module (GH-113)" + assert ( + actual_commit_message + == "bpo-123: Fix#12345 #1234 #12345Number Sign (#01234) (GH-11345)" + ) def test_get_updated_commit_message_without_links_replacement(config):