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

feat: add setting for enforcing ascii changlelog sections #502

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/configuration.rst
Expand Up @@ -233,6 +233,17 @@ create patch releases.

Default: `:ambulance:, :lock:, :bug:, :zap:, :goal_net:, :alien:, :wheelchair:, :speech_balloon:, :mag:, :apple:, :penguin:, :checkered_flag:, :robot:, :green_apple:`

.. _config-use_textual_changelog_sections:

``use_textual_changelog_sections``
------------------------------------

If this is set to `true` with using the :py:func:`semantic_release.history.emoji_parser`,
semantic-release will use human readable ASCII section headings in the changelog instead of
the configured emoji.

Default: `false`

.. _config-scipy-parser:

``scipy_parser``
Expand Down
1 change: 1 addition & 0 deletions semantic_release/defaults.cfg
Expand Up @@ -11,6 +11,7 @@ changelog_file=CHANGELOG.md
changelog_placeholder=<!--next-version-placeholder-->
changelog_scope=true
changelog_sections=feature,fix,breaking,documentation,performance,:boom:,:sparkles:,:children_crossing:,:lipstick:,:iphone:,:egg:,:chart_with_upwards_trend:,:ambulance:,:lock:,:bug:,:zap:,:goal_net:,:alien:,:wheelchair:,:speech_balloon:,:mag:,:apple:,:penguin:,:checkered_flag:,:robot:,:green_apple:,Other
use_textual_changelog_sections=false
check_build_status=false
include_additional_files=
commit_message=Automatically generated by python-semantic-release
Expand Down
4 changes: 4 additions & 0 deletions semantic_release/history/parser_emoji.py
Expand Up @@ -39,6 +39,7 @@ def parse_commit_message(
patch = config.get("patch_emoji").split(",")
all_emojis = major + minor + patch

use_textual_changelog_sections = config.get("use_textual_changelog_sections")
# Loop over emojis from most important to least important
# Therefore, we find the highest level emoji first
primary_emoji = "Other"
Expand All @@ -52,9 +53,12 @@ def parse_commit_message(
level_bump = 0
if primary_emoji in major:
level_bump = 3
primary_emoji = "breaking" if use_textual_changelog_sections else primary_emoji
elif primary_emoji in minor:
primary_emoji = "feature" if use_textual_changelog_sections else primary_emoji
level_bump = 2
elif primary_emoji in patch:
primary_emoji = "fix" if use_textual_changelog_sections else primary_emoji
level_bump = 1

# All emojis will remain part of the returned description
Expand Down
1 change: 1 addition & 0 deletions semantic_release/settings.py
Expand Up @@ -39,6 +39,7 @@ def _config_from_ini(paths):
flags = {
"changelog_capitalize",
"changelog_scope",
"use_textual_changelog_sections",
"check_build_status",
"commit_version_number",
"ignore_token_for_push",
Expand Down
37 changes: 37 additions & 0 deletions tests/parsers/test_emoji.py
@@ -1,5 +1,10 @@
import mock
import pytest

from semantic_release.history import emoji_parser

from .. import wrapped_config_get


def test_major():
commit = (
Expand Down Expand Up @@ -65,3 +70,35 @@ def test_emoji_in_description():
":boom: should not be detected",
]
assert parsed_commit[4] == []


@mock.patch(
"semantic_release.history.parser_emoji.config.get",
wrapped_config_get(use_textual_changelog_sections=True),
)
@pytest.mark.parametrize(
"level,commit,commit_type",
[
(
3,
":boom: Breaking changes\n\n"
"More description\n\n"
"Even more description",
"breaking",
),
(
2,
":sparkles: Add a new feature\n\n" "Some description of the feature",
"feature",
),
(
1,
":bug: Fixing a bug\n\n" "The bug is finally gone!",
"fix",
),
],
)
def test_use_textual_changelog_sections(level, commit, commit_type):
parsed_commit = emoji_parser(commit)
assert parsed_commit[0] == level
assert parsed_commit[1] == commit_type