Skip to content

Commit

Permalink
feat(parser): support using regex group values (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Apr 2, 2023
1 parent fe5e5b8 commit 7767ace
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,8 @@ Examples:
- Group the commit as "Features" if the commit message (description) starts with "feat".
- `{ body = ".*security", group = "Security"}`
- Group the commit as "Security" if the commit body contains "security".
- `{ message = '^fix\((.*)\)', group = 'Fix (${1})' }`
- Use the matched scope value from the commit message in the group name.
- `{ message = ".*deprecated", body = ".*deprecated", group = "Deprecation"}`
- Group the commit as "Deprecation" if the commit body and message contains "deprecated".
- `{ message = "^revert", skip = true}`
Expand Down
10 changes: 9 additions & 1 deletion git-cliff-core/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,15 @@ impl Commit<'_> {
"Skipping commit",
)));
} else {
self.group = parser.group.as_ref().cloned();
self.group =
parser.group.as_ref().cloned().map(|mut group| {
for mat in regex.find_iter(&text) {
group = regex
.replace(mat.as_str(), group)
.to_string();
}
group
});
self.scope = parser.scope.as_ref().cloned();
self.default_scope = parser.default_scope.as_ref().cloned();
return Ok(self);
Expand Down
20 changes: 20 additions & 0 deletions git-cliff/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ mod test {
scope: Some(String::from("documentation")),
skip: None,
},
CommitParser {
message: Regex::new(r#"match\((.*)\):.*"#).ok(),
body: None,
group: Some(String::from("Matched ($1)")),
default_scope: None,
scope: None,
skip: None,
},
CommitParser {
message: Regex::new(".*").ok(),
body: None,
Expand Down Expand Up @@ -307,6 +315,10 @@ mod test {
String::from("qwertz"),
String::from("feat!: support breaking commits"),
),
Commit::new(
String::from("qwert0"),
String::from("match(group): support regex-replace for groups"),
),
],
commit_id: Some(String::from("0bc123")),
timestamp: 50000000,
Expand Down Expand Up @@ -392,6 +404,10 @@ mod test {
#### documentation
- update docs
### Matched (group)
#### group
- support regex-replace for groups
### New features
#### app
- add cool features
Expand Down Expand Up @@ -497,6 +513,10 @@ chore(deps): fix broken deps
#### documentation
- update docs
### Matched (group)
#### group
- support regex-replace for groups
### New features
#### app
- add cool features
Expand Down

0 comments on commit 7767ace

Please sign in to comment.