mirror of
https://github.com/orhun/git-cliff.git
synced 2024-09-11 15:05:30 +03:00
feat(args): add --with-tag-message
argument
to allow setting the message of the last release in the context
This commit is contained in:
parent
b5b1d3cfc2
commit
cea95ad214
37
.github/fixtures/test-bump-unreleased-with-tag-message-arg/cliff.toml
vendored
Normal file
37
.github/fixtures/test-bump-unreleased-with-tag-message-arg/cliff.toml
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
[changelog]
|
||||
# template for the changelog footer
|
||||
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") }}]
|
||||
{% if message %}
|
||||
{{ message }}
|
||||
{% endif %}\
|
||||
{% 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" },
|
||||
]
|
11
.github/fixtures/test-bump-unreleased-with-tag-message-arg/commit.sh
vendored
Executable file
11
.github/fixtures/test-bump-unreleased-with-tag-message-arg/commit.sh
vendored
Executable file
@ -0,0 +1,11 @@
|
||||
#!/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_COMMITTER_DATE="2022-04-06 01:25:10" git commit --allow-empty -m "fix: fix feature 1"
|
||||
git tag v0.1.0
|
||||
GIT_COMMITTER_DATE="2022-04-06 01:25:11" git commit --allow-empty -m "feat(gui): add feature 2"
|
||||
GIT_COMMITTER_DATE="2022-04-06 01:25:12" git commit --allow-empty -m "fix(gui): fix feature 2"
|
||||
git tag v0.2.0
|
||||
GIT_COMMITTER_DATE="2022-04-06 01:25:13" git commit --allow-empty -m "test: add tests"
|
13
.github/fixtures/test-bump-unreleased-with-tag-message-arg/expected.md
vendored
Normal file
13
.github/fixtures/test-bump-unreleased-with-tag-message-arg/expected.md
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [0.2.1]
|
||||
|
||||
Some text
|
||||
|
||||
### Test
|
||||
|
||||
- Add tests
|
||||
|
||||
<!-- generated by git-cliff -->
|
2
.github/workflows/test-fixtures.yml
vendored
2
.github/workflows/test-fixtures.yml
vendored
@ -80,6 +80,8 @@ jobs:
|
||||
- fixtures-name: test-cli-arg-ignore-tags
|
||||
command: --ignore-tags ".*beta"
|
||||
- fixtures-name: test-tag-message
|
||||
- fixtures-name: test-bump-unreleased-with-tag-message-arg
|
||||
command: --bump --unreleased --with-tag-message "Some text"
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
|
@ -142,6 +142,15 @@ pub struct Opt {
|
||||
num_args(1..)
|
||||
)]
|
||||
pub with_commit: Option<Vec<String>>,
|
||||
/// Sets custom message to the latest release (will overwrite original tag's
|
||||
/// message if exists).
|
||||
#[arg(
|
||||
long,
|
||||
env = "GIT_CLIFF_WITH_TAG_MESSAGE",
|
||||
value_name = "MSG",
|
||||
num_args = 0..=1,
|
||||
)]
|
||||
pub with_tag_message: Option<String>,
|
||||
/// Sets the tags to ignore in the changelog.
|
||||
#[arg(long, env = "GIT_CLIFF_IGNORE_TAGS", value_name = "PATTERN")]
|
||||
pub ignore_tags: Option<Regex>,
|
||||
|
@ -292,6 +292,13 @@ fn process_repository<'a>(
|
||||
}
|
||||
}
|
||||
|
||||
// Set custom message to the latest release.
|
||||
if let Some(message) = &args.with_tag_message {
|
||||
if let Some(latest_release) = releases.iter_mut().last() {
|
||||
latest_release.message = Some(message.to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
// Set the previous release if the first release does not have one set.
|
||||
if !releases.is_empty() &&
|
||||
releases
|
||||
|
Loading…
Reference in New Issue
Block a user