mirror of
https://github.com/orhun/git-cliff.git
synced 2024-12-01 21:05:17 +03:00
feat(config): add trim option to changelog
This commit is contained in:
parent
c67370e5a7
commit
2d0d89cb7a
16
cliff.toml
16
cliff.toml
@ -10,21 +10,23 @@ All notable changes to this project will be documented in this file.\n
|
||||
# https://tera.netlify.app/docs/#introduction
|
||||
body = """
|
||||
{% if version %}\
|
||||
## [{{ version | replace(from="v", to="") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
|
||||
## [{{ version | replace(from="v", to="") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
|
||||
{% else %}\
|
||||
## [unreleased]
|
||||
## [unreleased]
|
||||
{% endif %}\
|
||||
{% for group, commits in commits | group_by(attribute="group") %}
|
||||
### {{ group | upper_first }}
|
||||
{% for commit in commits %}
|
||||
- {{ commit.message | upper_first }}\
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
### {{ group | upper_first }}
|
||||
{% for commit in commits %}
|
||||
- {{ commit.message | upper_first }}\
|
||||
{% endfor %}
|
||||
{% endfor %}\n
|
||||
"""
|
||||
# changelog footer
|
||||
footer = """
|
||||
<!-- generated by git-cliff -->\n
|
||||
"""
|
||||
# remove the leading and trailing whitespaces from the template
|
||||
trim = true
|
||||
|
||||
[git]
|
||||
# allow only conventional commits
|
||||
|
@ -19,6 +19,8 @@ pub struct ChangelogConfig {
|
||||
pub body: String,
|
||||
/// Changelog footer.
|
||||
pub footer: Option<String>,
|
||||
/// Trim the template.
|
||||
pub trim: Option<bool>,
|
||||
}
|
||||
|
||||
/// Git configuration
|
||||
|
@ -25,6 +25,7 @@ fn generate_changelog() -> Result<()> {
|
||||
{% endfor %}"#,
|
||||
),
|
||||
footer: Some(String::from("eoc - end of changelog")),
|
||||
trim: None,
|
||||
};
|
||||
let git_config = GitConfig {
|
||||
conventional_commits: true,
|
||||
|
@ -18,7 +18,17 @@ impl<'a> Changelog<'a> {
|
||||
pub fn new(releases: Vec<Release<'a>>, config: &'a Config) -> Result<Self> {
|
||||
let mut changelog = Self {
|
||||
releases,
|
||||
template: Template::new(config.changelog.body.to_string())?,
|
||||
template: Template::new({
|
||||
let mut template = config.changelog.body.to_string();
|
||||
if config.changelog.trim == Some(true) {
|
||||
template = template
|
||||
.lines()
|
||||
.map(|v| v.trim())
|
||||
.collect::<Vec<&str>>()
|
||||
.join("\n")
|
||||
}
|
||||
template
|
||||
})?,
|
||||
config,
|
||||
};
|
||||
changelog.process_commits();
|
||||
@ -142,9 +152,9 @@ mod test {
|
||||
#### {{ group }}{% for commit in commits %}
|
||||
- {{ commit.message }}{% endfor %}
|
||||
{% endfor %}{% endfor %}"#,
|
||||
)
|
||||
.replace(" ", ""),
|
||||
),
|
||||
footer: Some(String::from("------------")),
|
||||
trim: Some(true),
|
||||
},
|
||||
git: GitConfig {
|
||||
conventional_commits: true,
|
||||
@ -239,7 +249,6 @@ mod test {
|
||||
assert_eq!(
|
||||
String::from(
|
||||
r#"# Changelog
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Bug Fixes
|
||||
@ -274,8 +283,7 @@ mod test {
|
||||
|
||||
#### ui
|
||||
- make good stuff
|
||||
------------
|
||||
"#
|
||||
------------"#
|
||||
)
|
||||
.replace(" ", ""),
|
||||
str::from_utf8(&out).unwrap()
|
||||
|
Loading…
Reference in New Issue
Block a user