From 1d1b3b80e163baf34113456f24e3fbbc203e355d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Fri, 12 Apr 2024 13:58:06 +0300 Subject: [PATCH] fix(parser): allow matching empty commit body (#605) --- git-cliff-core/src/commit.rs | 18 ++++++++---------- website/docs/tips-and-tricks.md | 9 +++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/git-cliff-core/src/commit.rs b/git-cliff-core/src/commit.rs index a72a689..c9c535b 100644 --- a/git-cliff-core/src/commit.rs +++ b/git-cliff-core/src/commit.rs @@ -262,11 +262,13 @@ impl Commit<'_> { if let Some(message_regex) = parser.message.as_ref() { regex_checks.push((message_regex, self.message.to_string())) } - if let (Some(body_regex), Some(body)) = ( - parser.body.as_ref(), - self.conv.as_ref().and_then(|v| v.body()), - ) { - regex_checks.push((body_regex, body.to_string())) + let body = self + .conv + .as_ref() + .and_then(|v| v.body()) + .map(|v| v.to_string()); + if let Some(body_regex) = parser.body.as_ref() { + regex_checks.push((body_regex, body.clone().unwrap_or_default())) } if let (Some(field_name), Some(pattern_regex)) = (parser.field.as_ref(), parser.pattern.as_ref()) @@ -276,11 +278,7 @@ impl Commit<'_> { match field_name.as_str() { "id" => Some(self.id.clone()), "message" => Some(self.message.clone()), - "body" => self - .conv - .as_ref() - .and_then(|v| v.body()) - .map(|v| v.to_string()), + "body" => body, "author.name" => self.author.name.clone(), "author.email" => self.author.email.clone(), "committer.name" => self.committer.name.clone(), diff --git a/website/docs/tips-and-tricks.md b/website/docs/tips-and-tricks.md index 5dfe2fa..5c13592 100644 --- a/website/docs/tips-and-tricks.md +++ b/website/docs/tips-and-tricks.md @@ -60,3 +60,12 @@ commit_preprocessors = [ { pattern = ' *(:\w+:|[\p{Emoji_Presentation}\p{Extended_Pictographic}](?:\u{FE0F})?\u{200D}?) *', replace = "" }, ] ``` + +## Skip commits with an empty body + +```toml +[git] +commit_parsers = [ + { body = "$^", skip = true }, +] +```