orhun / git-cliff

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

allow limiting commits to scoped ones #749

Open tobiaskohlbau opened 3 months ago

tobiaskohlbau commented 3 months ago

Is there an existing issue or pull request for this?

Feature description

I have a monorepo where multiple projects are mixed into each other. This results in include and exclude path not being an option. I've tried to set a default scope for each commit parser and used scopes in each commit in order to assign it either to a specific project or an overlapping one. So for e.g. if a commit is affecting multiple projects we drop the scope within the commit title and fall back to a default scope called overlapping. The concrete problem is the lack of an option to filter commits by its scope in order to say for e.g. render the changelog for project A and every potentially overlapping commit.

Desired solution

It would be nice to have some kind of scope option to specify either in configuration or by cli argument to say: please filter every commit by the following scopes.

The desired call would look for e.g. like:

git cliff --scope "Project A" --scope overlapping --tag-pattern "projecta/.*"

Alternatives considered

I'm not aware of a good alternative, but please let me know if something else comes to mind.

Additional context

I've tinkered with the repository and tried to implement a proof of concept in https://github.com/tobiaskohlbau/git-cliff/commit/613350488a2014bb665bfcdac1d9e8e4b7baebf6. I would like to work on this if it gets accepted but most likely need some guidance as I've never done Rust before (Best practices etc.).

welcome[bot] commented 3 months ago

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

orhun commented 3 weeks ago

Hey! Thanks for the issue and sorry for the delayed response.

Have you tried using the scope filter within commit_parsers, like so:

[git]
# regex for parsing and grouping commits
commit_parsers = [
  { message = "(www)", scope = "Application" }
]

Then you can use this scope for grouping in the template:

https://github.com/orhun/git-cliff/blob/82cc09ff75166b5121f9b446f6ef8216a625c858/examples/scoped.toml#L20-L25

Check out the scoped template example to see if it works for you.

Let me know if there is anything else that I can help :)

tobiaskohlbau commented 2 weeks ago

Hi thanks for the reply.

IIRC the issue is that it's not possible to produce an changelog for a specific scope. The issue lies on the side of the collection not on the side of generation. Let's assume one releases Project A which has scope "projecta". In addition to everything scoped it's also desired to show common changes in such changelog. The changelog for each project should be generated by different invocations (different changelogs) as it's attached to the release for such subproject. Normally this would be done with include or exclude paths, to only include files changed within a subfolder. But in my scenario changes to common files outside the directory should be shown as well.

I'm suggesting filtering the commits similar to "include/exclude" on it's scope before passing it to the generating step.

orhun commented 2 weeks ago

I see, I still feel like this might be somehow possible currently.

For me to understand this better and kickstart the implementation, can you help me come up with a test fixture?

I need a list of commits as follows, example configuration and expected output. e.g.

git init
git commit --allow-empty -m "Initial commit"

touch scope-a/x
git add scope-a
git commit  -m "feat(scope-a): add feature 1"

touch scope-a/y
git add scope-a
git commit  -m "feat(scope-b): add feature 1"

git tag v0.1.0

and then I need the command e.g. git cliff --include-path scope-a etc. etc. and lastly what you expect to see in the output 🐻