diff --git a/git-cliff-core/src/process.rs b/git-cliff-core/src/process.rs index 74b6ef1aa7..1afc18b087 100644 --- a/git-cliff-core/src/process.rs +++ b/git-cliff-core/src/process.rs @@ -259,6 +259,8 @@ impl<'cfg, 'sum> CommitProcessor<'cfg, 'sum> { #[cfg(test)] mod test { + use std::str::FromStr; + use regex::Regex; use super::*; @@ -367,4 +369,58 @@ mod test { Ok(()) } + + #[test] + fn list_matches_anchored_parsers_on_unconventional_body_lines() -> Result<()> { + let config = crate::config::Config::from_str( + r#" + [git] + conventional_commits = false + filter_unconventional = false + split_commits = true + filter_commits = true + commit_parsers = [{ message = "^fix:", group = "Fixed" }] + processing_order = [ + "commit_preprocessors", + "split_commits", + "conventional_commits", + "commit_parsers", + "link_parsers", + ] + "#, + )?; + let commit = Commit::new( + String::from("123123"), + String::from( + "Unconventional commit\n\nfix: first line of the commit body\nbugfix: not a \ + matching line\nfix: second line of the commit body", + ), + ); + + let mut commits = vec![commit.clone()]; + CommitProcessor::new(&config.git, &mut Summary::default()).run(&mut commits)?; + assert_eq!(commits.len(), 2); + assert_eq!(commits[0].message, "fix: first line of the commit body"); + assert_eq!(commits[1].message, "fix: second line of the commit body"); + for commit in commits { + assert_eq!(commit.group.as_deref(), Some("Fixed")); + assert_eq!(commit.id, "123123"); + } + + for order in [ + None, + Some(vec![ + ProcessingStep::CommitParsers, + ProcessingStep::SplitCommits, + ]), + ] { + let mut cfg = config.git.clone(); + cfg.processing_order = order; + let mut commits = vec![commit.clone()]; + CommitProcessor::new(&cfg, &mut Summary::default()).run(&mut commits)?; + assert!(commits.is_empty()); + } + + Ok(()) + } } diff --git a/npm/git-cliff/yarn.lock b/npm/git-cliff/yarn.lock index bd55224975..0093e17121 100644 --- a/npm/git-cliff/yarn.lock +++ b/npm/git-cliff/yarn.lock @@ -1496,44 +1496,44 @@ __metadata: languageName: node linkType: hard -"git-cliff-darwin-arm64@npm:2.13.1": - version: 2.13.1 - resolution: "git-cliff-darwin-arm64@npm:2.13.1" +"git-cliff-darwin-arm64@npm:2.14.2": + version: 2.14.2 + resolution: "git-cliff-darwin-arm64@npm:2.14.2" conditions: os=darwin & cpu=arm64 languageName: node linkType: hard -"git-cliff-darwin-x64@npm:2.13.1": - version: 2.13.1 - resolution: "git-cliff-darwin-x64@npm:2.13.1" +"git-cliff-darwin-x64@npm:2.14.2": + version: 2.14.2 + resolution: "git-cliff-darwin-x64@npm:2.14.2" conditions: os=darwin & cpu=x64 languageName: node linkType: hard -"git-cliff-linux-arm64@npm:2.13.1": - version: 2.13.1 - resolution: "git-cliff-linux-arm64@npm:2.13.1" +"git-cliff-linux-arm64@npm:2.14.2": + version: 2.14.2 + resolution: "git-cliff-linux-arm64@npm:2.14.2" conditions: os=linux & cpu=arm64 languageName: node linkType: hard -"git-cliff-linux-x64@npm:2.13.1": - version: 2.13.1 - resolution: "git-cliff-linux-x64@npm:2.13.1" +"git-cliff-linux-x64@npm:2.14.2": + version: 2.14.2 + resolution: "git-cliff-linux-x64@npm:2.14.2" conditions: os=linux & cpu=x64 languageName: node linkType: hard -"git-cliff-windows-arm64@npm:2.13.1": - version: 2.13.1 - resolution: "git-cliff-windows-arm64@npm:2.13.1" +"git-cliff-windows-arm64@npm:2.14.2": + version: 2.14.2 + resolution: "git-cliff-windows-arm64@npm:2.14.2" conditions: os=win32 & cpu=arm64 languageName: node linkType: hard -"git-cliff-windows-x64@npm:2.13.1": - version: 2.13.1 - resolution: "git-cliff-windows-x64@npm:2.13.1" +"git-cliff-windows-x64@npm:2.14.2": + version: 2.14.2 + resolution: "git-cliff-windows-x64@npm:2.14.2" conditions: os=win32 & cpu=x64 languageName: node linkType: hard @@ -1549,12 +1549,12 @@ __metadata: "@typescript-eslint/parser": "npm:^8.38.0" eslint: "npm:^9.32.0" execa: "npm:^9.6.0" - git-cliff-darwin-arm64: "npm:2.13.1" - git-cliff-darwin-x64: "npm:2.13.1" - git-cliff-linux-arm64: "npm:2.13.1" - git-cliff-linux-x64: "npm:2.13.1" - git-cliff-windows-arm64: "npm:2.13.1" - git-cliff-windows-x64: "npm:2.13.1" + git-cliff-darwin-arm64: "npm:2.14.2" + git-cliff-darwin-x64: "npm:2.14.2" + git-cliff-linux-arm64: "npm:2.14.2" + git-cliff-linux-x64: "npm:2.14.2" + git-cliff-windows-arm64: "npm:2.14.2" + git-cliff-windows-x64: "npm:2.14.2" tsup: "npm:^8.5.0" typescript: "npm:^5.8.3" typescript-eslint: "npm:^8.38.0" diff --git a/website/docs/configuration/git.md b/website/docs/configuration/git.md index 2d6b560156..3f8165f6b7 100644 --- a/website/docs/configuration/git.md +++ b/website/docs/configuration/git.md @@ -130,6 +130,58 @@ With the configuration above, lines are parsed as conventional commits and uncon If `filter_unconventional = false`, every line will be processed as an unconventional commit, resulting in each line of a commit being treated as a changelog entry. +:::note + +Without [`processing_order`](#processing_order), **git-cliff** applies parsers to the full message before splitting it. A skipped or unmatched commit is discarded before its body lines are checked. + +
+ To filter each line separately: + +To filter each line separately, put `split_commits` before `commit_parsers`: + +```toml +[git] +conventional_commits = false +filter_unconventional = false +split_commits = true +filter_commits = true +commit_parsers = [ + { message = "^fix:", group = "Fixed" }, +] +processing_order = [ + "commit_preprocessors", + "split_commits", + "conventional_commits", + "commit_parsers", + "link_parsers", +] +``` + +Given this message, the configuration keeps only the two `fix:` lines in the `Fixed` group: + +```text +Unconventional commit + +fix: first line of the commit body +bugfix: not a matching line +fix: second line of the commit body +``` + +The resulting changelog excerpt is: + +```markdown +## [unreleased] + +### Fixed + +- Fix: first line of the commit body +- Fix: second line of the commit body +``` + +
+ +::: + ### processing_order Defines a custom commit processing pipeline. @@ -144,7 +196,7 @@ Supported step names: - [`commit_parsers`](#commit_parsers) - [`link_parsers`](#link_parsers) -The default processing order is: +The default processing order (split-before-parsing pipeline) is: ```toml [git]