diff --git a/.github/fixtures/test-header-template/cliff.toml b/.github/fixtures/test-header-template/cliff.toml new file mode 100644 index 0000000000..8f6dbd7849 --- /dev/null +++ b/.github/fixtures/test-header-template/cliff.toml @@ -0,0 +1,31 @@ +[changelog] +# changelog header +header = """ +# Changelog +{% for release in releases %}\ + {% if release.version %}\ + {% if release.previous.version %}\ + + {% endif %}\ + {% else %}\ + + {% endif %}\ +{% endfor %}\ +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{% if version %}\ + ## [{{ version | trim_start_matches(pat="v") }}] +{% else %}\ + ## [unreleased] +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# remove the leading and trailing whitespace from the templates +trim = true diff --git a/.github/fixtures/test-header-template/commit.sh b/.github/fixtures/test-header-template/commit.sh new file mode 100644 index 0000000000..ed35b19af4 --- /dev/null +++ b/.github/fixtures/test-header-template/commit.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -e + +GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: add feature 1" +GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: add feature 2" +git tag v0.1.0 + +GIT_COMMITTER_DATE="2021-01-23 01:23:46" git commit --allow-empty -m "fix: fix feature 1" +GIT_COMMITTER_DATE="2021-01-23 01:23:46" git commit --allow-empty -m "fix: fix feature 2" +git tag v0.2.0 + +GIT_COMMITTER_DATE="2021-01-23 01:23:47" git commit --allow-empty -m "feat: add footer" +git tag v3.0.0 + +GIT_COMMITTER_DATE="2021-01-23 01:23:47" git commit --allow-empty -m "test: footer" +GIT_COMMITTER_DATE="2021-01-23 01:23:47" git commit --allow-empty -m "perf: footer" diff --git a/.github/fixtures/test-header-template/expected.md b/.github/fixtures/test-header-template/expected.md new file mode 100644 index 0000000000..f9b52bfa64 --- /dev/null +++ b/.github/fixtures/test-header-template/expected.md @@ -0,0 +1,33 @@ +# Changelog + + + +## [unreleased] + +### Perf + +- Footer + +### Test + +- Footer + +## [3.0.0] + +### Feat + +- Add footer + +## [0.2.0] + +### Fix + +- Fix feature 1 +- Fix feature 2 + +## [0.1.0] + +### Feat + +- Add feature 1 +- Add feature 2 diff --git a/git-cliff-core/src/changelog.rs b/git-cliff-core/src/changelog.rs index 7707f37596..4e751dc6c9 100644 --- a/git-cliff-core/src/changelog.rs +++ b/git-cliff-core/src/changelog.rs @@ -29,6 +29,7 @@ use std::time::{ pub struct Changelog<'a> { /// Releases that the changelog will contain. pub releases: Vec>, + header_template: Option