diff --git a/.github/fixtures/test-custom-tag-pattern/cliff.toml b/.github/fixtures/test-custom-tag-pattern/cliff.toml new file mode 100644 index 0000000000..fc3d5db2a2 --- /dev/null +++ b/.github/fixtures/test-custom-tag-pattern/cliff.toml @@ -0,0 +1,34 @@ +[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="alpha-") }}] - {{ 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 %} + - {{ 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 parsing and grouping commits +commit_parsers = [ + { message = "^feat", group = "Features", default_scope = "app" }, + { message = "^fix", group = "Bug Fixes", scope = "cli" }, +] diff --git a/.github/fixtures/test-custom-tag-pattern/commit.sh b/.github/fixtures/test-custom-tag-pattern/commit.sh new file mode 100755 index 0000000000..8e300bdf7b --- /dev/null +++ b/.github/fixtures/test-custom-tag-pattern/commit.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -e + +GIT_COMMITTER_DATE="2022-04-06 01:25:08" git commit --allow-empty -m "Initial commit" +GIT_COMMITTER_DATE="2022-04-06 01:25:09" git commit --allow-empty -m "feat: add feature 1" +git tag beta-0.1.0 +GIT_COMMITTER_DATE="2022-04-06 01:25:10" git commit --allow-empty -m "fix: fix feature 1" +git tag alpha-0.1.0 +GIT_COMMITTER_DATE="2022-04-06 01:25:11" git commit --allow-empty -m "feat(gui): add feature 2" +git tag beta-0.2.0 +GIT_COMMITTER_DATE="2022-04-06 01:25:12" git commit --allow-empty -m "fix(gui): fix feature 2" +git tag alpha-0.2.0 +GIT_COMMITTER_DATE="2022-04-06 01:25:13" git commit --allow-empty -m "test: add tests" diff --git a/.github/fixtures/test-custom-tag-pattern/expected.md b/.github/fixtures/test-custom-tag-pattern/expected.md new file mode 100644 index 0000000000..72e96a6f09 --- /dev/null +++ b/.github/fixtures/test-custom-tag-pattern/expected.md @@ -0,0 +1,31 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## [unreleased] + +### Test + +- Add tests + +## [0.2.0] - 2022-04-06 + +### Bug Fixes + +- Fix feature 2 + +### Features + +- Add feature 2 + +## [0.1.0] - 2022-04-06 + +### Bug Fixes + +- Fix feature 1 + +### Features + +- Add feature 1 + + diff --git a/.github/workflows/test-fixtures.yml b/.github/workflows/test-fixtures.yml index d8aab5dd63..22b3473de1 100644 --- a/.github/workflows/test-fixtures.yml +++ b/.github/workflows/test-fixtures.yml @@ -65,6 +65,8 @@ jobs: command: --skip-commit ad27b43e8032671afb4809a1a3ecf12f45c60e0e - fixtures-name: test-no-exec command: --no-exec + - fixtures-name: test-custom-tag-pattern + command: --tag-pattern "alpha.*" steps: - name: Checkout uses: actions/checkout@v4 diff --git a/git-cliff/src/args.rs b/git-cliff/src/args.rs index 468f780383..3f8d6766a2 100644 --- a/git-cliff/src/args.rs +++ b/git-cliff/src/args.rs @@ -18,6 +18,7 @@ use git_cliff_core::{ DEFAULT_OUTPUT, }; use glob::Pattern; +use regex::Regex; use secrecy::SecretString; use std::path::PathBuf; @@ -130,6 +131,9 @@ pub struct Opt { num_args(1..) )] pub exclude_path: Option>, + /// Sets the regex for matching git tags. + #[arg(long, env = "GIT_CLIFF_TAG_PATTERN", value_name = "PATTERN")] + pub tag_pattern: Option, /// Sets custom commit messages to include in the changelog. #[arg( long, diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index 93d260ea28..f3355bedd8 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -417,6 +417,9 @@ pub fn run(mut args: Opt) -> Result<()> { } } config.git.skip_tags = config.git.skip_tags.filter(|r| !r.as_str().is_empty()); + if args.tag_pattern.is_some() { + config.git.tag_pattern = args.tag_pattern.clone(); + } // Process the repositories. let repositories = args.repository.clone().unwrap_or(vec![env::current_dir()?]); diff --git a/website/docs/configuration/git.md b/website/docs/configuration/git.md index a23ee46167..b7d7145919 100644 --- a/website/docs/configuration/git.md +++ b/website/docs/configuration/git.md @@ -183,6 +183,8 @@ If set to `true`, commits that are not matched by [`commit_parsers`](#commit_par A regular expression for matching the git tags. +This value can be also overridden with using the `--tag-pattern` argument. + ### skip_tags A regex for skip processing the matched tags. diff --git a/website/docs/usage/args.md b/website/docs/usage/args.md index 56973051cc..3a79ff630c 100644 --- a/website/docs/usage/args.md +++ b/website/docs/usage/args.md @@ -1,6 +1,7 @@ --- sidebar_position: 1 --- + # Command-line Arguments ``` @@ -32,6 +33,7 @@ git-cliff [FLAGS] [OPTIONS] [--] [RANGE] -r, --repository ... Sets the git repository [env: GIT_CLIFF_REPOSITORY=] --include-path ... Sets the path to include related commits [env: GIT_CLIFF_INCLUDE_PATH=] --exclude-path ... Sets the path to exclude related commits [env: GIT_CLIFF_EXCLUDE_PATH=] + --tag-pattern Sets the regex for matching git tags [env: GIT_CLIFF_TAG_PATTERN=] --with-commit ... Sets custom commit messages to include in the changelog [env: GIT_CLIFF_WITH_COMMIT=] --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=]