feat(commits): add Conventional Commits message normalizer - #222
Open
iamlasse wants to merge 3 commits into
Open
feat(commits): add Conventional Commits message normalizer#222iamlasse wants to merge 3 commits into
iamlasse wants to merge 3 commits into
Conversation
Add internal/commits with pure Normalize/validate functions enforcing the project's Conventional Commits rules (known type set, lowercase type, lowercase subject, 72-char subject limit, whitespace trimming, and 72-column body wrapping). Wire it into the CLI as 'nightshift commit normalize' (positional, --file, and stdin sources; --check to validate only), ship a commit-msg git hook under scripts/, and document the format and installation in docs/commit-messages.md. Nightshift-Task: commit-normalize Nightshift-Ref: https://github.com/marcus/nightshift
Add internal/commits with pure Normalize/Validate functions enforcing the project's Conventional Commits rules: a known type set (feat, fix, docs, style, refactor, test, chore, perf, build, ci, revert), lowercase type and subject, a 72-character subject limit, whitespace trimming, and 72-column body wrapping. Trivially fixable issues are rewritten automatically; missing or unknown types, missing subjects, and overlong subjects are rejected with actionable errors. Wire the package into the CLI as 'nightshift commit normalize' (positional, --file, and stdin sources; --check validates with a diff-style report and exits non-zero without modifying anything; --file rewrites the message file in place). Ship an installable scripts/commit-msg.sh hook, extend 'make install-hooks' to install it, and document the format, command, and hook in docs/commit-messages.md with a pointer from the README. Nightshift-Task: commit-normalize Nightshift-Ref: https://github.com/marcus/nightshift
The commit-msg hook invoked its go-run fallback as a single quoted string, so the exec failed and every commit was rejected with a misleading formatting error. The hook now stores the command as an array, probes that the tool runs before blaming the message, uses a mktemp'd error file cleaned up by a trap, and distinguishes tooling failures from format rejections. The normalizer now accepts and preserves Conventional Commits breaking-change markers (feat!:, feat(scope)!:), checks the 72-char subject limit after trailing-period trimming, measures body wrap width in runes rather than bytes, and keeps trailing trailer/footer blocks verbatim instead of re-wrapping them. Nightshift-Task: commit-normalize Nightshift-Ref: https://github.com/marcus/nightshift
Author
|
Review fixes pushed ( Hook fallback bug (confirmed): Minor items:
gofmt/vet/build/tests all pass; new table-driven tests cover each fix. |
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.
Summary
Standardizes commit messages across the repo with a small, dependency-free normalizer plus tooling around it.
internal/commits— pureNormalize(msg) (string, error)andValidate(msg) errorenforcing Conventional Commits:type(scope)?: subjectrestricted to a known type set:feat,fix,docs,style,refactor,test,chore,perf,build,ci,revertNormalize(Normalize(m)) == Normalize(m)nightshift commit normalize— cobra subcommand reading the message from a positional arg,--file, or stdin; with--filethe normalized message is written back in place, otherwise printed to stdout.--checkvalidates only, printing a diff-style report and exiting non-zero without modifying anything.scripts/commit-msg.sh— installable git commit-msg hook that normalizes the message file in place and rejects unfixable messages;make install-hooksnow installs it alongside the pre-commit hook:docs/commit-messages.mdcovers the format rules, examples, CLI usage, and hook installation; the README links to it.Testing
gofmt -l .clean,go vet ./...clean,go build ./...succeedsgo test ./internal/commits/... ./cmd/nightshift/...passes (table-driven tests: idempotency, casing, wrapping, all error cases,Validate)--file/--checkflows and the hook itself (this commit was normalized by it)Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift