orhun / git-cliff

A highly customizable Changelog Generator that follows Conventional Commit specifications ⛰️
https://git-cliff.org
Apache License 2.0
8.71k stars 184 forks source link

Configurable set of prefixes that result in bump with `--bump` flag #405

Closed hauleth closed 6 months ago

hauleth commented 8 months ago

Is your feature request related to a problem? Please describe.

I am using Conventional Commits with a little twist - instead of feat I use ft to not waste 2 letters of the 72 (that is my upper limit for commit title) towards one of the most frequently used commit tag. However that prevents me from using --bump flag as expected, as it requires feat tag to be used.

Describe the solution you'd like

Within git.commit_parsers there could be option bump that could take value "major", "minor", "patch" and would bump respective value when using --bump option. It would simply walk through commits and pick largest of the three that would match any commit in the list. This would also allow it to be applicable to non Conventional Commits repositories.

Describe alternatives you've considered

Something similar to changelog.postprocessors could be used as well to rewrite in memory commit messages before further processing, but I think that would be a little bit overkill.

welcome[bot] commented 8 months ago

Thanks for opening your first issue at git-cliff! Be sure to follow the issue template! ⛰️

orhun commented 8 months ago

Hello! 🐻

Have you considered using commit preprocessors to replace the ft with feat? I think it would be more straightforward than adding major, minor and patch values to the commit parsers.

hauleth commented 8 months ago

I will test that out.

hauleth commented 8 months ago

It seems that this also doesn't work.

With config:

[git]
commit_preprocessors = [
  { pattern = '^ft', replace = 'feat' },
]

History:

c1926c3 chore: replace git-chglog with git-cliff
5e7ffc9 chore: update GitHub Actions
b8b5ecd chore: update CHANGELOG [skip ci]
6209033 ft: ignore generated functions
dc4839e chore: update CHANGELOG [skip ci]
6f9eb52 ft: Allow for specifying checks in mix config

I get:

# Changelog

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

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.1] - 2023-12-26

### Features

- Ignore generated functions

### Miscellaneous Tasks

- Update GitHub Actions
- Replace git-chglog with git-cliff

## [1.0.0] - 2023-12-13

### Features

- Allow for specifying checks in mix config

## [0.4.1] - 2023-06-29

### Bug Fixes

- Resolve issue with unused analyzer reporting false positives

While I would expect version to be 1.1.0.

orhun commented 8 months ago

Hey again! Thanks for testing it, I thought it might work but realized it only takes the raw commits into account.

So I changed that behavior in #408 and now it is should work as expected. Feel free to build from source and test it out.

Reiterating myself again, I think doing this is less complex and more straightforward than having configurable prefixes for --bump flag. Especially if you consider that that feature depends on another library.

hauleth commented 8 months ago

It is within tolerable behaviour for me. It will probably not help people that use non-conventional commits, but for my needs it will work.

hauleth commented 8 months ago

It seems to work on main now.

orhun commented 8 months ago

Good to know, thanks for testing!

welpo commented 8 months ago

Came here ready to open an issue for this. Can confirm the fix is working for me too.

Just to share my use-case: I use gitmoji with conventional commits. A pre-processor allows me to remove the gitmoji for parsing. This works great for the changelog, but I was seeing the same issue when calculating the next version.

Thanks for a fantastic piece of software and quick fixes, @orhun!!!

P.S: If anyone's curious about the pre-processor for gitmoji (removes adjacent whitespace[s]):

commit_preprocessors = [
  # Remove gitmoji, both actual UTF emoji and :emoji:
  { pattern = ' *(:\w+:|[\p{Emoji_Presentation}\p{Extended_Pictographic}\u{200D}]) *', replace = "" },
]
orhun commented 8 months ago

@welpo I'm glad the fix worked for you and thanks for sharing your config!

One idea that I had in the back of my mind is to have a "Tips & Tricks" section in the documentation for sharing config snippets like this but haven't got around to do it yet. (Also mentioned in https://github.com/orhun/git-cliff/issues/143#issuecomment-1858945623)

welpo commented 8 months ago

That's a good idea! It took me a while to figure out the regex, and I know I'm not the only one combining conventional commits and gitmoji.

orhun commented 8 months ago

I added that section in 82e93c26deaa0eeebe0f46f91fa2d35154bcfe2c

https://git-cliff.org/docs/tips-and-tricks