Skip to content

Commit ad039d5

Browse files
authored
feat(config): add changelog.render_always option (#859)
* feat(config): add changelog.always_render option * chore(fixtures): fix typo in arguments * chore(fixture): update expected output * chore: fix edge cases * fix: add missing field * refactor: rename always_render to render_always
1 parent 470ff53 commit ad039d5

File tree

13 files changed

+130
-3
lines changed

13 files changed

+130
-3
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[changelog]
2+
# template for the changelog footer
3+
header = """
4+
# Changelog\n
5+
All notable changes to this project will be documented in this file.\n
6+
"""
7+
# template for the changelog body
8+
# https://keats.github.io/tera/docs/#introduction
9+
body = """
10+
{% if version %}
11+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
12+
{% else %}
13+
## [unreleased]
14+
{% endif %}
15+
16+
{% if commits | length == 0 -%}
17+
No significant changes.
18+
19+
{% else -%}
20+
{% for group, commits in commits | group_by(attribute="group") -%}
21+
### {{ group | upper_first }}
22+
etc.
23+
{% endfor %}
24+
{%- endif %}
25+
"""
26+
# template for the changelog footer
27+
footer = """
28+
<!-- generated by git-cliff -->
29+
"""
30+
# remove the leading and trailing whitespace from the templates
31+
trim = true
32+
# render body even when there are no releases to process
33+
render_always = true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
GIT_COMMITTER_DATE="2022-04-06 01:25:08" git commit --allow-empty -m "Initial commit"
5+
GIT_COMMITTER_DATE="2022-04-06 01:25:09" git commit --allow-empty -m "feat: add feature 1"
6+
GIT_COMMITTER_DATE="2022-04-06 01:25:10" git commit --allow-empty -m "fix: fix feature 1"
7+
git tag v0.1.0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
6+
## [unreleased]
7+
8+
9+
No significant changes.
10+
11+
<!-- generated by git-cliff -->
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[changelog]
2+
# template for the changelog footer
3+
header = """
4+
# Changelog\n
5+
All notable changes to this project will be documented in this file.\n
6+
"""
7+
# template for the changelog body
8+
# https://keats.github.io/tera/docs/#introduction
9+
body = """
10+
{% if version %}
11+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
12+
{% else %}
13+
## [unreleased]
14+
{% endif %}
15+
16+
{% if commits | length == 0 -%}
17+
No significant changes.
18+
19+
{% else -%}
20+
{% for group, commits in commits | group_by(attribute="group") -%}
21+
### {{ group | upper_first }}
22+
etc.
23+
{% endfor %}
24+
{%- endif %}
25+
"""
26+
# template for the changelog footer
27+
footer = """
28+
<!-- generated by git-cliff -->
29+
"""
30+
# remove the leading and trailing whitespace from the templates
31+
trim = true
32+
# render body even when there are no releases to process
33+
render_always = true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
GIT_COMMITTER_DATE="2022-04-06 01:25:08" git commit --allow-empty -m "Initial commit"
5+
GIT_COMMITTER_DATE="2022-04-06 01:25:09" git commit --allow-empty -m "feat: add feature 1"
6+
GIT_COMMITTER_DATE="2022-04-06 01:25:10" git commit --allow-empty -m "fix: fix feature 1"
7+
git tag v0.1.0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
6+
## [0.2.0] - 2024-09-21
7+
8+
9+
No significant changes.
10+
11+
<!-- generated by git-cliff -->

.github/workflows/test-fixtures.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ jobs:
9393
command: --bump --unreleased --with-tag-message "Some text"
9494
- fixtures-name: test-from-context
9595
command: --from-context context.json
96+
- fixtures-name: test-always-render-unreleased
97+
command: --unreleased
98+
- fixtures-name: test-always-render
99+
command: --unreleased --tag v0.2.0
96100
- fixtures-name: test-unchanged-tag-date
97101
command: --tag v0.2.0
98102

config/cliff.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ trim = true
3838
postprocessors = [
3939
# { pattern = '<REPO>', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL
4040
]
41+
# render body even when there are no releases to process
42+
# render_always = true
4143
# output file path
4244
# output = "test.md"
4345

git-cliff-core/src/changelog.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<'a> Changelog<'a> {
148148

149149
/// Processes the releases and filters them out based on the configuration.
150150
fn process_releases(&mut self) {
151-
debug!("Processing the releases...");
151+
debug!("Processing {} release(s)...", self.releases.len());
152152
let skip_regex = self.config.git.skip_tags.as_ref();
153153
let mut skipped_tags = Vec::new();
154154
self.releases = self
@@ -161,7 +161,12 @@ impl<'a> Changelog<'a> {
161161
if let Some(version) = release.version.clone() {
162162
trace!("Release doesn't have any commits: {}", version);
163163
}
164-
false
164+
match &release.previous {
165+
Some(prev_release) if prev_release.commits.is_empty() => {
166+
self.config.changelog.render_always.unwrap_or(false)
167+
}
168+
_ => false,
169+
}
165170
} else if let Some(version) = &release.version {
166171
!skip_regex.is_some_and(|r| {
167172
let skip_tag = r.is_match(version);
@@ -670,6 +675,7 @@ mod test {
670675
replace: Some(String::from("exciting")),
671676
replace_command: None,
672677
}]),
678+
render_always: None,
673679
output: None,
674680
},
675681
git: GitConfig {

git-cliff-core/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ pub struct ChangelogConfig {
7777
pub footer: Option<String>,
7878
/// Trim the template.
7979
pub trim: Option<bool>,
80+
/// Always render the body template.
81+
pub render_always: Option<bool>,
8082
/// Changelog postprocessors.
8183
pub postprocessors: Option<Vec<TextProcessor>>,
8284
/// Output file path.

0 commit comments

Comments
 (0)