Conventional Commits and git-cliff: a plugin changelog from the commit history
The changelog in readme.txt is written at release time, from memory, and it shows: fixes are forgotten, internal refactorings are listed as features. If the commit messages follow a simple convention, a tool can sort them into “Features”, “Fixes” and “Breaking changes” and write the changelog section. Conventional Commits is that convention, git-cliff is a fast generator for it.
Problem: A plugin’s changelog in readme.txt is incomplete. Before every release, someone reads 60 commit messages like “fix”, “wip” and “update” and guesses what changed for users.
Solution: Write commit messages as type(scope): description (feat, fix, perf, a ! or BREAKING CHANGE: footer for breaking changes), check the format in a commit-msg hook, generate the changelog for a release with git cliff from the last tag, and paste it into readme.txt.
The format
feat(checkout): add VAT number field to the checkout block fix(settings): escape the API label on the settings page perf(sync): batch product updates in groups of 100 refactor: move the API client to its own class docs: document the ha_sync_batch_size filter feat(api)!: remove the deprecated v1 REST routes BREAKING CHANGE: the routes under ha/v1 were removed, use ha/v2.
The type says what kind of change it is, the optional scope names the part of the plugin, and the description is written for the changelog reader. ! after the type or a BREAKING CHANGE: footer marks a change that requires action from users, which in semantic versioning means a new major version.
Enforce it with a hook
#!/usr/bin/env bash
# .githooks/commit-msg
pattern='^(feat|fix|perf|refactor|docs|test|build|ci|chore|revert)(\([a-z0-9-]+\))?!?: .{3,}'
if ! head -n 1 "$1" | grep -qE "$pattern"; then
echo "Commit message must look like: fix(settings): escape the API label" >&2
exit 1
fi
chmod +x .githooks/commit-msg git config core.hooksPath .githooks
core.hooksPath points git to a folder in the repository, so the hook is versioned and every developer gets it with one config command. In CI, the same check can run on the commits of a pull request.
git-cliff configuration
# cliff.toml
[changelog]
body = """
{% for group, commits in commits | group_by(attribute="group") %}
* {{ group }}
{% for commit in commits %} * {{ commit.message | upper_first }}{% if commit.breaking %} (breaking){% endif %}
{% endfor %}{% endfor %}
"""
trim = true
[git]
conventional_commits = true
filter_unconventional = true
commit_parsers = [
{ message = "^feat", group = "New" },
{ message = "^fix", group = "Fixed" },
{ message = "^perf", group = "Faster" },
{ message = "^(refactor|docs|test|build|ci|chore)", skip = true },
]
tag_pattern = "v[0-9].*"
Internal types are skipped: users do not need to read about refactorings. The template produces the asterisk list that readme.txt uses.
Generate for a release
git cliff --unreleased --strip all # changes since the last tag git cliff v2.4.0..HEAD --strip all # explicit range git cliff --bump --unreleased # also suggests the next version from the commit types
= 2.5.0 = * New * Add VAT number field to the checkout block * Fixed * Escape the API label on the settings page
Paste the output under a new = 2.5.0 = heading in readme.txt, then tag the release: git tags and signed releases. git-cliff is a single binary (packages for Homebrew, Cargo, npm via git-cliff, and a GitHub Action).
NOTE: The tool only reorganizes what the commits say. A commit “fix: stuff” produces a changelog line “Stuff”. The convention works when the description is written for users; squash-merging pull requests with a well-written title is an easy way to get one good message per change. Cleaning up local commits before pushing: interactive rebase.