Skip to content

Commit

Permalink
feat(changelog): Do not duplicate same commit messages (#196)
Browse files Browse the repository at this point in the history
When producing changelog. So, if release has 2 or more similar commit
messages, only first one will be shown in changelog.

Issue: #189
  • Loading branch information
playpauseandstop authored Nov 3, 2022
1 parent 5823846 commit 41cb2b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
16 changes: 9 additions & 7 deletions src/badabump/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,16 @@ def format_block(
return "\n\n".join((header, items))

def format_commits(commits: Iterator[ConventionalCommit]) -> str:
return "\n".join(
ul_li(
item.format(
format_type, ignore_footer_urls=ignore_footer_urls
)
formatted_commits = []
for commit in commits:
formatted_commit = commit.format(
format_type, ignore_footer_urls=ignore_footer_urls
)
for item in commits
)
if formatted_commit in formatted_commits:
continue
formatted_commits.append(formatted_commit)

return "\n".join(ul_li(item) for item in formatted_commits)

features = format_block("Features:", self.feature_commits)
fixes = format_block("Fixes:", self.fix_commits)
Expand Down
23 changes: 15 additions & 8 deletions tests/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
- Export types, enums, utils, themes
- Update components to use styled-components ThemeProvider
Issue: IFXND-55
Issue: DEV-55
"""

FIX_COMMIT = "fix: Update logic behind math operations"
Expand All @@ -48,7 +48,7 @@

CHANGELOG_FILE_MD = """## Features:
- [IFXND-55] Export necessary types from the package (#31)
- [DEV-55] Export necessary types from the package (#31)
## Fixes:
Expand All @@ -65,7 +65,7 @@

CHANGELOG_FILE_MD_PRE = """### Features:
- [IFXND-55] Export necessary types from the package (#31)
- [DEV-55] Export necessary types from the package (#31)
### Fixes:
Expand All @@ -82,7 +82,7 @@

CHANGELOG_FILE_RST = CHANGELOG_GIT_RST = """**Features:**
- [IFXND-55] Export necessary types from the package (#31)
- [DEV-55] Export necessary types from the package (#31)
**Fixes:**
Expand All @@ -100,7 +100,7 @@
CHANGELOG_GIT_MD = """Features:
---------
- [IFXND-55] Export necessary types from the package (#31)
- [DEV-55] Export necessary types from the package (#31)
Fixes:
------
Expand All @@ -121,6 +121,10 @@
UTCNOW = datetime.datetime.utcnow()


def test_changelog_duplicate_commits_with_prs():
...


@pytest.mark.parametrize(
"changelog_type, format_type, expected",
(
Expand Down Expand Up @@ -163,8 +167,11 @@ def test_changelog_format_file(format_type, is_pre_release, expected):
FEATURE_COMMIT,
FIX_COMMIT,
CI_BREAKING_COMMIT,
REFACTOR_COMMIT,
DOCS_SCOPE_COMMIT,
REFACTOR_COMMIT,
CI_BREAKING_COMMIT,
REFACTOR_COMMIT,
]
)
content = changelog.format(
Expand Down Expand Up @@ -320,18 +327,18 @@ def test_commit_feature():
commit.description == "Export necessary types from the package (#31)"
)
assert commit.is_breaking_change is False
assert commit.issues == ("IFXND-55",)
assert commit.issues == ("DEV-55",)
assert (
commit.body
== """- Export types, enums, utils, themes
- Update components to use styled-components ThemeProvider
Issue: IFXND-55"""
Issue: DEV-55"""
)
assert commit.scope is None
assert (
commit.format(FormatTypeEnum.markdown)
== "[IFXND-55] Export necessary types from the package (#31)"
== "[DEV-55] Export necessary types from the package (#31)"
)
assert commit.format(FormatTypeEnum.markdown) == commit.format(
FormatTypeEnum.rst
Expand Down

0 comments on commit 41cb2b8

Please sign in to comment.