feat(commits): add Conventional Commits message normalizer - #218
Open
iamlasse wants to merge 1 commit into
Open
Conversation
Add a pure internal/commits package that validates and rewrites commit messages into canonical Conventional Commits form: - <type>(<scope>): <subject> header with allowed type set - lowercase type, non-capitalized subject, max 72-char subject - whitespace/trailing-period cleanup and 72-column body wrapping - git comment stripping and idempotent normalization - sentinel errors (ErrEmptyMessage, ErrMissingType, ErrUnknownType, ErrMissingSubject, ErrSubjectTooLong, ErrSubjectLowercase) matched via errors.Is Wire a 'nightshift commit normalize' cobra subcommand (positional arg, --file, stdin; --check validate-only mode) and ship an installable scripts/commit-msg.sh hook that normalizes the message file in place and blocks invalid messages. make install-hooks now installs both hooks. Rules and usage are documented in docs/commit-messages.md. Restored from unmerged commit c26c5fd with fixes: hook now reports its friendly error instead of being silenced by set -e, --check no longer prints the rewritten message, CLI errors print once without usage spam, and install-hooks links the commit-msg hook. Nightshift-Task: commit-normalize Nightshift-Ref: https://github.com/marcus/nightshift Co-Authored-By: Claude <noreply@anthropic.com>
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 message format with a Conventional Commits normalizer, restored from the unmerged commit
c26c5fdand reviewed against main with three fixes applied.Format rules (
internal/commits)<type>(<scope>): <subject>per Conventional Commits 1.0.0feat,fix,docs,style,refactor,test,chore,perf,build,ci#comments strippedErrEmptyMessage,ErrMissingType,ErrUnknownType,ErrMissingSubject,ErrSubjectTooLong,ErrSubjectLowercase) matched viaerrors.IsCLI
Hook
make install-hooksnow installs bothpre-commitandcommit-msg. The commit-msg hook normalizes the message file in place before the commit is created and blocks messages it cannot fix (missing/unknown type, capitalized or overlong subject). Bypass withgit commit --no-verify.Docs:
docs/commit-messages.md.Fixes applied on top of c26c5fd
scripts/commit-msg.sh:set -eaborted the script before the friendly error could print — capture insideif !and use amktemperror file instead of a fixed/tmppathcommit normalize --check: no longer prints the rewritten message (validate-only)Makefileinstall-hooksactually links the commit-msg hook (docs referenced it but it wasn't installed)Testing
go build ./...✅go vet ./...✅gofmt -l .clean ✅go test ./...all packages pass ✅ (table-driven tests ininternal/commits/normalizer_test.go: happy path, auto-fix cases, every sentinel error, idempotency, allowed-type set)--file/stdin/--checkpaths, and the hook rewriting a message file in place + rejecting an invalid one🤖 Generated with Claude Code