From 41cb2b8229cd934905d716aa3b3ff355b4e9c20d Mon Sep 17 00:00:00 2001 From: Igor Davydenko Date: Thu, 3 Nov 2022 20:14:52 +0100 Subject: [PATCH] feat(changelog): Do not duplicate same commit messages (#196) When producing changelog. So, if release has 2 or more similar commit messages, only first one will be shown in changelog. Issue: #189 --- src/badabump/changelog.py | 16 +++++++++------- tests/test_changelog.py | 23 +++++++++++++++-------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/badabump/changelog.py b/src/badabump/changelog.py index 9374f6a..e6b4fcd 100644 --- a/src/badabump/changelog.py +++ b/src/badabump/changelog.py @@ -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) diff --git a/tests/test_changelog.py b/tests/test_changelog.py index 38a2dd3..b8c7254 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -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" @@ -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: @@ -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: @@ -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:** @@ -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: ------ @@ -121,6 +121,10 @@ UTCNOW = datetime.datetime.utcnow() +def test_changelog_duplicate_commits_with_prs(): + ... + + @pytest.mark.parametrize( "changelog_type, format_type, expected", ( @@ -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( @@ -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