1
1
mirror of https://github.com/orhun/git-cliff.git synced 2024-08-16 10:20:25 +03:00

fix(parser): allow matching empty commit body (#605)

This commit is contained in:
Orhun Parmaksız 2024-04-12 13:58:06 +03:00 committed by GitHub
parent c7001e9d13
commit 1d1b3b80e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 10 deletions

View File

@ -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(),

View File

@ -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 },
]
```