diff --git a/src/git_changelog/build.py b/src/git_changelog/build.py index f2b522a..5794b2d 100644 --- a/src/git_changelog/build.py +++ b/src/git_changelog/build.py @@ -159,12 +159,12 @@ def add_commit(self, commit: Commit) -> None: """ self.commits.append(commit) commit.version = self.tag or "HEAD" - if commit_type := commit.convention.get("type"): - if commit_type not in self.sections_dict: - section = Section(section_type=commit_type) - self.sections_list.append(section) - self.sections_dict[commit_type] = section - self.sections_dict[commit_type].commits.append(commit) + commit_type = commit.convention.get("type") + if commit_type not in self.sections_dict: + section = Section(section_type=commit_type) + self.sections_list.append(section) + self.sections_dict[commit_type] = section + self.sections_dict[commit_type].commits.append(commit) class Changelog: diff --git a/tests/test_build.py b/tests/test_build.py index a07f6d6..aa20552 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -321,3 +321,29 @@ def test_ignore_nonsemver_tag(repo: GitRepo) -> None: expected_prev_tag=None, expected_commits=[commit_c, commit_b, commit_a], ) + + +def test_untyped_commits(repo: GitRepo) -> None: + """Test capture of untyped (i.e. uncategorizable) commits. + + Parameters: + repo: GitRepo to a temporary repository. + """ + commit_a = repo.first_hash + commit_b = repo.commit("this commit is untyped and therefore does not have a section!") + repo.tag("1.0.0") + changelog = Changelog(repo.path, convention=AngularConvention) + assert len(changelog.versions_list) == 1 + version, = changelog.versions_list + assert len(version.sections_list) == 2 + typed_sections = changelog.versions_dict[version.tag].typed_sections + assert len(typed_sections) == 1 + untyped = changelog.versions_dict[version.tag].untyped_section + assert untyped is not None + typed, = typed_sections + assert len(untyped.commits) == 1 + assert len(typed.commits) == 1 + untyped_commit, = untyped.commits + typed_commit, = typed.commits + assert untyped_commit.hash == commit_b + assert typed_commit.hash == commit_a