1
1
mirror of https://github.com/orhun/git-cliff.git synced 2024-09-11 15:05:30 +03:00

Compare commits

...

3 Commits

Author SHA1 Message Date
dependabot[bot]
5e3b4ef35f
Merge e44ab36c09 into b8045e97ed 2024-08-15 14:53:02 -07:00
tison
b8045e97ed
feat(changelog): support count_tags option (#599)
* feat: support count_tags option

Signed-off-by: tison <wander4096@gmail.com>

* add fixures tags

Signed-off-by: tison <wander4096@gmail.com>

* fixup

Signed-off-by: tison <wander4096@gmail.com>

* add count_tags to args

Signed-off-by: tison <wander4096@gmail.com>

* add docs

Signed-off-by: tison <wander4096@gmail.com>

* run cargo fmt

Signed-off-by: tison <wander4096@gmail.com>

* fixup default to true

Signed-off-by: tison <wander4096@gmail.com>

* docs(website): update documentation about count_tags

---------

Signed-off-by: tison <wander4096@gmail.com>
Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2024-08-13 12:22:54 +03:00
dependabot[bot]
e44ab36c09
chore(deps): bump env_logger from 0.10.2 to 0.11.5
Bumps [env_logger](https://github.com/rust-cli/env_logger) from 0.10.2 to 0.11.5.
- [Release notes](https://github.com/rust-cli/env_logger/releases)
- [Changelog](https://github.com/rust-cli/env_logger/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-cli/env_logger/compare/v0.10.2...v0.11.5)

---
updated-dependencies:
- dependency-name: env_logger
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-29 08:29:38 +00:00
13 changed files with 124 additions and 21 deletions

View 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="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 = "v0.1.0-beta.1"
# regex for ignoring tags
ignore_tags = "v.*-beta.*"
count_tags = "v0.2.0"

View File

@ -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

View File

@ -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 1
- Fix feature 1
- Add feature 2
- Add feature 3
<!-- generated by git-cliff -->

View File

@ -22,6 +22,7 @@ jobs:
- fixtures-name: test-gitea-integration
- fixtures-name: test-bitbucket-integration
- fixtures-name: test-ignore-tags
- fixtures-name: test-invert-ignore-tags
- fixtures-name: test-topo-order
command: --latest
- fixtures-name: test-date-order

31
Cargo.lock generated
View File

@ -634,16 +634,26 @@ dependencies = [
]
[[package]]
name = "env_logger"
version = "0.10.2"
name = "env_filter"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580"
checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab"
dependencies = [
"humantime",
"is-terminal",
"log",
"regex",
"termcolor",
]
[[package]]
name = "env_logger"
version = "0.11.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d"
dependencies = [
"anstream",
"anstyle",
"env_filter",
"humantime",
"log",
]
[[package]]
@ -2730,15 +2740,6 @@ dependencies = [
"unic-segment",
]
[[package]]
name = "termcolor"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
dependencies = [
"winapi-util",
]
[[package]]
name = "terminal_size"
version = "0.3.0"

View File

@ -784,6 +784,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,

View File

@ -109,6 +109,9 @@ pub struct GitConfig {
/// Regex to ignore matched tags.
#[serde(with = "serde_regex", default)]
pub ignore_tags: Option<Regex>,
/// Regex to count matched tags.
#[serde(with = "serde_regex", default)]
pub count_tags: Option<Regex>,
/// Whether to sort tags topologically.
pub topo_order: Option<bool>,
/// Sorting of the commits inside sections.

View File

@ -118,6 +118,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![

View File

@ -53,7 +53,7 @@ clap_mangen = "0.2.21"
shellexpand = "3.1.0"
update-informer = { version = "1.1.0", optional = true }
indicatif = { version = "0.17.8", optional = true }
env_logger = "0.10.2"
env_logger = "0.11.5"
pprof = { version = "0.13", optional = true }
rand = { version = "0.8.4", optional = true }

View File

@ -154,6 +154,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<Regex>,
/// Sets the tags to count in the changelog.
#[arg(long, env = "GIT_CLIFF_COUNT_TAGS", value_name = "PATTERN")]
pub count_tags: Option<Regex>,
/// Sets commits that will be skipped in the changelog.
#[arg(
long,

View File

@ -86,6 +86,7 @@ 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.retain(|_, tag| {
let name = &tag.name;
@ -95,6 +96,14 @@ fn process_repository<'a>(
return true;
}
let count = count_tags.map_or(true, |r| {
let count_tag = r.is_match(name);
if count_tag {
trace!("Counting release: {}", name)
}
count_tag
});
let ignore = ignore_regex.is_some_and(|r| {
if r.as_str().trim().is_empty() {
return false;
@ -106,7 +115,8 @@ fn process_repository<'a>(
}
ignore_tag
});
!ignore
count && !ignore
});
if !config.remote.github.is_set() {
@ -508,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::<Release>::new();

View File

@ -200,12 +200,28 @@ 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 _counting in_ the matched tags in the final result.
:::info
`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

View File

@ -37,6 +37,7 @@ git-cliff [FLAGS] [OPTIONS] [--] [RANGE]
--with-commit <MSG>... Sets custom commit messages to include in the changelog [env: GIT_CLIFF_WITH_COMMIT=]
--with-tag-message [<MSG>] Sets custom message for the latest release [env: GIT_CLIFF_WITH_TAG_MESSAGE=]
--ignore-tags <PATTERN> Sets the tags to ignore in the changelog [env: GIT_CLIFF_IGNORE_TAGS=]
--count-tags <PATTERN> Sets the tags to count in the changelog [env: GIT_CLIFF_COUNT_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=]