Skip to content

Commit

Permalink
feat(args): add --ignore-tags argument (#696)
Browse files Browse the repository at this point in the history
* feat(cli,args): allow overwriting `ignore_tags` argument

Signed-off-by: Bukowa <[email protected]>

* chore(lint): cargo fmt

Signed-off-by: Bukowa <[email protected]>

* chore(lint): clippy

Signed-off-by: Bukowa <[email protected]>

* Revert "chore(lint): clippy"

This reverts commit f307647.

Signed-off-by: Bukowa <[email protected]>

* Revert chore(lint): cargo fmt in changelog.rs

Signed-off-by: Bukowa <[email protected]>

* chore: git update-index --chmod=+x .github/fixtures/test-cli-arg-ignore-tags/commit.sh

Signed-off-by: Bukowa <[email protected]>

* chore(lint): fix formatting

Signed-off-by: Bukowa <[email protected]>

* revert changes to test-fixtures-locally.sh

Signed-off-by: Bukowa <[email protected]>

* revert changes to .gitignore

Signed-off-by: Bukowa <[email protected]>

* chore: change doc in args.rs and doc

Signed-off-by: Bukowa <[email protected]>

* Revert "chore(lint): fix formatting"

This reverts commit c829865.

Signed-off-by: Bukowa <[email protected]>

* style(lint): rustfmt

Signed-off-by: Bukowa <[email protected]>

* tests(fixtures): uncomment commit

* tests(fixtures): fix expected.md

---------

Signed-off-by: Bukowa <[email protected]>
  • Loading branch information
bukowa authored Jun 17, 2024
1 parent 9fc12bb commit 94891c2
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 1 deletion.
33 changes: 33 additions & 0 deletions .github/fixtures/test-cli-arg-ignore-tags/cliff.toml
Original file line number Diff line number Diff line change
@@ -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 = """
<!-- generated by git-cliff -->
"""
# remove the leading and trailing whitespace from the templates
trim = true

[git]
# regex for skipping tags
skip_tags = ""
# regex for ignoring tags
ignore_tags = ""
15 changes: 15 additions & 0 deletions .github/fixtures/test-cli-arg-ignore-tags/commit.sh
Original file line number Diff line number Diff line change
@@ -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 first beta feature"
git tag v1.0.0-beta.1

GIT_COMMITTER_DATE="2021-01-23 01:23:46" git commit --allow-empty -m "feat: add second beta feature"
git tag v1.0.0-beta.2

# WARNING: If we won't create this commit, 1.0.0 won't be created!
GIT_COMMITTER_DATE="2021-01-23 01:23:47" git commit --allow-empty -m "chore: why do i need a commit here?"
git tag v1.0.0

GIT_COMMITTER_DATE="2021-01-23 01:23:49" git commit --allow-empty -m "fix: simple fix"
git tag v1.0.1
22 changes: 22 additions & 0 deletions .github/fixtures/test-cli-arg-ignore-tags/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Changelog

All notable changes to this project will be documented in this file.

## [1.0.1] - 2021-01-23

### Fix

- Simple fix

## [1.0.0] - 2021-01-23

### Chore

- Why do i need a commit here?

### Feat

- Add first beta feature
- Add second beta feature

<!-- generated by git-cliff -->
3 changes: 3 additions & 0 deletions .github/workflows/test-fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ jobs:
command: --bump
- fixtures-name: test-bump-initial-tag-cli-arg
command: --bump --tag=2.1.1
- fixtures-name: test-cli-arg-ignore-tags
command: --ignore-tags ".*beta"

steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions git-cliff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ pub struct Opt {
num_args(1..)
)]
pub with_commit: Option<Vec<String>>,
/// Sets the tags to ignore in the changelog.
#[arg(long, env = "GIT_CLIFF_IGNORE_TAGS", value_name = "PATTERN")]
pub ignore_tags: Option<Regex>,
/// Sets commits that will be skipped in the changelog.
#[arg(
long,
Expand Down
4 changes: 3 additions & 1 deletion git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,9 @@ pub fn run(mut args: Opt) -> Result<()> {
if args.tag.is_some() {
config.bump.initial_tag.clone_from(&args.tag);
}

if args.ignore_tags.is_some() {
config.git.ignore_tags.clone_from(&args.ignore_tags);
}
// Process the repositories.
let repositories = args.repository.clone().unwrap_or(vec![env::current_dir()?]);
let mut releases = Vec::<Release>::new();
Expand Down
2 changes: 2 additions & 0 deletions website/docs/configuration/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ 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.

### topo_order
Expand Down
1 change: 1 addition & 0 deletions website/docs/usage/args.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ git-cliff [FLAGS] [OPTIONS] [--] [RANGE]
--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=]
--ignore-tags <PATTERN> Sets the tags to ignore in the changelog [env: GIT_CLIFF_IGNORE_TAGS=]
--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=]
-o, --output [<PATH>] Writes output to the given file [env: GIT_CLIFF_OUTPUT=]
Expand Down

0 comments on commit 94891c2

Please sign in to comment.