Skip to content

Commit

Permalink
Make # replacing more strict
Browse files Browse the repository at this point in the history
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
  • Loading branch information
serhiy-storchaka committed Feb 12, 2024
1 parent 45e0d09 commit d6b4dbf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions cherry_picker/test_cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,12 @@ 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):
Expand Down

0 comments on commit d6b4dbf

Please sign in to comment.