mirror of
https://github.com/orhun/git-cliff.git
synced 2024-11-29 14:52:58 +03:00
feat(changelog): allow disabling conventional commits
This commit is contained in:
parent
1ae8bf1195
commit
76414ce1ad
@ -31,6 +31,8 @@ footer = """
|
||||
"""
|
||||
|
||||
[git]
|
||||
# allow only conventional commits
|
||||
conventional_commits = true
|
||||
# regex for parsing and grouping commits
|
||||
commit_parsers = [
|
||||
{ regex = "feat*", group = "Features"},
|
||||
|
@ -50,10 +50,17 @@ impl Commit<'_> {
|
||||
///
|
||||
/// * converts commit to a conventional commit
|
||||
/// * sets the group for the commit
|
||||
pub fn process(&self, parsers: &[CommitParser], filter: bool) -> Result<Self> {
|
||||
let commit = self.clone();
|
||||
let commit = commit.into_conventional()?;
|
||||
let commit = commit.into_grouped(parsers, filter)?;
|
||||
pub fn process(
|
||||
&self,
|
||||
parsers: &[CommitParser],
|
||||
filter_commits: bool,
|
||||
conventional_commits: bool,
|
||||
) -> Result<Self> {
|
||||
let mut commit = self.clone();
|
||||
if conventional_commits {
|
||||
commit = commit.into_conventional()?;
|
||||
}
|
||||
let commit = commit.into_grouped(parsers, filter_commits)?;
|
||||
Ok(commit)
|
||||
}
|
||||
|
||||
|
@ -24,15 +24,17 @@ pub struct ChangelogConfig {
|
||||
/// Git configuration
|
||||
#[derive(Debug, Clone, serde_derive::Serialize, serde_derive::Deserialize)]
|
||||
pub struct GitConfig {
|
||||
/// Whether to enable conventional commits.
|
||||
pub conventional_commits: bool,
|
||||
/// Git commit parsers.
|
||||
pub commit_parsers: Vec<CommitParser>,
|
||||
pub commit_parsers: Vec<CommitParser>,
|
||||
/// Whether to filter out commits.
|
||||
pub filter_commits: bool,
|
||||
pub filter_commits: bool,
|
||||
/// Blob pattern for git tags.
|
||||
pub tag_pattern: String,
|
||||
pub tag_pattern: String,
|
||||
#[serde(with = "serde_regex")]
|
||||
/// Regex to skip matched tags.
|
||||
pub skip_tags: Regex,
|
||||
pub skip_tags: Regex,
|
||||
}
|
||||
|
||||
/// Parser for grouping commits.
|
||||
|
@ -27,7 +27,8 @@ fn generate_changelog() -> Result<()> {
|
||||
footer: String::from("eoc - end of changelog"),
|
||||
};
|
||||
let git_config = GitConfig {
|
||||
commit_parsers: vec![
|
||||
conventional_commits: true,
|
||||
commit_parsers: vec![
|
||||
CommitParser {
|
||||
regex: Regex::new("feat*").unwrap(),
|
||||
group: Some(String::from("shiny features")),
|
||||
@ -39,9 +40,9 @@ fn generate_changelog() -> Result<()> {
|
||||
skip: None,
|
||||
},
|
||||
],
|
||||
filter_commits: true,
|
||||
tag_pattern: String::new(),
|
||||
skip_tags: Regex::new("v3*").unwrap(),
|
||||
filter_commits: true,
|
||||
tag_pattern: String::new(),
|
||||
skip_tags: Regex::new("v3*").unwrap(),
|
||||
};
|
||||
|
||||
let releases = vec![
|
||||
@ -59,8 +60,12 @@ fn generate_changelog() -> Result<()> {
|
||||
]
|
||||
.iter()
|
||||
.filter_map(|c| {
|
||||
c.process(&git_config.commit_parsers, git_config.filter_commits)
|
||||
.ok()
|
||||
c.process(
|
||||
&git_config.commit_parsers,
|
||||
git_config.filter_commits,
|
||||
git_config.conventional_commits,
|
||||
)
|
||||
.ok()
|
||||
})
|
||||
.collect::<Vec<Commit>>(),
|
||||
commit_id: None,
|
||||
|
@ -38,6 +38,7 @@ impl<'a> Changelog<'a> {
|
||||
match commit.process(
|
||||
&config.git.commit_parsers,
|
||||
config.git.filter_commits,
|
||||
config.git.conventional_commits,
|
||||
) {
|
||||
Ok(commit) => Some(commit),
|
||||
Err(e) => {
|
||||
|
Loading…
Reference in New Issue
Block a user