Skip to content

Commit

Permalink
feat(args): add --with-tag-message
Browse files Browse the repository at this point in the history
to allow setting the message of the last release in the context
  • Loading branch information
MeitarR committed Jun 21, 2024
1 parent b5b1d3c commit b7a273f
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -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" },
]
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions .github/workflows/test-fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 45 additions & 36 deletions git-cliff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct Opt {
help = "Prints help information",
help_heading = "FLAGS"
)]
pub help: Option<bool>,
pub help: Option<bool>,
#[arg(
short = 'V',
long,
Expand All @@ -73,10 +73,10 @@ pub struct Opt {
help = "Prints version information",
help_heading = "FLAGS"
)]
pub version: Option<bool>,
pub version: Option<bool>,
/// Increases the logging verbosity.
#[arg(short, long, action = ArgAction::Count, alias = "debug", help_heading = Some("FLAGS"))]
pub verbose: u8,
pub verbose: u8,
/// Writes the default configuration file to cliff.toml
#[arg(
short,
Expand All @@ -85,7 +85,7 @@ pub struct Opt {
num_args = 0..=1,
required = false
)]
pub init: Option<Option<String>>,
pub init: Option<Option<String>>,
/// Sets the configuration file.
#[arg(
short,
Expand All @@ -95,7 +95,7 @@ pub struct Opt {
default_value = DEFAULT_CONFIG,
value_parser = Opt::parse_dir
)]
pub config: PathBuf,
pub config: PathBuf,
/// Sets the working directory.
#[arg(
short,
Expand All @@ -104,7 +104,7 @@ pub struct Opt {
value_name = "PATH",
value_parser = Opt::parse_dir
)]
pub workdir: Option<PathBuf>,
pub workdir: Option<PathBuf>,
/// Sets the git repository.
#[arg(
short,
Expand All @@ -114,45 +114,54 @@ pub struct Opt {
num_args(1..),
value_parser = Opt::parse_dir
)]
pub repository: Option<Vec<PathBuf>>,
pub repository: Option<Vec<PathBuf>>,
/// Sets the path to include related commits.
#[arg(
long,
env = "GIT_CLIFF_INCLUDE_PATH",
value_name = "PATTERN",
num_args(1..)
)]
pub include_path: Option<Vec<Pattern>>,
pub include_path: Option<Vec<Pattern>>,
/// Sets the path to exclude related commits.
#[arg(
long,
env = "GIT_CLIFF_EXCLUDE_PATH",
value_name = "PATTERN",
num_args(1..)
)]
pub exclude_path: Option<Vec<Pattern>>,
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>,
pub tag_pattern: Option<Regex>,
/// Sets custom commit messages to include in the changelog.
#[arg(
long,
env = "GIT_CLIFF_WITH_COMMIT",
value_name = "MSG",
num_args(1..)
)]
pub with_commit: Option<Vec<String>>,
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>,
pub ignore_tags: Option<Regex>,
/// Sets commits that will be skipped in the changelog.
#[arg(
long,
env = "GIT_CLIFF_SKIP_COMMIT",
value_name = "SHA1",
num_args(1..)
)]
pub skip_commit: Option<Vec<String>>,
pub skip_commit: Option<Vec<String>>,
/// Prepends entries to the given changelog file.
#[arg(
short,
Expand All @@ -161,7 +170,7 @@ pub struct Opt {
value_name = "PATH",
value_parser = Opt::parse_dir
)]
pub prepend: Option<PathBuf>,
pub prepend: Option<PathBuf>,
/// Writes output to the given file.
#[arg(
short,
Expand All @@ -172,7 +181,7 @@ pub struct Opt {
num_args = 0..=1,
default_missing_value = DEFAULT_OUTPUT
)]
pub output: Option<PathBuf>,
pub output: Option<PathBuf>,
/// Sets the tag for the latest version.
#[arg(
short,
Expand All @@ -181,13 +190,13 @@ pub struct Opt {
value_name = "TAG",
allow_hyphen_values = true
)]
pub tag: Option<String>,
pub tag: Option<String>,
/// Bumps the version for unreleased changes.
#[arg(long, help_heading = Some("FLAGS"))]
pub bump: bool,
pub bump: bool,
/// Prints bumped version for unreleased changes.
#[arg(long, help_heading = Some("FLAGS"))]
pub bumped_version: bool,
pub bumped_version: bool,
/// Sets the template for the changelog body.
#[arg(
short,
Expand All @@ -196,38 +205,38 @@ pub struct Opt {
value_name = "TEMPLATE",
allow_hyphen_values = true
)]
pub body: Option<String>,
pub body: Option<String>,
/// Processes the commits starting from the latest tag.
#[arg(short, long, help_heading = Some("FLAGS"))]
pub latest: bool,
pub latest: bool,
/// Processes the commits that belong to the current tag.
#[arg(long, help_heading = Some("FLAGS"))]
pub current: bool,
pub current: bool,
/// Processes the commits that do not belong to a tag.
#[arg(short, long, help_heading = Some("FLAGS"))]
pub unreleased: bool,
pub unreleased: bool,
/// Sorts the tags topologically.
#[arg(long, help_heading = Some("FLAGS"))]
pub topo_order: bool,
pub topo_order: bool,
/// Disables the external command execution.
#[arg(long, help_heading = Some("FLAGS"))]
pub no_exec: bool,
pub no_exec: bool,
/// Prints changelog context as JSON.
#[arg(short = 'x', long, help_heading = Some("FLAGS"))]
pub context: bool,
pub context: bool,
/// Strips the given parts from the changelog.
#[arg(short, long, value_name = "PART", value_enum)]
pub strip: Option<Strip>,
pub strip: Option<Strip>,
/// Sets sorting of the commits inside sections.
#[arg(
long,
value_enum,
default_value_t = Sort::Oldest
)]
pub sort: Sort,
pub sort: Sort,
/// Sets the commit range to process.
#[arg(value_name = "RANGE", help_heading = Some("ARGS"))]
pub range: Option<String>,
pub range: Option<String>,
/// Sets the GitHub API token.
#[arg(
long,
Expand All @@ -236,7 +245,7 @@ pub struct Opt {
hide_env_values = true,
hide = !cfg!(feature = "github"),
)]
pub github_token: Option<SecretString>,
pub github_token: Option<SecretString>,
/// Sets the GitHub repository.
#[arg(
long,
Expand All @@ -245,7 +254,7 @@ pub struct Opt {
value_name = "OWNER/REPO",
hide = !cfg!(feature = "github"),
)]
pub github_repo: Option<RemoteValue>,
pub github_repo: Option<RemoteValue>,
/// Sets the GitLab API token.
#[arg(
long,
Expand All @@ -254,7 +263,7 @@ pub struct Opt {
hide_env_values = true,
hide = !cfg!(feature = "gitlab"),
)]
pub gitlab_token: Option<SecretString>,
pub gitlab_token: Option<SecretString>,
/// Sets the GitLab repository.
#[arg(
long,
Expand All @@ -263,7 +272,7 @@ pub struct Opt {
value_name = "OWNER/REPO",
hide = !cfg!(feature = "gitlab"),
)]
pub gitlab_repo: Option<RemoteValue>,
pub gitlab_repo: Option<RemoteValue>,
/// Sets the Gitea API token.
#[arg(
long,
Expand All @@ -272,7 +281,7 @@ pub struct Opt {
hide_env_values = true,
hide = !cfg!(feature = "gitea"),
)]
pub gitea_token: Option<SecretString>,
pub gitea_token: Option<SecretString>,
/// Sets the GitLab repository.
#[arg(
long,
Expand All @@ -281,7 +290,7 @@ pub struct Opt {
value_name = "OWNER/REPO",
hide = !cfg!(feature = "gitea"),
)]
pub gitea_repo: Option<RemoteValue>,
pub gitea_repo: Option<RemoteValue>,
/// Sets the Bitbucket API token.
#[arg(
long,
Expand All @@ -290,7 +299,7 @@ pub struct Opt {
hide_env_values = true,
hide = !cfg!(feature = "bitbucket"),
)]
pub bitbucket_token: Option<SecretString>,
pub bitbucket_token: Option<SecretString>,
/// Sets the Bitbucket repository.
#[arg(
long,
Expand All @@ -299,7 +308,7 @@ pub struct Opt {
value_name = "OWNER/REPO",
hide = !cfg!(feature = "bitbucket"),
)]
pub bitbucket_repo: Option<RemoteValue>,
pub bitbucket_repo: Option<RemoteValue>,
}

/// Custom type for the remote value.
Expand Down
7 changes: 7 additions & 0 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b7a273f

Please sign in to comment.