Skip to content

Commit d6b4dbf

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 d6b4dbf

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,12 @@ 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", return_value=b"bpo-123: Fix#12345 #1234 #12345Number Sign (#01234) (#11345)"
371371
):
372372
actual_commit_message = cp.get_commit_message(
373373
"22a594a0047d7706537ff2ac676cdc0f1dcb329c"
374374
)
375-
assert actual_commit_message == "bpo-123: Fix Spam Module (GH-113)"
375+
assert actual_commit_message == "bpo-123: Fix#12345 #1234 #12345Number Sign (#01234) (GH-11345)"
376376

377377

378378
def test_get_updated_commit_message_without_links_replacement(config):

0 commit comments

Comments
 (0)