Skip to content

Commit d878e42

Browse files
committed
fix: restore commits for untyped section (closes #88)
1 parent b9bad9c commit d878e42

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/git_changelog/build.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ def add_commit(self, commit: Commit) -> None:
159159
"""
160160
self.commits.append(commit)
161161
commit.version = self.tag or "HEAD"
162-
if commit_type := commit.convention.get("type"):
163-
if commit_type not in self.sections_dict:
164-
section = Section(section_type=commit_type)
165-
self.sections_list.append(section)
166-
self.sections_dict[commit_type] = section
167-
self.sections_dict[commit_type].commits.append(commit)
162+
commit_type = commit.convention.get("type")
163+
if commit_type not in self.sections_dict:
164+
section = Section(section_type=commit_type)
165+
self.sections_list.append(section)
166+
self.sections_dict[commit_type] = section
167+
self.sections_dict[commit_type].commits.append(commit)
168168

169169

170170
class Changelog:

tests/test_build.py

+26
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,29 @@ def test_ignore_nonsemver_tag(repo: GitRepo) -> None:
321321
expected_prev_tag=None,
322322
expected_commits=[commit_c, commit_b, commit_a],
323323
)
324+
325+
326+
def test_untyped_commits(repo: GitRepo) -> None:
327+
"""Test capture of untyped (i.e. uncategorizable) commits.
328+
329+
Parameters:
330+
repo: GitRepo to a temporary repository.
331+
"""
332+
commit_a = repo.first_hash
333+
commit_b = repo.commit("this commit is untyped and therefore does not have a section!")
334+
repo.tag("1.0.0")
335+
changelog = Changelog(repo.path, convention=AngularConvention)
336+
assert len(changelog.versions_list) == 1
337+
version, = changelog.versions_list
338+
assert len(version.sections_list) == 2
339+
typed_sections = changelog.versions_dict[version.tag].typed_sections
340+
assert len(typed_sections) == 1
341+
untyped = changelog.versions_dict[version.tag].untyped_section
342+
assert untyped is not None
343+
typed, = typed_sections
344+
assert len(untyped.commits) == 1
345+
assert len(typed.commits) == 1
346+
untyped_commit, = untyped.commits
347+
typed_commit, = typed.commits
348+
assert untyped_commit.hash == commit_b
349+
assert typed_commit.hash == commit_a

0 commit comments

Comments
 (0)