From 27896eb05d19fb85ab049f7cbc374c0cd9b51d0a Mon Sep 17 00:00:00 2001 From: Christopher Klinge Date: Wed, 12 Mar 2025 22:33:51 +0100 Subject: [PATCH] refactor: default to embeded config --- config/cliff.toml | 8 +++ git-cliff-core/src/changelog.rs | 88 +++++++++++------------- git-cliff-core/src/commit.rs | 33 ++++----- git-cliff-core/src/config.rs | 39 ++++++----- git-cliff-core/tests/integration_test.rs | 42 +++++------ git-cliff/src/lib.rs | 56 ++++++--------- 6 files changed, 128 insertions(+), 138 deletions(-) diff --git a/config/cliff.toml b/config/cliff.toml index bc311f270c..b95f080102 100644 --- a/config/cliff.toml +++ b/config/cliff.toml @@ -33,6 +33,8 @@ footer = """ """ # Remove leading and trailing whitespaces from the changelog's body. trim = true +# Render body even when there are no releases to process. +render_always = true # An array of regex based postprocessors to modify the changelog. postprocessors = [ # Replace the placeholder with a URL. @@ -62,6 +64,8 @@ commit_preprocessors = [ # If the spelling is incorrect, it will be fixed automatically. #{ pattern = '.*', replace_command = 'typos --write-changes -' }, ] +# Prevent commits that are breaking from being excluded by commit parsers. +protect_breaking_commits = false # An array of regex based parsers for extracting data from the commit message. # Assigns commits to groups. # Optionally sets the commit's scope and can decide to exclude commits from further processing. @@ -84,6 +88,10 @@ commit_parsers = [ ] # Exclude commits that are not matched by any commit parser. filter_commits = false +# An array of link parsers for extracting external references, and turning them into URLs, using regex. +link_parsers = [] +# Include only the tags that belong to the current branch. +use_branch_tags = false # Order releases topologically instead of chronologically. topo_order = false # Order of commits in each group/release within the changelog. diff --git a/git-cliff-core/src/changelog.rs b/git-cliff-core/src/changelog.rs index bdae154db0..6bfb90120c 100644 --- a/git-cliff-core/src/changelog.rs +++ b/git-cliff-core/src/changelog.rs @@ -54,7 +54,7 @@ impl<'a> Changelog<'a> { /// Builds a changelog from releases and config. fn build(releases: Vec>, config: &'a Config) -> Result { - let trim = config.changelog.trim.unwrap_or(true); + let trim = config.changelog.trim; Ok(Self { releases, header_template: match &config.changelog.header { @@ -127,7 +127,7 @@ impl<'a> Changelog<'a> { .cloned() .filter_map(|commit| Self::process_commit(&commit, &self.config.git)) .flat_map(|commit| { - if self.config.git.split_commits.unwrap_or(false) { + if self.config.git.split_commits { commit .message .lines() @@ -148,7 +148,7 @@ impl<'a> Changelog<'a> { .collect::>(); }); - if self.config.git.require_conventional.unwrap_or(false) { + if self.config.git.require_conventional { self.check_conventional_commits()?; } @@ -203,7 +203,7 @@ impl<'a> Changelog<'a> { } match &release.previous { Some(prev_release) if prev_release.commits.is_empty() => { - self.config.changelog.render_always.unwrap_or(false) + self.config.changelog.render_always } _ => false, } @@ -561,12 +561,7 @@ impl<'a> Changelog<'a> { /// Generates the changelog and writes it to the given output. pub fn generate(&self, out: &mut W) -> Result<()> { debug!("Generating changelog..."); - let postprocessors = self - .config - .changelog - .postprocessors - .clone() - .unwrap_or_default(); + let postprocessors = self.config.changelog.postprocessors.clone(); if let Some(header_template) = &self.header_template { let write_result = writeln!( @@ -653,13 +648,7 @@ impl<'a> Changelog<'a> { } fn get_body_template(config: &Config, trim: bool) -> Result