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

fix: account for trailing newlines in commit messages #495

Merged
merged 1 commit into from
Aug 23, 2022
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
11 changes: 9 additions & 2 deletions semantic_release/history/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def evaluate_version_bump(current_version: str, force: str = None) -> Optional[s

current_version_commit = get_formatted_commit(current_version)
for _hash, commit_message in get_commit_log(current_version):
if commit_message == current_version_commit:
# https://github.com/relekang/python-semantic-release/issues/490 -
# commit messages (which we compare with ==) have a trailing newline
if commit_message.strip() == current_version_commit.strip():
# Stop once we reach the current version
# (we are looping in the order of newest -> oldest)
logger.debug(
Expand Down Expand Up @@ -115,7 +117,12 @@ def generate_changelog(
)
found_the_release = True

if from_version_commit and commit_message == from_version_commit:
# See https://github.com/relekang/python-semantic-release/issues/490 -
# commit messages (which we compare with ==) have a trailing newline
if (
from_version_commit
and commit_message.strip() == from_version_commit.strip()
):
# We reached the previous release
logger.debug(f"{from_version} reached, ending changelog generation")
break
Expand Down
4 changes: 2 additions & 2 deletions tests/history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
PATCH_COMMIT_MESSAGES = [PATCH, PATCH]
MAJOR_LAST_RELEASE_MINOR_AFTER = [
MINOR,
("22", "1.1.0\n\nAutomatically generated by python-semantic-release"),
("22", "1.1.0\n\nAutomatically generated by python-semantic-release\n"),
MAJOR,
]
MAJOR_MENTIONING_LAST_VERSION = [
MAJOR_MENTIONING_1_0_0,
("22", "1.0.0\n\nAutomatically generated by python-semantic-release"),
("22", "1.0.0\n\nAutomatically generated by python-semantic-release\n"),
MAJOR,
]
53 changes: 53 additions & 0 deletions tests/history/test_version_bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,44 @@ def test_should_search_for_release_with_commit_subject_pattern():
assert evaluate_version_bump("1.0.0") == "minor"


@mock.patch(
"semantic_release.history.config.get",
wrapped_config_get(
commit_subject="chore(release): {version}",
commit_message="Custom message",
),
)
@mock.patch(
"semantic_release.history.logs.get_commit_log",
lambda *a, **kw: [
MINOR,
("777", "chore(release): 1.0.0\n\nCustom message \n"),
MAJOR,
],
)
def test_should_search_for_release_with_commit_subject_pattern_including_whitespace():
assert evaluate_version_bump("1.0.0") == "minor"


@mock.patch(
"semantic_release.history.config.get",
wrapped_config_get(
commit_subject="chore(release): {version}",
commit_message="Custom message ",
),
)
@mock.patch(
"semantic_release.history.logs.get_commit_log",
lambda *a, **kw: [
MINOR,
("777", "chore(release): 1.0.0\n\nCustom message\n"),
MAJOR,
],
)
def test_should_search_for_release_with_commit_subject_pattern_including_whitespace_in_configuration():
assert evaluate_version_bump("1.0.0") == "minor"


@mock.patch(
"semantic_release.history.config.get",
wrapped_config_get(
Expand All @@ -120,3 +158,18 @@ def test_should_search_for_release_with_commit_subject_pattern():
)
def test_should_not_search_for_release_without_commit_subject_pattern():
assert evaluate_version_bump("1.0.0") == "major"


@mock.patch(
"semantic_release.history.config.get",
wrapped_config_get(
commit_subject="chore(release): {version}",
commit_message="Custom message",
),
)
@mock.patch(
"semantic_release.history.logs.get_commit_log",
lambda *a, **kw: [MINOR, ("777", "1.0.0\n"), MAJOR],
)
def test_should_not_search_for_release_without_commit_subject_pattern_including_whitespace():
assert evaluate_version_bump("1.0.0") == "major"