Skip to content

Signed commit in changelog #2114

Open
Open

Description

@eamanu

Description

Hi,

I started to use commitizen so I'm really newbie. I'd like to have in changelog each line with the @user if the commit is signed, something like:

v0.1.0 (date)

...

  • fix: this a fix @user1
  • feat: this a feat @user2
  • fix: this a non signed commit

Not sure if it already exists, but I didn't found it, sorry in advance :-)

Cheers

Activity

  1. woile commented on Oct 22, 2026

    @woile
    Member

    Hi there, it's not impossible, but it's not easy.

    First thing, commitizen builds the changelog with the information stored in git, so it doesn't know about GitHub users.

    You would have to build a specialized GitHub-aware custom commiter, and publish it to pypi. In there you could make an API to Github call to get the user on each commit (even implement your own rules, like only show the user if it's a new feature). I haven't found an api call to get a range of commit, but if it's there, you could also do that. Commitizen class has support for a few different types of hooks for the changelog

    Example:

    curl -Ls https://api.github.com/repos/commitizen-tools/commitizen/commits/2ebac02c7ab70e883f856c1943bfdda8fe5da40a \
        | jq .committer.login
    

    (If it's a private repo, you might need a github token, which wouldn't be a problem if you are running commitizen in your CI).

    Something like this:

    import json
    from commitizen.cz.conventional_commits import ConventionalCommitsCz
    import urllib.request
    from string import Template
    
    GITHUB_API = "https://api.github.com/repos/$OWNER/$REPO/commits/$REF"
    GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN", None)
    GITHUB_REPOSITORY = os.environ.get('GITHUB_REPOSITORY', None)
    
    headers = {}
    if GITHUB_TOKEN:
        headers = {
            "Authorization": f"Bearer {GITHUB_TOKEN}",
            "Accept": "application/vnd.github+json",
            "User-Agent": "Python-urllib"  # GitHub APIs require a user-agent header
        }
    owner = None
    repo_name = None
    if GITHUB_REPOSITORY:
        # Split the string at the slash
        owner, repo_name = github_repository.split('/')
    
    class ConventionalGithub(ConventionalCommitsCz):
        def changelog_message_builder_hook(
                self, message: dict[str, Any], commit: git.GitCommit
            ) -> dict[str, Any]:
            if not owner:
                # If there's no owner, nothing to be done, we are not in a gh action
                return message
            url = t.safe_substitute(OWNER=owner,REPO=repo_name,REF=commit.rev)
            req = urllib.request.Request(url, headers=headers)
            with urllib.request.urlopen(req) as response:
                data = json.loads(response.read().decode('utf-8'))
                user = data["committer"]["login"]
                msg = message["message"]
                message["message"] = f"{msg} (@{user})"
            return message

    We have a very basic template to get started:
    https://github.com/commitizen-tools/commitizen_cz_template

  2. eamanu commented on Oct 22, 2026

    @eamanu
    Author

    Hi!,

    thanks for the quick reply. Actually, and it's my fault for don't being clear, I'd like to have the user (mail and/or email) from the Signed-off-by of commit, to don't depend in the git provider

  3. woile commented on Oct 22, 2026

    @woile
    Member

    That should make it easier then, because the git.GitCommit where we get the ref also contains the author and author_email:
    https://github.com/commitizen-tools/commitizen/blob/master/commitizen/git.py#L73-L74

  4. eamanu commented on Oct 22, 2026

    @eamanu
    Author

    I push #2115 to show what's my idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions