Skip to content

Commit

Permalink
feat: add changelog_capitalize configuration
Browse files Browse the repository at this point in the history
Fixes #260
  • Loading branch information
keelerm84 authored and relekang committed Nov 24, 2020
1 parent da20b9b commit 7cacca1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
6 changes: 6 additions & 0 deletions docs/configuration.rst
Expand Up @@ -297,6 +297,12 @@ will be updated.

Default: ``<!--next-version-placeholder-->``.

``changelog_capitalize``
-------------------------
If set to false commit messages will not be automatically capitalized when generating the changelog.

Default: ``True``.

Distributions
=============

Expand Down
9 changes: 6 additions & 3 deletions semantic_release/history/logs.py
Expand Up @@ -115,12 +115,15 @@ def generate_changelog(from_version: str, to_version: str = None) -> dict:
logger.debug(f"Creating new changelog section for {message.type} ")
changes[message.type] = list()

# Capialize the first letter of the message, leaving others as they were
# Capitalize the first letter of the message, leaving others as they were
# (using str.capitalize() would make the other letters lowercase)
capital_message = (
formatted_message = (
message.descriptions[0][0].upper() + message.descriptions[0][1:]
)
changes[message.type].append((_hash, capital_message))
if config.get('changelog_capitalize') is False:
formatted_message = message.descriptions[0]

changes[message.type].append((_hash, formatted_message))

if message.breaking_descriptions:
# Copy breaking change descriptions into changelog
Expand Down
19 changes: 15 additions & 4 deletions tests/history/test_changelog.py
Expand Up @@ -4,6 +4,7 @@
from semantic_release.history.logs import generate_changelog

from . import *
from .. import wrapped_config_get


def test_should_generate_necessary_sections():
Expand Down Expand Up @@ -74,10 +75,20 @@ def test_should_get_multiple_breaking_descriptions():
assert changelog["breaking"][1][1] == "Breaking change 2"


def test_messages_are_capitalized():
@mock.patch(
"semantic_release.history.logs.get_commit_log",
lambda *a, **k: [("23", "fix(x): abCD")],
)
@pytest.mark.parametrize(
"config_setting,expected_description",
[
(True, "AbCD"),
(False, "abCD"),
],
)
def test_message_capitalization_is_configurable(config_setting, expected_description):
with mock.patch(
"semantic_release.history.logs.get_commit_log",
lambda *a, **k: [("23", "fix(x): abCD")],
"semantic_release.history.config.get", wrapped_config_get(changelog_capitalize=config_setting)
):
changelog = generate_changelog("0.0.0")
assert changelog["fix"][0][1] == "AbCD"
assert changelog["fix"][0][1] == expected_description

0 comments on commit 7cacca1

Please sign in to comment.