Skip to content

Commit

Permalink
feat(args): add --with-commit argument for including custom commit …
Browse files Browse the repository at this point in the history
…messages in changelog
  • Loading branch information
orhun committed Dec 11, 2021
1 parent 316c11b commit e4c60b2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ git-cliff [FLAGS] [OPTIONS] [RANGE]
-r, --repository <PATH> Sets the git repository [env: REPOSITORY=]
--include-path <PATTERN>... Sets the path to include related commits [env: INCLUDE_PATH=]
--exclude-path <PATTERN>... Sets the path to exclude related commits [env: EXCLUDE_PATH=]
--with-commit <MSG>... Sets custom commit messages to include in the changelog [env: WITH_COMMIT=]
-p, --prepend <PATH> Prepends entries to the given changelog file [env: PREPEND=
-o, --output <PATH> Writes output to the given file [env: OUTPUT=]
-t, --tag <TAG> Sets the tag for the latest version [env: TAG=]
Expand Down Expand Up @@ -221,6 +222,18 @@ git cliff --include-path "**/*.toml" --include-path "*.md"
git cliff --exclude-path ".github/*"
```

Generate a changelog that includes yet unexisting commit messages:

```sh
commit_msg="chore(release): update CHANGELOG.md for 1.0.0"

# You might need to include the commit messages that do not exist
# for testing purposes or solving the chicken-egg problem.
git cliff --with-commit "$commit_msg"

git commit -m "$commit_msg"
```

Sort the commits inside sections:

```sh
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 @@ -43,6 +43,9 @@ pub struct Opt {
/// Sets the path to exclude related commits.
#[structopt(long, env, value_name = "PATTERN")]
pub exclude_path: Option<Vec<Pattern>>,
/// Sets custom commit messages to include in the changelog.
#[structopt(long, env, value_name = "MSG")]
pub with_commit: Option<Vec<String>>,
/// Prepends entries to the given changelog file.
#[structopt(short, long, env, value_name = "PATH")]
pub prepend: Option<PathBuf>,
Expand Down
11 changes: 11 additions & 0 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,17 @@ pub fn run(mut args: Opt) -> Result<()> {
}
}

// Add custom commit messages to the latest release.
if let Some(custom_commits) = args.with_commit {
if let Some(latest_release) = releases.iter_mut().last() {
custom_commits.iter().for_each(|commit_message| {
latest_release
.commits
.push(Commit::new(String::new(), commit_message.to_string()))
});
}
}

// Set the previous release if needed.
if args.latest {
if let Some((commit_id, version)) = tags.get_index(tags.len() - 2) {
Expand Down

0 comments on commit e4c60b2

Please sign in to comment.