mirror of
https://github.com/orhun/git-cliff.git
synced 2024-09-11 06:55:38 +03:00
fix(changelog): update the commit processing order (#556)
* 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
This commit is contained in:
parent
4971b236ac
commit
c5ef9ab291
@ -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::{
|
||||
@ -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) {
|
||||
@ -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>>();
|
||||
});
|
||||
}
|
||||
@ -311,7 +322,6 @@ mod test {
|
||||
Bump,
|
||||
ChangelogConfig,
|
||||
CommitParser,
|
||||
GitConfig,
|
||||
Remote,
|
||||
RemoteConfig,
|
||||
TextProcessor,
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user