Skip to content

Commit

Permalink
feat(changelog): expose commits sha1, author and author_email i…
Browse files Browse the repository at this point in the history
…n changelog tree (fix #987) (#1013)
  • Loading branch information
noirbizarre committed Mar 19, 2024
1 parent c8a9008 commit bbae8e0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
7 changes: 6 additions & 1 deletion commitizen/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@ def process_commit_message(
changes: dict[str | None, list],
change_type_map: dict[str, str] | None = None,
):
message: dict = parsed.groupdict()
message: dict = {
"sha1": commit.rev,
"author": commit.author,
"author_email": commit.author_email,
**parsed.groupdict(),
}

if processed := hook(message, commit) if hook else message:
messages = [processed] if isinstance(processed, dict) else processed
Expand Down
3 changes: 3 additions & 0 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ Each `Change` has the following fields:
| ---- | ---- | ----------- |
| scope | `str | None` | An optional scope |
| message | `str` | The commit message body |
| sha1 | `str` | The commit `sha1` |
| author | `str` | The commit author name |
| author_email | `str` | The commit author email |

!!! Note
The field values depend on the customization class and/or the settings you provide
Expand Down
22 changes: 18 additions & 4 deletions tests/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,10 +1084,24 @@ def test_generate_tree_from_commits(gitcommits, tags, merge_prereleases):
tree = changelog.generate_tree_from_commits(
gitcommits, tags, parser, changelog_pattern, merge_prerelease=merge_prereleases
)
if merge_prereleases:
assert tuple(tree) == COMMITS_TREE_AFTER_MERGED_PRERELEASES
else:
assert tuple(tree) == COMMITS_TREE
expected = (
COMMITS_TREE_AFTER_MERGED_PRERELEASES if merge_prereleases else COMMITS_TREE
)

for release, expected_release in zip(tree, expected):
assert release["version"] == expected_release["version"]
assert release["date"] == expected_release["date"]
assert release["changes"].keys() == expected_release["changes"].keys()
for change_type in release["changes"]:
changes = release["changes"][change_type]
expected_changes = expected_release["changes"][change_type]
for change, expected_change in zip(changes, expected_changes):
assert change["scope"] == expected_change["scope"]
assert change["breaking"] == expected_change["breaking"]
assert change["message"] == expected_change["message"]
assert change["author"] == "Commitizen"
assert change["author_email"] in "author@cz.dev"
assert "sha1" in change


def test_generate_tree_from_commits_with_no_commits(tags):
Expand Down

0 comments on commit bbae8e0

Please sign in to comment.