Skip to content

Commit

Permalink
fix: Restore "untyped section" feature
Browse files Browse the repository at this point in the history
In versions prior to 2.4.1, Jinja templates could optionally generate change lines by accessing the `""` section (e.g. `untyped_section`). This allowed for capturing of commit messages that would otherwise be lost.

Upon version 2.4.1, that was broken and `untyped_section` became always empty.

This change restores the functionality.

Issue-88: #88
PR-89: #89
Co-authored-by: Autumn Jolitz <autumn@aible.com>
  • Loading branch information
autumnjolitz and autumnjolitz authored Jun 30, 2024
1 parent b9bad9c commit fe041fa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
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

0 comments on commit fe041fa

Please sign in to comment.