Skip to content
Draft
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
5 changes: 1 addition & 4 deletions src/semantic_release/commit_parser/conventional/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ class ConventionalCommitParserOptions(ParserOptions):
one of these prefixes, it will not be considered a valid commit message.
"""

default_bump_level: LevelBump = LevelBump.NO_RELEASE
"""The minimum bump level to apply to valid commit message."""

parse_squash_commits: bool = True
"""Toggle flag for whether or not to parse squash commits"""

Expand All @@ -64,7 +61,7 @@ def __post_init__(self) -> None:
# for our expected output. Due to the empty second array, we know the first is always longest
# and that means no values in the first entry of the tuples will ever be a LevelBump. We
# apply a str() to make mypy happy although it will never happen.
*zip_longest(self.allowed_tags, (), fillvalue=self.default_bump_level),
*zip_longest(self.allowed_tags, (), fillvalue=LevelBump.NO_RELEASE),
*zip_longest(self.patch_tags, (), fillvalue=LevelBump.PATCH),
*zip_longest(self.minor_tags, (), fillvalue=LevelBump.MINOR),
]
Expand Down
4 changes: 1 addition & 3 deletions src/semantic_release/commit_parser/conventional/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,7 @@ def create_parsed_message_result(
level_bump = (
LevelBump.MAJOR
if body_components["breaking_descriptions"] or parsed_break
else self.options.tag_to_level.get(
parsed_type, self.options.default_bump_level
)
else self.options.tag_to_level.get(parsed_type, LevelBump.NO_RELEASE)
)

return ParsedMessageResult(
Expand Down
9 changes: 2 additions & 7 deletions src/semantic_release/commit_parser/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ class EmojiParserOptions(ParserOptions):
)
"""All commit-type prefixes that are allowed."""

default_bump_level: LevelBump = LevelBump.NO_RELEASE
"""The minimum bump level to apply to valid commit message."""

parse_linked_issues: bool = False
"""
Whether to parse linked issues from the commit message.
Expand Down Expand Up @@ -111,7 +108,7 @@ def __post_init__(self) -> None:
# for our expected output. Due to the empty second array, we know the first is always longest
# and that means no values in the first entry of the tuples will ever be a LevelBump. We
# apply a str() to make mypy happy although it will never happen.
*zip_longest(self.allowed_tags, (), fillvalue=self.default_bump_level),
*zip_longest(self.allowed_tags, (), fillvalue=LevelBump.NO_RELEASE),
*zip_longest(self.patch_tags, (), fillvalue=LevelBump.PATCH),
*zip_longest(self.minor_tags, (), fillvalue=LevelBump.MINOR),
*zip_longest(self.major_tags, (), fillvalue=LevelBump.MAJOR),
Expand Down Expand Up @@ -280,9 +277,7 @@ def parse_message(self, message: str) -> ParsedMessageResult:
primary_emoji = match.group("type") if match else "Other"
parsed_scope = (match.group("scope") if match else None) or ""

level_bump = self.options.tag_to_level.get(
primary_emoji, self.options.default_bump_level
)
level_bump = self.options.tag_to_level.get(primary_emoji, LevelBump.NO_RELEASE)

