Skip to content

Commit 625829b

Browse files
authored
Merge pull request #754 from hasezoey/gitcliff
Add git cliff config for changelog generation
2 parents f36d887 + bfe5ae6 commit 625829b

2 files changed

Lines changed: 127 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Specifically, we use:
5353
- `deps`: A Dependency update. (includes updates necessary for breaking dependency updates)
5454
- `docs`: Documentation update. (ex. for `README`; code should use `style` instead)
5555
- `chore`: Anything that does not touch the code itself and does not fall into any other category like `docs`.
56+
- `test`: Changes that only touch tests (`#[cfg(test)]` blocks).
5657
- `revert`: A Revert commit. (may be excempt from following conventional commits)
5758
- `merge`: A Merge commit. (may be excempt from following conventional commits)
5859
2. For Scope:

cliff.toml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# git-cliff ~ configuration file
2+
# https://git-cliff.org/docs/configuration
3+
4+
[changelog]
5+
# A Tera template to be rendered as the changelog's header.
6+
# See https://keats.github.io/tera/docs/#introduction
7+
header = """
8+
# Changelog\n
9+
All notable changes to this project will be documented in this file.\n
10+
"""
11+
# A Tera template to be rendered for each release in the changelog.
12+
# See https://keats.github.io/tera/docs/#introduction
13+
body = """
14+
{%- macro remote_url() -%}
15+
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
16+
{%- endmacro -%}
17+
{%- macro scoped(commit) -%}
18+
{% if commit.scope -%} *{{ commit.scope | split(pat="::") | first }}*: {% endif %}
19+
{%- endmacro -%}
20+
{%- macro first_message(commit) -%}
21+
{{ commit.message | split(pat="\n") | first | upper_first | trim_end }}
22+
{%- endmacro -%}
23+
{%- macro print_commit(commit) -%}
24+
- {{ self::scoped(commit=commit) }}\
25+
{{ self::first_message(commit=commit) }}\
26+
{% if commit.remote.pr_number %} ([#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }})){% endif %}
27+
{%- endmacro -%}
28+
29+
{% if version %}\
30+
## [{{ version }}]
31+
32+
Released on: {{ timestamp | date(format="%Y-%m-%d") }}
33+
{% else %}\
34+
## [Unreleased]
35+
{% endif %}
36+
{% if commits | filter(attribute="breaking", value=true) | length != 0 %}\
37+
### Breaking Changes
38+
{% for commit in commits| filter(attribute="breaking", value=true) %}
39+
- {{ self::scoped(commit=commit) }}\
40+
{{ self::first_message(commit=commit) }}\
41+
{% if commit.remote.pr_number %} ([#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }})){% endif %}
42+
{% raw %} {% endraw %}- **BREAKING CHANGE**: {{ commit.breaking_description }}
43+
{% endfor -%}
44+
{% endif -%}
45+
46+
{% for group, commits in commits | group_by(attribute="group") %}
47+
### {{ group | striptags | trim | upper_first }}
48+
49+
{% for commit in commits %}
50+
{%- if commit.scope -%}
51+
{% else -%}
52+
{{ self::print_commit(commit=commit) }}
53+
{% endif -%}
54+
{%- endfor -%}
55+
{%- for commit in commits | filter(attribute="scope") | sort(attribute="scope") -%}
56+
{{ self::print_commit(commit=commit) }}
57+
{% endfor -%}
58+
{% endfor %}
59+
### Commit Statistics\n
60+
- {{ statistics.commit_count }} commit(s) contributed to the release.
61+
- {{ statistics.commits_timespan | default(value=0) }} day(s) passed between the first and last commit.
62+
{%- if statistics.days_passed_since_last_release %}
63+
- {{ statistics.days_passed_since_last_release }} day(s) passed between releases.
64+
{%- endif %}
65+
66+
{% if version %}\
67+
[{{ version }}]({{ self::remote_url() }}/compare/{{ previous.version }}..{{ version }})
68+
{% else %}\
69+
[Unreleased]: {{ self::remote_url() }}/compare/{{ previous.version }}..HEAD
70+
{% endif %}\n
71+
"""
72+
# A Tera template to be rendered as the changelog's footer.
73+
# See https://keats.github.io/tera/docs/#introduction
74+
footer = """
75+
<!-- generated by git-cliff -->
76+
"""
77+
# Remove leading and trailing whitespaces from the changelog's body.
78+
trim = true
79+
80+
[git]
81+
# Parse commits according to the conventional commits specification.
82+
# See https://www.conventionalcommits.org
83+
conventional_commits = true
84+
# Exclude commits that do not match the conventional commits specification.
85+
filter_unconventional = false
86+
commit_preprocessors = [
87+
# Remove the "(#XXX)" that gets added in the default squash merge message in the github web interface
88+
{ pattern = '\(#\d+\)', replace = "" }
89+
]
90+
# An array of regex based parsers for extracting data from the commit message.
91+
# Assigns commits to groups.
92+
# Optionally sets the commit's scope and can decide to exclude commits from further processing.
93+
# HTML comments are used for group order, as groups are sorted alphabetically.
94+
commit_parsers = [
95+
{ message = "^feat", group = "<!-- 1 -->Features" },
96+
{ message = "^fix", group = "<!-- 2 -->Bug Fixes" },
97+
{ message = "^docs", group = "<!-- 7 -->Documentation" },
98+
{ message = "^perf", group = "<!-- 3 -->Performance" },
99+
{ message = "^refactor", group = "<!-- 5 -->Refactor" },
100+
# Style changes dont need to be mentioned
101+
{ message = "^style", group = "Styling", skip = true },
102+
{ message = "^test", group = "<!-- 6 -->Testing" },
103+
# Release commits dont add anything noteworthy to add to a changelog
104+
{ message = "^chore\\(release\\): prepare for", skip = true },
105+
{ message = "^chore", group = "<!-- 5 -->Miscellaneous Tasks" },
106+
# Merge commits themself dont add anything noteworthy
107+
{ message = "^[mM]erge", skip = true },
108+
{ message = "^[rR]evert", group = "<!-- 8 -->Revert" },
109+
{ message = "^deps", group = "<!-- 4 -->Dependencies" },
110+
{ body = ".*security", group = "<!-- 0 -->Security" },
111+
{ body = ".*", group = "<!-- 99 -->Other (unconventional)" },
112+
]
113+
# Any commit that contains "BREAKING CHANGE" will be protected from being filtered out.
114+
protect_breaking_commits = true
115+
# Exclude commits that are not matched by any commit parser.
116+
filter_commits = false
117+
# Order releases topologically instead of chronologically.
118+
topo_order = false
119+
# Order of commits in each group/release within the changelog.
120+
# Allowed values: newest, oldest
121+
sort_commits = "oldest"
122+
123+
[bump]
124+
# If this would be "true", it would immediately push us to "1.0.0" instead
125+
# of continuing to use "0." based versions.
126+
breaking_always_bump_major = false

0 commit comments

Comments
 (0)