Skip to content

Commit

Permalink
fix(changelog): update the commit processing order (#556)
Browse files Browse the repository at this point in the history
* fix(changelog): update the commit processing order

* chore(fixture): do not filter out unconventional commits for split fixture

* chore(changelog): do not filter unconventional if split_commits is true
  • Loading branch information
orhun authored Mar 24, 2024
1 parent 4971b23 commit c5ef9ab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
42 changes: 26 additions & 16 deletions git-cliff-core/src/changelog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::commit::Commit;
use crate::config::Config;
use crate::config::{
Config,
GitConfig,
};
use crate::error::Result;
#[cfg(feature = "github")]
use crate::github::{
Expand Down Expand Up @@ -57,6 +60,25 @@ impl<'a> Changelog<'a> {
Ok(changelog)
}

/// Processes a single commit and returns/logs the result.
fn process_commit(
commit: Commit<'a>,
git_config: &GitConfig,
) -> Option<Commit<'a>> {
match commit.process(git_config) {
Ok(commit) => Some(commit),
Err(e) => {
trace!(
"{} - {} ({})",
commit.id[..7].to_string(),
e,
commit.message.lines().next().unwrap_or_default().trim()
);
None
}
}
}

/// Processes the commits and omits the ones that doesn't match the
/// criteria set by configuration file.
fn process_commits(&mut self) {
Expand All @@ -66,33 +88,22 @@ impl<'a> Changelog<'a> {
.commits
.iter()
.cloned()
.filter_map(|commit| Self::process_commit(commit, &self.config.git))
.flat_map(|commit| {
if self.config.git.split_commits.unwrap_or(false) {
commit
.message
.lines()
.map(|line| {
.flat_map(|line| {
let mut c = commit.clone();
c.message = line.to_string();
c
Self::process_commit(c, &self.config.git)
})
.collect()
} else {
vec![commit]
}
})
.filter_map(|commit| match commit.process(&self.config.git) {
Ok(commit) => Some(commit),
Err(e) => {
trace!(
"{} - {} ({})",
commit.id[..7].to_string(),
e,
commit.message.lines().next().unwrap_or_default().trim()
);
None
}
})
.collect::<Vec<Commit>>();
});
}
Expand Down Expand Up @@ -311,7 +322,6 @@ mod test {
Bump,
ChangelogConfig,
CommitParser,
GitConfig,
Remote,
RemoteConfig,
TextProcessor,
Expand Down
4 changes: 3 additions & 1 deletion git-cliff-core/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ impl Commit<'_> {
commit = commit.preprocess(preprocessors)?;
}
if config.conventional_commits.unwrap_or(true) {
if config.filter_unconventional.unwrap_or(true) {
if config.filter_unconventional.unwrap_or(true) &&
!config.split_commits.unwrap_or(false)
{
commit = commit.into_conventional()?;
} else if let Ok(conv_commit) = commit.clone().into_conventional() {
commit = conv_commit;
Expand Down

0 comments on commit c5ef9ab

Please sign in to comment.