Skip to content

Commit

Permalink
fix: account for trailing newlines in commit messages (#495)
Browse files Browse the repository at this point in the history
Fixes #490
  • Loading branch information
bernardcooke53 committed Aug 23, 2022
1 parent bd2201f commit 111b151
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
11 changes: 9 additions & 2 deletions semantic_release/history/logs.py
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
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
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"

0 comments on commit 111b151

Please sign in to comment.