mirror of
https://github.com/orhun/git-cliff.git
synced 2024-11-29 15:42:15 +03:00
feat(args): add --tag-pattern
argument (#526)
* feat(args): add `--tag-pattern` argument * fix: fix typo in the fixture name * test: update fixture case
This commit is contained in:
parent
bb5664f85f
commit
b4e7a3400f
34
.github/fixtures/test-custom-tag-pattern/cliff.toml
vendored
Normal file
34
.github/fixtures/test-custom-tag-pattern/cliff.toml
vendored
Normal file
@ -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 = """
|
||||
<!-- generated by git-cliff -->
|
||||
"""
|
||||
# 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" },
|
||||
]
|
13
.github/fixtures/test-custom-tag-pattern/commit.sh
vendored
Executable file
13
.github/fixtures/test-custom-tag-pattern/commit.sh
vendored
Executable file
@ -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"
|
31
.github/fixtures/test-custom-tag-pattern/expected.md
vendored
Normal file
31
.github/fixtures/test-custom-tag-pattern/expected.md
vendored
Normal file
@ -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
|
||||
|
||||
<!-- generated by git-cliff -->
|
2
.github/workflows/test-fixtures.yml
vendored
2
.github/workflows/test-fixtures.yml
vendored
@ -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
|
||||
|
@ -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<Vec<Pattern>>,
|
||||
/// Sets the regex for matching git tags.
|
||||
#[arg(long, env = "GIT_CLIFF_TAG_PATTERN", value_name = "PATTERN")]
|
||||
pub tag_pattern: Option<Regex>,
|
||||
/// Sets custom commit messages to include in the changelog.
|
||||
#[arg(
|
||||
long,
|
||||
|
@ -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()?]);
|
||||
|
@ -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.
|
||||
|
@ -1,6 +1,7 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# Command-line Arguments
|
||||
|
||||
```
|
||||
@ -32,6 +33,7 @@ git-cliff [FLAGS] [OPTIONS] [--] [RANGE]
|
||||
-r, --repository <PATH>... Sets the git repository [env: GIT_CLIFF_REPOSITORY=]
|
||||
--include-path <PATTERN>... Sets the path to include related commits [env: GIT_CLIFF_INCLUDE_PATH=]
|
||||
--exclude-path <PATTERN>... Sets the path to exclude related commits [env: GIT_CLIFF_EXCLUDE_PATH=]
|
||||
--tag-pattern <PATTERN> Sets the regex for matching git tags [env: GIT_CLIFF_TAG_PATTERN=]
|
||||
--with-commit <MSG>... Sets custom commit messages to include in the changelog [env: GIT_CLIFF_WITH_COMMIT=]
|
||||
--skip-commit <SHA1>... Sets commits that will be skipped in the changelog [env: GIT_CLIFF_SKIP_COMMIT=]
|
||||
-p, --prepend <PATH> Prepends entries to the given changelog file [env: GIT_CLIFF_PREPEND=]
|
||||
|
Loading…
Reference in New Issue
Block a user