Skip to content

Commit

Permalink
feat: support count_tags option
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Apr 9, 2024
1 parent 3b74254 commit 63cffa7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions git-cliff-core/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ mod test {
tag_pattern: None,
skip_tags: Regex::new("v3.*").ok(),
ignore_tags: None,
count_tags: None,
topo_order: Some(false),
sort_commits: Some(String::from("oldest")),
link_parsers: None,
Expand Down
3 changes: 3 additions & 0 deletions git-cliff-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ pub struct GitConfig {
/// Regex to ignore matched tags.
#[serde(with = "serde_regex", default)]
pub ignore_tags: Option<Regex>,
/// Regex to count matched tags.
#[serde(with = "serde_regex", default)]
pub count_tags: Option<Regex>,
/// Whether to sort tags topologically.
pub topo_order: Option<bool>,
/// Sorting of the commits inside sections.
Expand Down
1 change: 1 addition & 0 deletions git-cliff-core/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ fn generate_changelog() -> Result<()> {
tag_pattern: None,
skip_tags: None,
ignore_tags: None,
count_tags: None,
topo_order: None,
sort_commits: None,
link_parsers: Some(vec![
Expand Down
13 changes: 12 additions & 1 deletion git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,23 @@ fn process_repository<'a>(
let mut tags = repository.tags(&config.git.tag_pattern, args.topo_order)?;
let skip_regex = config.git.skip_tags.as_ref();
let ignore_regex = config.git.ignore_tags.as_ref();
let count_tags = config.git.count_tags.as_ref();
tags = tags
.into_iter()
.filter(|(_, name)| {
// Keep skip tags to drop commits in the later stage.
let skip = skip_regex.map(|r| r.is_match(name)).unwrap_or_default();

let count = count_tags
.map(|r| {
let count_tag = r.is_match(name);
if count_tag {
trace!("Counting release: {}", name)
}
count_tag
})
.unwrap_or(true);

let ignore = ignore_regex
.map(|r| {
if r.as_str().trim().is_empty() {
Expand All @@ -107,7 +118,7 @@ fn process_repository<'a>(
})
.unwrap_or_default();

skip || !ignore
skip || (count && !ignore)
})
.collect();

Expand Down

0 comments on commit 63cffa7

Please sign in to comment.