Skip to content

Commit

Permalink
feat: Put refactor commits into separate section (#58)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
playpauseandstop committed Apr 6, 2021
1 parent 2c83d68 commit 7b1d508
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/badabump/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

COMMIT_TYPE_FEATURE = "feat"
COMMIT_TYPE_FIX = "fix"
COMMIT_TYPE_REFACTOR = "refactor"

COMMIT_TYPE_SUBJECT_RE = re.compile(
r"^(?P<commit_type>[^\:]+)\: (?P<description>.+)$"
Expand Down Expand Up @@ -109,23 +110,28 @@ 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:
if commit.commit_type == COMMIT_TYPE_FEATURE:
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
Expand Down Expand Up @@ -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":
Expand Down
33 changes: 31 additions & 2 deletions tests/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -86,6 +98,11 @@
- Update logic behind math operations
Refactoring:
------------
- [DEV-1010] Change algorigthm to use
Other:
------
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 7b1d508

Please sign in to comment.