From cecf6cb06089511aaef41d944bd43d28875fc922 Mon Sep 17 00:00:00 2001 From: Igor Davydenko Date: Mon, 5 Apr 2021 23:32:19 +0200 Subject: [PATCH] feat: Put refactor commits into separate section Previously all `refactor` commits was a part of _Other_ section, which suppress the fact that most of refactor commits should be highlighted in ChangeLog as they at most times contain important updates. Fixes: #34 --- src/badabump/changelog.py | 11 ++++++++++- tests/test_changelog.py | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/badabump/changelog.py b/src/badabump/changelog.py index a31e3d2..5d4315e 100644 --- a/src/badabump/changelog.py +++ b/src/badabump/changelog.py @@ -14,6 +14,7 @@ COMMIT_TYPE_FEATURE = "feat" COMMIT_TYPE_FIX = "fix" +COMMIT_TYPE_REFACTOR = "refactor" COMMIT_TYPE_SUBJECT_RE = re.compile( r"^(?P[^\:]+)\: (?P.+)$" @@ -109,11 +110,13 @@ class ChangeLog: feature_commits: Tuple[ConventionalCommit, ...] = attr.ib(init=False) fix_commits: Tuple[ConventionalCommit, ...] = attr.ib(init=False) + refactor_commits: Tuple[ConventionalCommit, ...] = attr.ib(init=False) other_commits: Tuple[ConventionalCommit, ...] = attr.ib(init=False) def __attrs_post_init__(self) -> None: feature_commits: List[ConventionalCommit] = [] fix_commits: List[ConventionalCommit] = [] + refactor_commits: List[ConventionalCommit] = [] other_commits: List[ConventionalCommit] = [] for commit in self.commits: @@ -121,11 +124,14 @@ def __attrs_post_init__(self) -> None: feature_commits.append(commit) elif commit.commit_type == COMMIT_TYPE_FIX: fix_commits.append(commit) + elif commit.commit_type == COMMIT_TYPE_REFACTOR: + refactor_commits.append(commit) else: other_commits.append(commit) object.__setattr__(self, "feature_commits", tuple(feature_commits)) object.__setattr__(self, "fix_commits", tuple(fix_commits)) + object.__setattr__(self, "refactor_commits", tuple(refactor_commits)) object.__setattr__(self, "other_commits", tuple(other_commits)) def format( # noqa: A003 @@ -176,9 +182,12 @@ def format_commits(commits: Iterator[ConventionalCommit]) -> str: features = format_block("Features:", self.feature_commits) fixes = format_block("Fixes:", self.fix_commits) + refactor = format_block("Refactoring:", self.refactor_commits) others = format_block("Other:", self.other_commits) - return "\n\n".join(item for item in (features, fixes, others) if item) + return "\n\n".join( + item for item in (features, fixes, refactor, others) if item + ) @classmethod def from_git_commits(cls, git_commits: Tuple[str, ...]) -> "ChangeLog": diff --git a/tests/test_changelog.py b/tests/test_changelog.py index 223d658..3ad6682 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -45,6 +45,10 @@ - Update logic behind math operations +## Refactoring: + +- [DEV-1010] Change algorigthm to use + ## Other: - **BREAKING CHANGE:** Use badabump release bot for pushing tags @@ -58,6 +62,10 @@ - Update logic behind math operations +### Refactoring: + +- [DEV-1010] Change algorigthm to use + ### Other: - **BREAKING CHANGE:** Use badabump release bot for pushing tags @@ -71,6 +79,10 @@ - Update logic behind math operations +**Refactoring:** + +- [DEV-1010] Change algorigthm to use + **Other:** - **BREAKING CHANGE:** Use badabump release bot for pushing tags @@ -86,6 +98,11 @@ - Update logic behind math operations +Refactoring: +------------ + +- [DEV-1010] Change algorigthm to use + Other: ------ @@ -133,7 +150,13 @@ def test_changelog_empty(changelog_type, format_type, expected): ) def test_changelog_format_file(format_type, is_pre_release, expected): changelog = ChangeLog.from_git_commits( - [FEATURE_COMMIT, FIX_COMMIT, CI_BREAKING_COMMIT, DOCS_SCOPE_COMMIT] + [ + FEATURE_COMMIT, + FIX_COMMIT, + CI_BREAKING_COMMIT, + DOCS_SCOPE_COMMIT, + REFACTOR_COMMIT, + ] ) content = changelog.format( ChangeLogTypeEnum.changelog_file, @@ -154,7 +177,13 @@ def test_changelog_format_file(format_type, is_pre_release, expected): ) def test_changelog_format_git(format_type, is_pre_release, expected): changelog = ChangeLog.from_git_commits( - [FEATURE_COMMIT, FIX_COMMIT, CI_BREAKING_COMMIT, DOCS_SCOPE_COMMIT] + [ + FEATURE_COMMIT, + FIX_COMMIT, + CI_BREAKING_COMMIT, + DOCS_SCOPE_COMMIT, + REFACTOR_COMMIT, + ] ) content = changelog.format( ChangeLogTypeEnum.git_commit,