Skip to content

Commit

Permalink
feat(changelog): breaking changes are never skipped
Browse files Browse the repository at this point in the history
Fixes orhun#106
  • Loading branch information
sbmueller committed Oct 1, 2022
1 parent f9d4b88 commit d257db4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,8 @@ BREAKING CHANGE: this is a breaking change
If the `BREAKING CHANGE:` footer is present, the footer will also be included in
`commit.footers`.

Breaking changes will never be skipped, even when matched by a skipping [commit_parser](#commit_parsers).

##### Committer vs Author

From [Git docs](https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History):
Expand Down
19 changes: 14 additions & 5 deletions git-cliff-core/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ impl Commit<'_> {
Ok(self)
}

/// States if the commit is skipped in the provided `CommitParser`.
///
/// Returns `true` if the parser's `skip` field is `true` and the commit is
/// not breaking, `false` otherwise.
fn skip_commit(&self, parser: &CommitParser) -> bool {
parser.skip.unwrap_or(false) &&
self.conv.as_ref().map(|c| !c.breaking()).unwrap_or(false)
}

/// Parses the commit using [`CommitParser`]s.
///
/// Sets the [`group`] and [`scope`] of the commit.
Expand All @@ -253,15 +262,15 @@ impl Commit<'_> {
}
for (regex, text) in regex_checks {
if regex.is_match(&text) {
if parser.skip != Some(true) {
if self.skip_commit(parser) {
return Err(AppError::GroupError(String::from(
"Skipping commit",
)));
} else {
self.group = parser.group.as_ref().cloned();
self.scope = parser.scope.as_ref().cloned();
self.default_scope = parser.default_scope.as_ref().cloned();
return Ok(self);
} else {
return Err(AppError::GroupError(String::from(
"Skipping commit",
)));
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions git-cliff/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ mod test {
String::from("qwerty"),
String::from("chore: <preprocess>"),
),
Commit::new(
String::from("qwertz"),
String::from("feat!: support breaking commits"),
),
],
commit_id: Some(String::from("0bc123")),
timestamp: 50000000,
Expand Down Expand Up @@ -328,6 +332,10 @@ mod test {
String::from("docs(app): document zyx"),
),
Commit::new(String::from("def789"), String::from("merge #4")),
Commit::new(
String::from("dev063"),
String::from("feat!: merge #5"),
),
Commit::new(
String::from("qwerty"),
String::from("fix(app): fix abc"),
Expand Down Expand Up @@ -364,6 +372,9 @@ mod test {
#### app
- add xyz
#### other
- merge #5
### Other
#### app
- document zyx
Expand All @@ -388,6 +399,7 @@ mod test {
#### other
- support unscoped commits
- support breaking commits
### Other
#### app
Expand Down Expand Up @@ -455,6 +467,9 @@ chore(deps): fix broken deps
#### app
- add xyz
#### other
- merge #5
### Other
#### app
- document zyx
Expand Down Expand Up @@ -490,6 +505,7 @@ chore(deps): fix broken deps
#### other
- support unscoped commits
- support breaking commits
- add awesome stuff
### Other
Expand Down

0 comments on commit d257db4

Please sign in to comment.