Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(changelog): support count_tags option #599

Merged
merged 11 commits into from
Aug 13, 2024
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>,
orhun marked this conversation as resolved.
Show resolved Hide resolved
orhun marked this conversation as resolved.
Show resolved Hide resolved
/// 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)
tisonkun marked this conversation as resolved.
Show resolved Hide resolved
})
.collect();

Expand Down
Loading