From bbae8e0880f0aa6359e2781a54e0bb56248c3049 Mon Sep 17 00:00:00 2001 From: Axel H Date: Tue, 19 Mar 2024 11:49:41 +0100 Subject: [PATCH 1/2] feat(changelog): expose commits `sha1`, `author` and `author_email` in changelog tree (fix #987) (#1013) --- commitizen/changelog.py | 7 ++++++- docs/customization.md | 3 +++ tests/test_changelog.py | 22 ++++++++++++++++++---- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/commitizen/changelog.py b/commitizen/changelog.py index 7caa64c640..12d52f7b08 100644 --- a/commitizen/changelog.py +++ b/commitizen/changelog.py @@ -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 diff --git a/docs/customization.md b/docs/customization.md index 24f749a1eb..1fd1826e03 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -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 diff --git a/tests/test_changelog.py b/tests/test_changelog.py index 831e013e3c..9ccc207936 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -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): From 91753282436eda42fe95b73eee0c2931b1858f43 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 19 Mar 2024 10:50:09 +0000 Subject: [PATCH 2/2] =?UTF-8?q?bump:=20version=203.19.0=20=E2=86=92=203.20?= =?UTF-8?q?.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 6 ++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6adebbedd0..fb3881cc7a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,7 +46,7 @@ repos: exclude: "poetry.lock" - repo: https://github.com/commitizen-tools/commitizen - rev: v3.19.0 # automatically updated by Commitizen + rev: v3.20.0 # automatically updated by Commitizen hooks: - id: commitizen - id: commitizen-branch diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e90176111..38f588354c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v3.20.0 (2024-03-19) + +### Feat + +- **changelog**: expose commits `sha1`, `author` and `author_email` in changelog tree (fix #987) (#1013) + ## v3.19.0 (2024-03-19) ### Feat diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 0e6cf3e2e7..10c5c0dd1b 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "3.19.0" +__version__ = "3.20.0" diff --git a/pyproject.toml b/pyproject.toml index 4ac781df3f..30d548890a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "3.19.0" +version = "3.20.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -9,7 +9,7 @@ version_files = [ [tool.poetry] name = "commitizen" -version = "3.19.0" +version = "3.20.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT"