Skip to content

Commit

Permalink
feat: add setting for enforcing textual changelog sections (#502)
Browse files Browse the repository at this point in the history
Resolves #498

Add the `use_textual_changelog_sections` setting flag for enforcing that
changelog section headings will always be regular ASCII when using the Emoji
parser.
  • Loading branch information
cowofevil committed Sep 25, 2022
1 parent ffae2dc commit 988437d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
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

0 comments on commit 988437d

Please sign in to comment.