Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make # replacing more strict #115

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cherry_picker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Backport CPython changes from main to maintenance branches."""

from __future__ import annotations

import importlib.metadata
Expand Down
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
8 changes: 6 additions & 2 deletions cherry_picker/test_cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading