From 63cffa7f9df02135cb3c736a949cc15776ad2e0b Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 10 Apr 2024 07:16:08 +0800 Subject: [PATCH 1/3] feat: support count_tags option Signed-off-by: tison --- git-cliff-core/src/changelog.rs | 1 + git-cliff-core/src/config.rs | 3 +++ git-cliff-core/tests/integration_test.rs | 1 + git-cliff/src/lib.rs | 13 ++++++++++++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/git-cliff-core/src/changelog.rs b/git-cliff-core/src/changelog.rs index 4014c95..110fe9f 100644 --- a/git-cliff-core/src/changelog.rs +++ b/git-cliff-core/src/changelog.rs @@ -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, diff --git a/git-cliff-core/src/config.rs b/git-cliff-core/src/config.rs index ad77863..4e8da72 100644 --- a/git-cliff-core/src/config.rs +++ b/git-cliff-core/src/config.rs @@ -109,6 +109,9 @@ pub struct GitConfig { /// Regex to ignore matched tags. #[serde(with = "serde_regex", default)] pub ignore_tags: Option, + /// Regex to count matched tags. + #[serde(with = "serde_regex", default)] + pub count_tags: Option, /// Whether to sort tags topologically. pub topo_order: Option, /// Sorting of the commits inside sections. diff --git a/git-cliff-core/tests/integration_test.rs b/git-cliff-core/tests/integration_test.rs index 27b2142..9d01f24 100644 --- a/git-cliff-core/tests/integration_test.rs +++ b/git-cliff-core/tests/integration_test.rs @@ -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![ diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index 51c63a7..4276ed7 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -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() { @@ -107,7 +118,7 @@ fn process_repository<'a>( }) .unwrap_or_default(); - skip || !ignore + skip || (count && !ignore) }) .collect(); From f219ebd68a1237baa1d8c15d8d93f1ae64c073b0 Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 9 Jun 2024 10:03:23 +0800 Subject: [PATCH 2/3] add fixures tags Signed-off-by: tison --- .../test-invert-ignore-tags/cliff.toml | 33 +++++++++++++++++++ .../test-invert-ignore-tags/commit.sh | 15 +++++++++ .../test-invert-ignore-tags/expected.md | 14 ++++++++ .github/workflows/test-fixtures.yml | 1 + 4 files changed, 63 insertions(+) create mode 100644 .github/fixtures/test-invert-ignore-tags/cliff.toml create mode 100755 .github/fixtures/test-invert-ignore-tags/commit.sh create mode 100644 .github/fixtures/test-invert-ignore-tags/expected.md diff --git a/.github/fixtures/test-invert-ignore-tags/cliff.toml b/.github/fixtures/test-invert-ignore-tags/cliff.toml new file mode 100644 index 00000000..3161efc --- /dev/null +++ b/.github/fixtures/test-invert-ignore-tags/cliff.toml @@ -0,0 +1,33 @@ +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file.\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{% if version %}\ + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else %}\ + ## [unreleased] +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# template for the changelog footer +footer = """ + +""" +# remove the leading and trailing whitespace from the templates +trim = true + +[git] +# regex for skipping tags +skip_tags = "v0.1.0-beta.1" +# regex for invert ignoring tags +count_tags = "v0.2.0" diff --git a/.github/fixtures/test-invert-ignore-tags/commit.sh b/.github/fixtures/test-invert-ignore-tags/commit.sh new file mode 100755 index 00000000..fa448ec --- /dev/null +++ b/.github/fixtures/test-invert-ignore-tags/commit.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -e + +GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: add skip feature" +git tag v0.1.0-beta.1 + +GIT_COMMITTER_DATE="2021-01-23 01:23:46" git commit --allow-empty -m "feat: add feature 1" +GIT_COMMITTER_DATE="2021-01-23 01:23:47" git commit --allow-empty -m "feat: fix feature 1" +git tag v0.1.0 + +GIT_COMMITTER_DATE="2021-01-23 01:23:48" git commit --allow-empty -m "feat: add feature 2" +git tag v0.2.0-beta.1 + +GIT_COMMITTER_DATE="2021-01-23 01:23:49" git commit --allow-empty -m "feat: add feature 3" +git tag v0.2.0 diff --git a/.github/fixtures/test-invert-ignore-tags/expected.md b/.github/fixtures/test-invert-ignore-tags/expected.md new file mode 100644 index 00000000..cd24508 --- /dev/null +++ b/.github/fixtures/test-invert-ignore-tags/expected.md @@ -0,0 +1,14 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## [0.2.0] - 2021-01-23 + +### Feat + +- Add feature 2 +- Add feature 3 +- Add feature 1 +- Fix feature 1 + + diff --git a/.github/workflows/test-fixtures.yml b/.github/workflows/test-fixtures.yml index 2e35cf7..ce8c582 100644 --- a/.github/workflows/test-fixtures.yml +++ b/.github/workflows/test-fixtures.yml @@ -19,6 +19,7 @@ jobs: - fixtures-name: new-fixture-template - fixtures-name: test-github-integration - fixtures-name: test-ignore-tags + - fixtures-name: test-invert-ignore-tags - fixtures-name: test-topo-order command: --latest - fixtures-name: test-date-order From cc2b748060f3866dd3ccf194d2559d2779878744 Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 9 Jun 2024 10:18:57 +0800 Subject: [PATCH 3/3] fixup Signed-off-by: tison --- .github/fixtures/test-invert-ignore-tags/cliff.toml | 3 ++- .github/fixtures/test-invert-ignore-tags/expected.md | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/fixtures/test-invert-ignore-tags/cliff.toml b/.github/fixtures/test-invert-ignore-tags/cliff.toml index 3161efc..bc7fee5 100644 --- a/.github/fixtures/test-invert-ignore-tags/cliff.toml +++ b/.github/fixtures/test-invert-ignore-tags/cliff.toml @@ -29,5 +29,6 @@ trim = true [git] # regex for skipping tags skip_tags = "v0.1.0-beta.1" -# regex for invert ignoring tags +# regex for ignoring tags +ignore_tags = "v.*-beta.*" count_tags = "v0.2.0" diff --git a/.github/fixtures/test-invert-ignore-tags/expected.md b/.github/fixtures/test-invert-ignore-tags/expected.md index cd24508..0b152c2 100644 --- a/.github/fixtures/test-invert-ignore-tags/expected.md +++ b/.github/fixtures/test-invert-ignore-tags/expected.md @@ -6,9 +6,9 @@ All notable changes to this project will be documented in this file. ### Feat -- Add feature 2 -- Add feature 3 - Add feature 1 - Fix feature 1 +- Add feature 2 +- Add feature 3