fix(commits): restrict trailer handling to the final body block - #232
Open
iamlasse wants to merge 2 commits into
Open
fix(commits): restrict trailer handling to the final body block#232iamlasse wants to merge 2 commits into
iamlasse wants to merge 2 commits into
Conversation
Add internal/commits with a pure Normalize function enforcing the project's Conventional Commits rules: known type set (feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert), optional scope, lowercase imperative subject limited to 72 chars with no trailing period, comment stripping, body wrapping at 72 columns, and verbatim preservation of git trailer blocks. Wire it into the CLI as 'nightshift commit normalize' (positional, --file, and stdin sources; --check validates only), ship a commit-msg hook under scripts/, install it via 'make install-hooks', and add a CI job that validates every commit in a pull request. Document the format in docs/commit-messages.md. Nightshift-Task: commit-normalize Nightshift-Ref: https://github.com/marcus/nightshift
Address review feedback on the commit message normalizer: - wrapBody no longer hoists Token-shaped lines out of mid-body prose; git only recognizes trailers in the last block, so only the final block is kept verbatim as trailers (and only when every line in it is trailer-shaped); anything else is wrapped in place, preserving order - the CI commit-messages job uses git rev-list --no-merges so GitHub merge commits do not fail validation - the 72-char subject limit is checked after the trailing period is trimmed, matching the documented auto-fix - malformed scopes such as feat(a)b) or feat() are rejected with a new ErrInvalidScope sentinel Nightshift-Task: commit-normalize Nightshift-Ref: https://github.com/marcus/nightshift
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.
Follow-up to #231 addressing the review's blocking findings on the commit message normalizer.
Blocking fixes
1. Trailers are only recognized in the last body block.
wrapBodypreviously treated anyToken: value-shaped line anywhere in the body as a git trailer and hoisted it into its own block, silently reordering message content — a mid-paragraphNote: ...line caused the prose after it to be merged into the preceding paragraph with the "trailer" moved below. Now the body is split into blank-line-separated blocks and only the final block is treated as a trailer block, and only when every line in it is trailer-shaped (matching where git itself recognizes trailers). Everything else is wrapped in place, preserving order. A trailer-shaped block followed by more prose is wrapped as prose.2. CI skips merge commits. The
commit-msgjob now usesgit rev-list --no-merges, so GitHub-generatedMerge pull request #N ...commits no longer fail validation (verified: such a subject exits non-zero undercommit normalize --check, and--no-mergesdrops it from the range).Minor fixes
.trims to a conforming 72 instead of being rejected — matching the documented auto-fix.feat(a)b):,feat():) are rejected with a newErrInvalidScopesentinel.Tests
New cases: mid-body
Note:line stays prose in place; trailer-shaped block followed by prose wrapped as prose; trailing-period subject at the boundary; malformed and empty scopes; extra idempotency cases. Full suite,go vet,gofmt, andgo buildpass; the commit-msg hook rewrite and rejection paths were exercised end-to-end.Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift
Automated by nightshift