feat(commits): add commit message normalizer and validator#185
Open
iamlasse wants to merge 1 commit into
Open
Conversation
Implement a Conventional Commits parser, normalizer, and validator in internal/commits. The normalizer rewrites a raw message into the canonical format (lowercase type and scope, imperative subject clamped to 72 chars, hard-wrapped body, preserved trailers with stable ordering) and is idempotent on already-conforming input. The validator reports structured violations for missing/unknown type, oversize subject, non-imperative verb, trailing period, and unwrapped body. Also adds cmd/commit-lint (powers the hook), an installable commit-msg hook (scripts/install-commit-msg.sh), and docs/commit-messages.md listing allowed types and scopes. Unit tests cover idempotency, normalization, malformed input, trailer preservation, subject clamping, and wrapping. 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.
Summary
Adds a Conventional Commits message normalizer/validator to the project, with an installable enforcement hook and documentation.
internal/commits: a parser/normalizer/validator packageNormalize(raw) (string, error)rewrites a raw message into canonical form: lowercase type and scope, imperative subject clamped to 72 chars, hard-wrapped body (≤72 cols), preserved trailers with stable ordering. Idempotent on already-conforming input.Validate(raw) []Violationreports structured violations: missing/unknown type, oversize subject, non-imperative verb, trailing period, unwrapped body, malformed trailer.Conforms(raw) boolconvenience predicate.cmd/commit-lint: standalone validator that reads the commit message file (Git commit-msg hook contract) and exits non-zero on violations.scripts/install-commit-msg.sh: installs a.git/hooks/commit-msghook that runscmd/commit-linton every commit.docs/commit-messages.md: the convention, allowed types/scopes, examples, and hook install instructions.Test plan
go build ./...go vet ./...gofmt -lcleango test ./internal/commits/...— 22 unit tests covering idempotency, normalization, malformed input, trailer preservation, subject clamping, body wrapping, and validator codes.cmd/commit-lint: well-formed message exits 0; malformed message exits 1 and prints violations.Closes the commit-normalize task.
Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift
Automated by nightshift