# All emojis will remain part of the returned description
body_components: dict[str, list[str]] = reduce(
Expand Down
12 changes: 2 additions & 10 deletions src/semantic_release/commit_parser/scipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ class ScipyParserOptions(ParserOptions):
one of these prefixes, it will not be considered a valid commit message.
"""

# TODO: breaking v11, make consistent with AngularParserOptions
default_level_bump: LevelBump = LevelBump.NO_RELEASE
"""The minimum bump level to apply to valid commit message."""

parse_squash_commits: bool = True
"""Toggle flag for whether or not to parse squash commits"""

Expand All @@ -161,16 +157,14 @@ def tag_to_level(self) -> dict[str, LevelBump]:
return self._tag_to_level

def __post_init__(self) -> None:
# TODO: breaking v11, remove as the name is now consistent
self.default_bump_level = self.default_level_bump
self._tag_to_level: dict[str, LevelBump] = {
str(tag): level
for tag, level in [
# we have to do a type ignore as zip_longest provides a type that is not specific enough
# for our expected output. Due to the empty second array, we know the first is always longest
# and that means no values in the first entry of the tuples will ever be a LevelBump. We
# apply a str() to make mypy happy although it will never happen.
*zip_longest(self.allowed_tags, (), fillvalue=self.default_bump_level),
*zip_longest(self.allowed_tags, (), fillvalue=LevelBump.NO_RELEASE),
*zip_longest(self.patch_tags, (), fillvalue=LevelBump.PATCH),
*zip_longest(self.minor_tags, (), fillvalue=LevelBump.MINOR),
*zip_longest(self.major_tags, (), fillvalue=LevelBump.MAJOR),
Expand Down Expand Up @@ -347,9 +341,7 @@ def parse_message(self, message: str) -> ParsedMessageResult | None:
},
)

level_bump = self.options.tag_to_level.get(
parsed_type, self.options.default_bump_level
)
level_bump = self.options.tag_to_level.get(parsed_type, LevelBump.NO_RELEASE)

return ParsedMessageResult(
bump=level_bump,
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/semantic_release/cli/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from semantic_release.commit_parser.scipy import ScipyParserOptions
from semantic_release.commit_parser.tag import TagParserOptions
from semantic_release.const import DEFAULT_COMMIT_AUTHOR
from semantic_release.enums import LevelBump
from semantic_release.errors import ParserLoadError

from tests.fixtures.repos import repo_w_no_tags_conventional_commits
Expand Down Expand Up @@ -138,7 +137,6 @@ def test_load_user_defined_parser_opts():
"allowed_tags": ["foo", "bar", "baz"],
"minor_tags": ["bar"],
"patch_tags": ["baz"],
"default_bump_level": LevelBump.PATCH.value,
}
raw_config = RawConfig.model_validate(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1116,8 +1116,9 @@ def test_parser_return_release_notices_from_commit_message(
##############################
# test custom parser options #
##############################
def test_parser_custom_default_level(make_commit_obj: MakeCommitObjFn):
options = ConventionalCommitParserOptions(default_bump_level=LevelBump.MINOR)
def test_parser_other_allowed_tags_no_bump(make_commit_obj: MakeCommitObjFn):
"""Test that commits with other_allowed_tags get NO_RELEASE bump level."""
options = ConventionalCommitParserOptions()
parsed_results = ConventionalCommitParser(options).parse(
make_commit_obj("test(parser): add a test for conventional parser")
)
Expand All @@ -1126,7 +1127,7 @@ def test_parser_custom_default_level(make_commit_obj: MakeCommitObjFn):

result = next(iter(parsed_results))
assert isinstance(result, ParsedCommit)
assert result.bump is LevelBump.MINOR
assert result.bump is LevelBump.NO_RELEASE


def test_parser_custom_allowed_types(
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/semantic_release/commit_parser/test_emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,3 +1073,17 @@ def test_parser_ignore_merge_commit(

assert isinstance(parsed_result, ParseError)
assert "Ignoring merge commit" in parsed_result.error


def test_parser_other_allowed_tags_no_bump(make_commit_obj: MakeCommitObjFn):
"""Test that commits with other_allowed_tags get NO_RELEASE bump level."""
options = EmojiParserOptions()
parsed_results = EmojiCommitParser(options).parse(
make_commit_obj(":memo: add documentation for emoji parser")
)

assert isinstance(parsed_results, Iterable)

result = next(iter(parsed_results))
assert isinstance(result, ParsedCommit)
assert result.bump is LevelBump.NO_RELEASE
14 changes: 14 additions & 0 deletions tests/unit/semantic_release/commit_parser/test_scipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,3 +1361,17 @@ def test_parser_ignore_merge_commit(

assert isinstance(parsed_result, ParseError)
assert "Ignoring merge commit" in parsed_result.error


def test_parser_other_allowed_tags_no_bump(make_commit_obj: MakeCommitObjFn):
"""Test that commits with other_allowed_tags get NO_RELEASE bump level."""
options = ScipyParserOptions()
parsed_results = ScipyCommitParser(options).parse(
make_commit_obj("TST: add a test for scipy parser")
)

assert isinstance(parsed_results, Iterable)

result = next(iter(parsed_results))
assert isinstance(result, ParsedCommit)
assert result.bump is LevelBump.NO_RELEASE