From 63cffa7f9df02135cb3c736a949cc15776ad2e0b Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 10 Apr 2024 07:16:08 +0800 Subject: [PATCH 1/8] 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 4014c95b47..110fe9ff2f 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 ad778637d2..4e8da72b94 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 27b2142668..9d01f24b88 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 51c63a7564..4276ed79de 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/8] 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 0000000000..3161efca00 --- /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 0000000000..fa448ec4ea --- /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 0000000000..cd245087bf --- /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 2e35cf7010..ce8c582688 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/8] 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 3161efca00..bc7fee5670 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 cd245087bf..0b152c22d2 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 From 6dfa88023398061da47e310d4714370f36a68811 Mon Sep 17 00:00:00 2001 From: tison Date: Tue, 16 Jul 2024 11:22:25 -0700 Subject: [PATCH 4/8] add count_tags to args Signed-off-by: tison --- git-cliff/src/args.rs | 3 +++ git-cliff/src/lib.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/git-cliff/src/args.rs b/git-cliff/src/args.rs index 4c7698567d..152e4bd9c0 100644 --- a/git-cliff/src/args.rs +++ b/git-cliff/src/args.rs @@ -153,6 +153,9 @@ pub struct Opt { /// Sets the tags to ignore in the changelog. #[arg(long, env = "GIT_CLIFF_IGNORE_TAGS", value_name = "PATTERN")] pub ignore_tags: Option, + /// Sets the tags to count in the changelog. + #[arg(long, env = "GIT_CLIFF_COUNT_TAGS", value_name = "PATTERN")] + pub count_tags: Option, /// Sets commits that will be skipped in the changelog. #[arg( long, diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index e682b4d6f5..34c464d8b7 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -518,6 +518,9 @@ pub fn run(mut args: Opt) -> Result<()> { if args.ignore_tags.is_some() { config.git.ignore_tags.clone_from(&args.ignore_tags); } + if args.count_tags.is_some() { + config.git.count_tags.clone_from(&args.count_tags); + } // Process the repositories. let repositories = args.repository.clone().unwrap_or(vec![env::current_dir()?]); let mut releases = Vec::::new(); From 43669c7a1f648e1d73d47e5304910d6cf208445f Mon Sep 17 00:00:00 2001 From: tison Date: Tue, 16 Jul 2024 11:27:48 -0700 Subject: [PATCH 5/8] add docs Signed-off-by: tison --- website/docs/configuration/git.md | 9 +++++++++ website/docs/usage/args.md | 1 + 2 files changed, 10 insertions(+) diff --git a/website/docs/configuration/git.md b/website/docs/configuration/git.md index 51dadd5e64..92cb9a54c7 100644 --- a/website/docs/configuration/git.md +++ b/website/docs/configuration/git.md @@ -204,6 +204,15 @@ While `skip_tags` drop commits from the changelog, `ignore_tags` include ignored * Note that if a commit has multiple tags, any matched tag will result in all associated tags being ignored, including those not explicitly matched by the regex. This is because git-cliff processes tags at the commit level rather than individually. For more details, you can view the discussion [here](https://github.com/orhun/git-cliff/discussions/707) +### count_tags + +A regex for count the matched tags in the final result. + +This value can be also overridden with using the `--count-tags` argument. + +While `skip_tags` drop commits from the changelog, `ignore_tags` include ignored commits into the next tag. +`count_tags` work like an inverted version of `ignore_tags`, that include all the commits but only count the specific tags. + ### topo_order If set to `true`, tags are processed in topological order instead of chronological. diff --git a/website/docs/usage/args.md b/website/docs/usage/args.md index efd9b3ee4b..82bdabf47f 100644 --- a/website/docs/usage/args.md +++ b/website/docs/usage/args.md @@ -37,6 +37,7 @@ git-cliff [FLAGS] [OPTIONS] [--] [RANGE] --with-commit ... Sets custom commit messages to include in the changelog [env: GIT_CLIFF_WITH_COMMIT=] --with-tag-message [] Sets custom message for the latest release [env: GIT_CLIFF_WITH_TAG_MESSAGE=] --ignore-tags Sets the tags to ignore in the changelog [env: GIT_CLIFF_IGNORE_TAGS=] + --count-tags Sets the tags to count in the changelog [env: GIT_CLIFF_COUNT_TAGS=] --skip-commit ... Sets commits that will be skipped in the changelog [env: GIT_CLIFF_SKIP_COMMIT=] -p, --prepend Prepends entries to the given changelog file [env: GIT_CLIFF_PREPEND=] -o, --output [] Writes output to the given file [env: GIT_CLIFF_OUTPUT=] From f62f02131d643887958a34c57dc78b2648642a57 Mon Sep 17 00:00:00 2001 From: tison Date: Tue, 16 Jul 2024 11:32:17 -0700 Subject: [PATCH 6/8] run cargo fmt Signed-off-by: tison --- git-cliff/src/args.rs | 6 +++--- git-cliff/src/lib.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/git-cliff/src/args.rs b/git-cliff/src/args.rs index 152e4bd9c0..328850b3f4 100644 --- a/git-cliff/src/args.rs +++ b/git-cliff/src/args.rs @@ -153,9 +153,9 @@ pub struct Opt { /// Sets the tags to ignore in the changelog. #[arg(long, env = "GIT_CLIFF_IGNORE_TAGS", value_name = "PATTERN")] pub ignore_tags: Option, - /// Sets the tags to count in the changelog. - #[arg(long, env = "GIT_CLIFF_COUNT_TAGS", value_name = "PATTERN")] - pub count_tags: Option, + /// Sets the tags to count in the changelog. + #[arg(long, env = "GIT_CLIFF_COUNT_TAGS", value_name = "PATTERN")] + pub count_tags: Option, /// Sets commits that will be skipped in the changelog. #[arg( long, diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index 34c464d8b7..31a34c455f 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -518,9 +518,9 @@ pub fn run(mut args: Opt) -> Result<()> { if args.ignore_tags.is_some() { config.git.ignore_tags.clone_from(&args.ignore_tags); } - if args.count_tags.is_some() { - config.git.count_tags.clone_from(&args.count_tags); - } + if args.count_tags.is_some() { + config.git.count_tags.clone_from(&args.count_tags); + } // Process the repositories. let repositories = args.repository.clone().unwrap_or(vec![env::current_dir()?]); let mut releases = Vec::::new(); From e1b3a12350d917d853d800fad505d7b33cc34909 Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 9 Aug 2024 11:18:23 +0800 Subject: [PATCH 7/8] fixup default to true Signed-off-by: tison --- git-cliff/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index 3c6b50b730..ed88cce637 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -96,7 +96,7 @@ fn process_repository<'a>( return true; } - let count = count_tags.is_some_and(|r| { + let count = count_tags.map_or(true, |r| { let count_tag = r.is_match(name); if count_tag { trace!("Counting release: {}", name) From 9badaa0ae366e941d1ade70763da773d01e03e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Tue, 13 Aug 2024 12:10:57 +0300 Subject: [PATCH 8/8] docs(website): update documentation about count_tags --- website/docs/configuration/git.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/website/docs/configuration/git.md b/website/docs/configuration/git.md index adfa3ef06c..8002c760e8 100644 --- a/website/docs/configuration/git.md +++ b/website/docs/configuration/git.md @@ -200,22 +200,29 @@ A regex for skip processing the matched tags. A regex for ignore processing the matched tags. -This value can be also overridden with using the `--ignore-tags` argument. - While `skip_tags` drop commits from the changelog, `ignore_tags` include ignored commits into the next tag. -* Note that if a commit has multiple tags, any matched tag will result in all associated tags being ignored, including those not explicitly matched by the regex. This is because git-cliff processes tags at the commit level rather than individually. -For more details, you can view the discussion [here](https://github.com/orhun/git-cliff/discussions/707) +:::note + +Note that if a commit has multiple tags, any matched tag will result in all associated tags being ignored, including those not explicitly matched by the regex. This is because git-cliff processes tags at the commit level rather than individually. +For more details, you can view the discussion [here](https://github.com/orhun/git-cliff/discussions/707). + +::: + +This value can be also overridden with using the `--ignore-tags` argument. ### count_tags -A regex for count the matched tags in the final result. +A regex for _counting in_ the matched tags in the final result. -This value can be also overridden with using the `--count-tags` argument. +:::info -While `skip_tags` drop commits from the changelog, `ignore_tags` include ignored commits into the next tag. `count_tags` work like an inverted version of `ignore_tags`, that include all the commits but only count the specific tags. +::: + +This value can be also overridden with using the `--count-tags` argument. + ### topo_order If set to `true`, tags are processed in topological order instead of chronological.