Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: restore commits for untyped section #89

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/git_changelog/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading