Skip to content

fix: get_current_release_version incorrectly parses commit message with version #444

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

Closed
Closed
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
8 changes: 4 additions & 4 deletions semantic_release/history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def get_previous_version(version: str) -> Optional[str]:
:return: A string with the previous version number.
"""
found_version = False
for commit_hash, commit_message in get_commit_log():
for commit_hash, commit_message, _ in get_commit_log():
logger.debug(f"Checking commit {commit_hash}")
if version in commit_message:
found_version = True
Expand All @@ -349,7 +349,7 @@ def get_previous_release_version(version: str) -> Optional[str]:
:return: A string with the previous version number.
"""
found_version = False
for commit_hash, commit_message in get_commit_log():
for commit_hash, commit_message, _ in get_commit_log():
logger.debug(f"Checking commit {commit_hash}")
if version in commit_message:
found_version = True
Expand All @@ -372,10 +372,10 @@ def get_current_release_version_by_commits() -> str:

:return: A string with the current version number.
"""
for commit_hash, commit_message in get_commit_log():
for commit_hash, commit_message, commit_author in get_commit_log():
logger.debug(f"Checking commit {commit_hash}")
match = re.search(rf"{release_version_pattern}", commit_message)
if match:
if match and commit_author.name == "github-actions" and commit_author.email == "action@github.com":
logger.debug(f"Version matches regex {commit_message}")
return match.group(1).strip()

Expand Down
4 changes: 2 additions & 2 deletions semantic_release/history/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def evaluate_version_bump(current_version: str, force: str = None) -> Optional[s
changes = []
commit_count = 0

for _hash, commit_message in get_commit_log(current_version):
for _hash, commit_message, _ in get_commit_log(current_version):
if commit_message.startswith(current_version):
# Stop once we reach the current version
# (we are looping in the order of newest -> oldest)
Expand Down Expand Up @@ -98,7 +98,7 @@ def generate_changelog(from_version: str, to_version: str = None) -> dict:
rev = from_version

found_the_release = to_version is None
for _hash, commit_message in get_commit_log(rev):
for _hash, commit_message, _ in get_commit_log(rev):
if not found_the_release:
# Skip until we find the last commit in this release
# (we are looping in the order of newest -> oldest)
Expand Down
4 changes: 2 additions & 2 deletions semantic_release/hvcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import mimetypes
import os
from typing import Any, Optional, Union, cast
from typing import Any, Optional, Union
from urllib.parse import urlsplit

from gitlab import exceptions, gitlab
Expand Down Expand Up @@ -578,7 +578,7 @@ def upload_asset(
url,
params={"name": name},
data={},
files=[
files=[ # type: ignore
(
"attachment",
(
Expand Down
2 changes: 1 addition & 1 deletion semantic_release/vcs_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_commit_log(from_rev=None):
)

for commit in repo.iter_commits(rev):
yield (commit.hexsha, commit.message.replace("\r\n", "\n"))
yield (commit.hexsha, commit.message.replace("\r\n", "\n"), commit.author)


@check_repo
Expand Down
18 changes: 12 additions & 6 deletions tests/history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,46 @@
"221",
"feat(x): Add super-feature\n\n"
"BREAKING CHANGE: Uses super-feature as default instead of dull-feature.",
"Alice <alice@example.com>",
)
MAJOR2 = (
"222",
"feat(x): Add super-feature\n\nSome explanation\n\n"
"BREAKING CHANGE: Uses super-feature as default instead of dull-feature.",
"Alice <alice@example.com>",
)
MAJOR_MENTIONING_1_0_0 = (
"223",
"feat(x): Add super-feature\n\nSome explanation\n\n"
"BREAKING CHANGE: Uses super-feature as default instead of dull-feature from v1.0.0.",
"Alice <alice@example.com>",
)
MAJOR_MULTIPLE_FOOTERS = (
"244",
"feat(x): Lots of breaking changes\n\n"
"BREAKING CHANGE: Breaking change 1\n\n"
"Not a BREAKING CHANGE\n\n"
"BREAKING CHANGE: Breaking change 2",
"Alice <alice@example.com>",
)
MAJOR_EXCL_WITH_FOOTER = (
"231",
"feat(x)!: Add another feature\n\n"
"BREAKING CHANGE: Another feature, another breaking change",
"Alice <alice@example.com>",
)
MAJOR_EXCL_NOT_FOOTER = (
"232",
"fix!: Fix a big bug that everyone exploited\n\nThis is the reason you should not exploit bugs",
"Alice <alice@example.com>",
)
MINOR = ("111", "feat(x): Add non-breaking super-feature")
PATCH = ("24", "fix(x): Fix bug in super-feature")
NO_TAG = ("191", "docs(x): Add documentation for super-feature")
UNKNOWN_STYLE = ("7", "random commits are the worst")
MINOR = ("111", "feat(x): Add non-breaking super-feature", "Bob <bob@example.com>")
PATCH = ("24", "fix(x): Fix bug in super-feature", "Bob <bob@example.com>")
NO_TAG = ("191", "docs(x): Add documentation for super-feature", "John <john@example.com>")
UNKNOWN_STYLE = ("7", "random commits are the worst", "John <john@example.com>")

ALL_KINDS_OF_COMMIT_MESSAGES = [MINOR, MAJOR, MINOR, PATCH]
MINOR_AND_PATCH_COMMIT_MESSAGES = [MINOR, PATCH]
PATCH_COMMIT_MESSAGES = [PATCH, PATCH]
MAJOR_LAST_RELEASE_MINOR_AFTER = [MINOR, ("22", "1.1.0"), MAJOR]
MAJOR_MENTIONING_LAST_VERSION = [MAJOR_MENTIONING_1_0_0, ("22", "1.0.0"), MAJOR]
MAJOR_LAST_RELEASE_MINOR_AFTER = [MINOR, ("22", "1.1.0", "Doe <doe@example.com>"), MAJOR]
MAJOR_MENTIONING_LAST_VERSION = [MAJOR_MENTIONING_1_0_0, ("22", "1.0.0", "Doe <doe@example.com>"), MAJOR]
13 changes: 7 additions & 6 deletions tests/history/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_scope_is_included_in_changelog(commit, commit_type, expected):

@mock.patch(
"semantic_release.history.logs.get_commit_log",
lambda *a, **k: [("24", "fix: Fix another bug")],
lambda *a, **k: [("24", "fix: Fix another bug", "Alice <alice@example.com>")],
)
def test_scope_is_omitted_with_empty_scope():
changelog = generate_changelog("0.0.0")
Expand Down Expand Up @@ -123,15 +123,16 @@ def test_scope_included_in_changelog_configurable(commit, commit_type):

@mock.patch(
"semantic_release.history.logs.get_commit_log",
lambda *a, **k: [("23", "fix(x): abCD"), ("23", "fix: abCD")],
lambda *a, **k: [("23", "fix(x): abCD", "Alice <alice@example.com>"),
("23", "fix: abCD", "Alice <alice@example.com>")],
)
@pytest.mark.parametrize(
"commit,config_setting,expected_description",
[
(("23", "fix(x): abCD"), True, "**x:** AbCD"),
(("23", "fix(x): abCD"), False, "**x:** abCD"),
(("23", "fix: abCD"), True, "AbCD"),
(("23", "fix: abCD"), False, "abCD"),
(("23", "fix(x): abCD", "Alice <alice@example.com>"), True, "**x:** AbCD"),
(("23", "fix(x): abCD", "Alice <alice@example.com>"), False, "**x:** abCD"),
(("23", "fix: abCD", "Alice <alice@example.com>"), True, "AbCD"),
(("23", "fix: abCD", "Alice <alice@example.com>"), False, "abCD"),
],
)
def test_message_capitalization_is_configurable(
Expand Down
28 changes: 20 additions & 8 deletions tests/history/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import mock
import pytest
from git.util import Actor

import semantic_release
from semantic_release.history import (
Expand Down Expand Up @@ -92,28 +93,33 @@ def test_current_release_version_should_return_default_version(
class TestGetPreviousVersion:
@mock.patch(
"semantic_release.history.get_commit_log",
lambda: [("211", "0.10.0"), ("13", "0.9.0")],
lambda: [("211", "0.10.0", Actor("github-actions", "action@github.com")),
("13", "0.9.0", Actor("github-actions", "action@github.com"))],
)
def test_should_return_correct_version(self):
assert get_previous_version("0.10.0") == "0.9.0"

@mock.patch(
"semantic_release.history.get_commit_log",
lambda: [("211", "v0.10.0"), ("13", "v0.9.0")],
lambda: [("211", "v0.10.0", Actor("github-actions", "action@github.com")),
("13", "v0.9.0", Actor("github-actions", "action@github.com"))],
)
def test_should_return_correct_version_with_v(self):
assert get_previous_version("0.10.0") == "0.9.0"

@mock.patch(
"semantic_release.history.get_commit_log",
lambda: [("211", "0.10.0-beta"), ("13", "0.9.0")],
lambda: [("211", "0.10.0-beta", Actor("github-actions", "action@github.com")),
("13", "0.9.0", Actor("github-actions", "action@github.com"))],
)
def test_should_return_correct_version_from_prerelease(self):
assert get_previous_version("0.10.0-beta") == "0.9.0"

@mock.patch(
"semantic_release.history.get_commit_log",
lambda: [("211", "0.10.0"), ("13", "0.10.0-beta"), ("13", "0.9.0")],
lambda: [("211", "0.10.0", Actor("github-actions", "action@github.com")),
("13", "0.10.0-beta", Actor("github-actions", "action@github.com")),
("13", "0.9.0", Actor("github-actions", "action@github.com"))],
)
def test_should_return_correct_version_skip_prerelease(self):
assert get_previous_version("0.10.0-beta") == "0.9.0"
Expand All @@ -122,28 +128,34 @@ def test_should_return_correct_version_skip_prerelease(self):
class TestGetCurrentReleaseVersionByCommits:
@mock.patch(
"semantic_release.history.get_commit_log",
lambda: [("211", "0.10.0-beta.1"), ("13", "0.9.1-beta.1"), ("13", "0.9.0")],
lambda: [("211", "0.10.0-beta.1", Actor("github-actions", "action@github.com")),
("13", "0.9.1-beta.1", Actor("github-actions", "action@github.com")),
("13", "0.9.0", Actor("github-actions", "action@github.com"))],
)
def test_should_return_correct_version(self):
assert get_current_release_version_by_commits() == "0.9.0"

@mock.patch(
"semantic_release.history.get_commit_log",
lambda: [("211", "v0.10.0-beta.1"), ("13", "0.9.1-beta.1"), ("13", "v0.9.0")],
lambda: [("211", "v0.10.0-beta.1", Actor("github-actions", "action@github.com")),
("13", "0.9.1-beta.1", Actor("github-actions", "action@github.com")),
("13", "v0.9.0", Actor("github-actions", "action@github.com"))],
)
def test_should_return_correct_version_with_v(self):
assert get_current_release_version_by_commits() == "0.9.0"

@mock.patch(
"semantic_release.history.get_commit_log",
lambda: [("211", "0.10.0-beta.0"), ("13", "0.9.0")],
lambda: [("211", "0.10.0-beta.0", Actor("github-actions", "action@github.com")),
("13", "0.9.0", Actor("github-actions", "action@github.com"))],
)
def test_should_return_correct_version_from_prerelease(self):
assert get_current_release_version_by_commits() == "0.9.0"

@mock.patch(
"semantic_release.history.get_commit_log",
lambda: [("211", "7.28.0"), ("13", "7.27.0")],
lambda: [("211", "7.28.0", Actor("github-actions", "action@github.com")),
("13", "7.27.0", Actor("github-actions", "action@github.com"))],
)
def test_should_return_correct_version_without_prerelease(self):
assert get_current_release_version_by_commits() == "7.28.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/history/test_version_bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_patch():
def test_nothing_if_no_tag():
with mock.patch(
"semantic_release.history.logs.get_commit_log",
lambda *a, **kw: [("", "...")],
lambda *a, **kw: [("", "...", "")],
):
assert evaluate_version_bump("0.0.0") is None

Expand Down