DEV Community

Ramu Narasinga
Ramu Narasinga

Posted on

git-cliff, a changelog generator.

In this article, we review git-cliff. You will learn:

  1. What is git-cliff?

  2. git-cliff usage in Nango

What is git-cliff?

git-cliff is a highly customizable Changelog Generator that follows Conventional Commit specifications.

High customizable

git-cliff uses regex-powered custom parsers and the changelog can be customized easily with a configuration file to match the desired format.

Conventional Commits

git-cliff can generate changelog files for any Git repository that follows the conventional commits specification.

Easy Integration

git-cliff can be easily integrated with your Rust/Python/Node.js project as a command-line tool and also can be used as a library for Rust projects.

Quick start

  1. Install git-cliff
cargo install git-cliff
Enter fullscreen mode Exit fullscreen mode
  1. Initialise git-cliff:
git-cliff --init
Enter fullscreen mode Exit fullscreen mode

Edit the default Configuration. (cliff.toml) as you like. Check out the

example. for different templates.

  1. Generate a changelog
git-cliff -o CHANGELOG.md
Enter fullscreen mode Exit fullscreen mode

git-cliff usage in Nango

I found the cliff.toml file in Nango codebase. It is defined as shown below.

# git-cliff ~ configuration file
# https://git-cliff.org/docs/configuration

[changelog]
# changelog header
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
"""
# template for the changelog body
# https://keats.github.io/tera/docs/#introduction
body = """
{% if version -%}
    ## [{{ version }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else -%}
    ## [Unreleased]
{% endif -%}
{% for group, commits in commits | group_by(attribute="group") %}
    ### {{ group | upper_first }}
    {% for commit in commits %}
        - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
           {{ commit.message | upper_first }}\
           {% if commit.github.username %} by @{{ commit.github.username }}{%- endif -%}
    {% endfor %}
{% endfor %}\n
"""
# template for the changelog footer
footer = """
{% for release in releases -%}
    {% if release.version -%}
        {% if release.previous.version -%}
            [{{ release.version }}]: \
                https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}\
                    /compare/{{ release.previous.version }}..{{ release.version }}
        {% endif -%}
    {% else -%}
        [unreleased]: https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}\
            /compare/{{ release.previous.version }}..HEAD
    {% endif -%}
{% endfor %}
<!-- generated by git-cliff -->
"""
# remove the leading and trailing whitespace from the templates
trim = true

[git]
# parse the commits based on https://www.conventionalcommits.org
conventional_commits = true
# filter out the commits that are not conventional
filter_unconventional = true
# process each line of a commit as an individual commit
split_commits = false
# regex for parsing and grouping commits
commit_parsers = [
  { message = "^feat", group = "Added" },
  { message = "^.*: add", group = "Added" },
  { message = "^test", group = "Fixed" },
  { message = "^fix", group = "Fixed" },
  { message = "^.*: fix", group = "Fixed" },
  { message = "^chore.release.", skip = true },
  { message = "^.*", group = "Changed" },
]
# protect breaking changes from being skipped due to matching a skipping commit_parser
protect_breaking_commits = false
# filter out the commits that are not matched by commit parsers
filter_commits = true
# regex for matching git tags
tag_pattern = "v[0-9].*"
# regex for skipping tags
skip_tags = ""
# regex for ignoring tags
ignore_tags = ""
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "oldest"
Enter fullscreen mode Exit fullscreen mode

You can find the generated Nango's changelog at CHANGELOG.md.

About me:

Hey, my name is ramunarasinga. Email: ramunarasinga@gmail.com

Tired of AI slop?

I spent 3+ years studying OSS codebases and wrote 350+ articles on what makes them production-grade. I built

Get started for free — thinkthroo.com

References:

  1. git-cliff.org/.

  2. git-cliff.org/docs/.

  3. nango/cliff.toml.

  4. nango/CHANGELOG.md

Top comments (0)