commitizen icon indicating copy to clipboard operation
commitizen copied to clipboard

Add commit hash and issue number to the changelog format as optional variables

Open nongrata081 opened this issue 1 year ago • 3 comments

Description

It would be nice to get for each commit in the generated changelog as as optional variables:

See an example that was generated with conventional-changelog-cli (node.js). See npm script that generates the changelog.

The justification is that having short commit hash and issue number as clickable links in repo gives a possibility to quickly access the related code and issues/threads in github, thus having full context of the item / entity worked on, without having to search for it by hand, that would take much more time.

changelog-example

Possible Solution

add linked commit hash and issue number as optional variables to each commit to changelog format

Additional context

No response

Additional context

No response

nongrata081 avatar Sep 07 '24 11:09 nongrata081

As a workaround, I built a plugin that tries to do what is mentioned. It will be great to have this implemented natively!

kmnhan avatar Oct 08 '24 05:10 kmnhan

Wanna add it to the third party section in the docs? https://commitizen-tools.github.io/commitizen/third-party-commitizen/

woile avatar Oct 08 '24 05:10 woile

@nongrata081 I got this working by modifying the template as follows:

{% for entry in tree %}

## {{ entry.version }}{% if entry.date %} ({{ entry.date }}){% endif %}

{% for change_key, changes in entry.changes.items() %}

{% if change_key %}
### {{ change_key }}
{% endif %}

{% for change in changes %}
{% if change.scope %}
- **{{ change.scope }}**: {{ change.message }} ({{ change.sha1[:7] }})
{% elif change.message %}
- {{ change.message }} ({{ change.sha1[:7] }})
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}

Adding ({{ change.sha1[:7] }}) includes the commit hash behind the change-message. Changelog is updated with cz ch --template _templates/CHANGELOG.md.j2. When pushing the CHANGELOG.md to GitHub/GitLab, the hash is automatically linked to the respective commit; same is ensured when referencing issue numbers or even contributors in the change messages.

kapsner avatar Jun 02 '25 08:06 kapsner