feat(parser): allow commits to be parsed by multiple parsers - #1611
Open
ChrisJr404 wants to merge 1 commit into
Open
feat(parser): allow commits to be parsed by multiple parsers#1611ChrisJr404 wants to merge 1 commit into
ChrisJr404 wants to merge 1 commit into
Conversation
Add an opt-in `continue` field to commit parsers. When set, parsing keeps going after a parser matches, so a commit can be handled by more than one parser in order (e.g. one sets the scope, the next sets the group). Default behavior is unchanged: the first matching parser wins and short-circuits.
Contributor
Author
|
The Test suite red here isn't coming from this PR. All the tests pass; it's the codecov upload step failing on gpg signature verification (Can't check signature: No public key), the same failure that's red on main right now. Should sort itself out on a re-run. |
Owner
|
Hey, thanks for the PR! There are a couple of issues:
Does
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #117. Adds an opt-in
continuefield on commit parsers so a commit can be processed by more than one parser instead of stopping at the first match.Today the parser loop returns as soon as a commit matches a parser, so you can't have one parser set the scope and a later one set the group. The config from #117 (
{ message = "(scope)", scope = "..." }followed by{ message = "^feat", group = "..." }) only ever applies the first parser and the group is never set. The only workaround is spelling out every scope/group combination in a single parser, which gets tedious fast.With this change you mark the parsers you want to compose with
continue = true:A parser with
continue = trueonly writes the fields it actually sets (here justscope), then parsing moves on to the next parser, which fills in the group. Parsers without the flag behave exactly as before: first match wins and the loop short-circuits. So existing configs are untouched — the flag defaults to unset.One thing worth a look: when several parsers should stack, each contributing one, they all need
continue = true(a parser without it is treated as terminal and overwrites with its own fields, matching the current overwrite semantics). That felt like the least surprising reading of the issue, but I'm happy to change the shape if you had something else in mind — the thread left the design open ("needs some brainstorming").Also handled the filtering edge case: a commit matched only by
continueparsers (e.g. one that just sets a scope, no group) is kept whenfilter_commitsis on, same as a normal match would be.Tests in
git-cliff-core/src/commit.rs(parse_commit_multiple_parsers) cover three things: the default first-match-wins path is unchanged, scope-then-group composition works with the flag, and a scope-onlycontinueparser survives filtering.cargo test -p git-cliff-coreis green (73 passed),cargo clippy --all-featuresclean, docs added underconfiguration/git.md.