Skip to content

Commit 94891c2

Browse files
authored
feat(args): add --ignore-tags argument (#696)
* feat(cli,args): allow overwriting `ignore_tags` argument Signed-off-by: Bukowa <gitbukowa@gmail.com> * chore(lint): cargo fmt Signed-off-by: Bukowa <gitbukowa@gmail.com> * chore(lint): clippy Signed-off-by: Bukowa <gitbukowa@gmail.com> * Revert "chore(lint): clippy" This reverts commit f307647. Signed-off-by: Bukowa <gitbukowa@gmail.com> * Revert chore(lint): cargo fmt in changelog.rs Signed-off-by: Bukowa <gitbukowa@gmail.com> * chore: git update-index --chmod=+x .github/fixtures/test-cli-arg-ignore-tags/commit.sh Signed-off-by: Bukowa <gitbukowa@gmail.com> * chore(lint): fix formatting Signed-off-by: Bukowa <gitbukowa@gmail.com> * revert changes to test-fixtures-locally.sh Signed-off-by: Bukowa <gitbukowa@gmail.com> * revert changes to .gitignore Signed-off-by: Bukowa <gitbukowa@gmail.com> * chore: change doc in args.rs and doc Signed-off-by: Bukowa <gitbukowa@gmail.com> * Revert "chore(lint): fix formatting" This reverts commit c829865. Signed-off-by: Bukowa <gitbukowa@gmail.com> * style(lint): rustfmt Signed-off-by: Bukowa <gitbukowa@gmail.com> * tests(fixtures): uncomment commit * tests(fixtures): fix expected.md --------- Signed-off-by: Bukowa <gitbukowa@gmail.com>
1 parent 9fc12bb commit 94891c2

File tree

8 files changed

+82
-1
lines changed

8 files changed

+82
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[changelog]
2+
# changelog header
3+
header = """
4+
# Changelog\n
5+
All notable changes to this project will be documented in this file.\n
6+
"""
7+
# template for the changelog body
8+
# https://keats.github.io/tera/docs/#introduction
9+
body = """
10+
{% if version %}\
11+
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
12+
{% else %}\
13+
## [unreleased]
14+
{% endif %}\
15+
{% for group, commits in commits | group_by(attribute="group") %}
16+
### {{ group | upper_first }}
17+
{% for commit in commits %}
18+
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\
19+
{% endfor %}
20+
{% endfor %}\n
21+
"""
22+
# template for the changelog footer
23+
footer = """
24+
<!-- generated by git-cliff -->
25+
"""
26+
# remove the leading and trailing whitespace from the templates
27+
trim = true
28+
29+
[git]
30+
# regex for skipping tags
31+
skip_tags = ""
32+
# regex for ignoring tags
33+
ignore_tags = ""
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: add first beta feature"
5+
git tag v1.0.0-beta.1
6+
7+
GIT_COMMITTER_DATE="2021-01-23 01:23:46" git commit --allow-empty -m "feat: add second beta feature"
8+
git tag v1.0.0-beta.2
9+
10+
# WARNING: If we won't create this commit, 1.0.0 won't be created!
11+
GIT_COMMITTER_DATE="2021-01-23 01:23:47" git commit --allow-empty -m "chore: why do i need a commit here?"
12+
git tag v1.0.0
13+
14+
GIT_COMMITTER_DATE="2021-01-23 01:23:49" git commit --allow-empty -m "fix: simple fix"
15+
git tag v1.0.1
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## [1.0.1] - 2021-01-23
6+
7+
### Fix
8+
9+
- Simple fix
10+
11+
## [1.0.0] - 2021-01-23
12+
13+
### Chore
14+
15+
- Why do i need a commit here?
16+
17+
### Feat
18+
19+
- Add first beta feature
20+
- Add second beta feature
21+
22+
<!-- generated by git-cliff -->

.github/workflows/test-fixtures.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ jobs:
7777
command: --bump
7878
- fixtures-name: test-bump-initial-tag-cli-arg
7979
command: --bump --tag=2.1.1
80+
- fixtures-name: test-cli-arg-ignore-tags
81+
command: --ignore-tags ".*beta"
82+
8083
steps:
8184
- name: Checkout
8285
uses: actions/checkout@v4

git-cliff/src/args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ pub struct Opt {
142142
num_args(1..)
143143
)]
144144
pub with_commit: Option<Vec<String>>,
145+
/// Sets the tags to ignore in the changelog.
146+
#[arg(long, env = "GIT_CLIFF_IGNORE_TAGS", value_name = "PATTERN")]
147+
pub ignore_tags: Option<Regex>,
145148
/// Sets commits that will be skipped in the changelog.
146149
#[arg(
147150
long,

git-cliff/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,9 @@ pub fn run(mut args: Opt) -> Result<()> {
489489
if args.tag.is_some() {
490490
config.bump.initial_tag.clone_from(&args.tag);
491491
}
492-
492+
if args.ignore_tags.is_some() {
493+
config.git.ignore_tags.clone_from(&args.ignore_tags);
494+
}
493495
// Process the repositories.
494496
let repositories = args.repository.clone().unwrap_or(vec![env::current_dir()?]);
495497
let mut releases = Vec::<Release>::new();

website/docs/configuration/git.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ A regex for skip processing the matched tags.
197197

198198
A regex for ignore processing the matched tags.
199199

200+
This value can be also overridden with using the `--ignore-tags` argument.
201+
200202
While `skip_tags` drop commits from the changelog, `ignore_tags` include ignored commits into the next tag.
201203

202204
### topo_order

website/docs/usage/args.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ git-cliff [FLAGS] [OPTIONS] [--] [RANGE]
3535
--exclude-path <PATTERN>... Sets the path to exclude related commits [env: GIT_CLIFF_EXCLUDE_PATH=]
3636
--tag-pattern <PATTERN> Sets the regex for matching git tags [env: GIT_CLIFF_TAG_PATTERN=]
3737
--with-commit <MSG>... Sets custom commit messages to include in the changelog [env: GIT_CLIFF_WITH_COMMIT=]
38+
--ignore-tags <PATTERN> Sets the tags to ignore in the changelog [env: GIT_CLIFF_IGNORE_TAGS=]
3839
--skip-commit <SHA1>... Sets commits that will be skipped in the changelog [env: GIT_CLIFF_SKIP_COMMIT=]
3940
-p, --prepend <PATH> Prepends entries to the given changelog file [env: GIT_CLIFF_PREPEND=]
4041
-o, --output [<PATH>] Writes output to the given file [env: GIT_CLIFF_OUTPUT=]

0 commit comments

Comments
 (0)