Skip to content

Commit 62f39f1

Browse files
Make # replacing more strict
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
1 parent 45e0d09 commit 62f39f1

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

cherry_picker/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Backport CPython changes from main to maintenance branches."""
2+
23
from __future__ import annotations
34

45
import importlib.metadata

cherry_picker/cherry_picker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,12 @@ def get_commit_message(self, commit_sha):
261261
click.echo(err.output)
262262
raise CherryPickException(f"Error getting commit message for {commit_sha}")
263263
if self.config["fix_commit_msg"]:
264-
return message.replace("#", "GH-")
264+
# Only replace "#" with "GH-" with the following conditions:
265+
# * "#" is separated from the previous word
266+
# * "#" is followed by at least 5-digit number that
267+
# does not start with 0
268+
# * the number is separated from the following word
269+
return re.sub(r"\B#(?=[1-9][0-9]{4,}\b)", "GH-", message)
265270
else:
266271
return message
267272

cherry_picker/test_cherry_picker.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,16 @@ def test_get_updated_commit_message(config):
367367
"origin", "22a594a0047d7706537ff2ac676cdc0f1dcb329c", branches, config=config
368368
)
369369
with mock.patch(
370-
"subprocess.check_output", return_value=b"bpo-123: Fix Spam Module (#113)"
370+
"subprocess.check_output",
371+
return_value=b"bpo-123: Fix#12345 #1234 #12345Number Sign (#01234) (#11345)",
371372
):
372373
actual_commit_message = cp.get_commit_message(
373374
"22a594a0047d7706537ff2ac676cdc0f1dcb329c"
374375
)
375-
assert actual_commit_message == "bpo-123: Fix Spam Module (GH-113)"
376+
assert (
377+
actual_commit_message
378+
== "bpo-123: Fix#12345 #1234 #12345Number Sign (#01234) (GH-11345)"
379+
)
376380

377381

378382
def test_get_updated_commit_message_without_links_replacement(config):

0 commit comments

Comments
 (0)