feat(commits): add Conventional Commits message normalizer - #213
Open
iamlasse wants to merge 1 commit into
Open
Conversation
Add an internal/commits package with a pure, idempotent Normalize that parses, validates, and rewrites commit messages into canonical Conventional Commits form (lowercased type, optional scope, lowercase <=72-char subject, comment stripping, 72-column body wrapping). Wire it into a 'nightshift commit normalize' cobra subcommand (positional/--file/stdin sources, --check validate-only flag), add a commit-msg git hook installed via 'make install-hooks', and document the format and tooling in docs/commit-messages.md. 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 to
nightshift: a pure Go library, a CLI subcommand, a git hook, and docs. This keeps the project's history consistent and lets tooling derive changelogs automatically.Changes
internal/commits— new package with an idempotentNormalize(msg) (string, error). Parses, validates, and rewrites messages into canonical<type>(<scope>): <subject>form plus a 72-column-wrapped body. Lowercases the type, enforces the allowed type set (feat fix docs style refactor test chore perf build ci), rejects overlong/capitalized subjects, strips git#comment lines, and returns typed errors (ErrEmptyMessage,ErrMissingType,ErrUnknownType,ErrMissingSubject,ErrSubjectTooLong,ErrSubjectLowercase).Normalize(Normalize(m)) == Normalize(m).cmd/nightshift/commands/commit.go—nightshift commit normalize [MESSAGE]cobra subcommand. Reads the message from a positional arg,--file/-f, or stdin (in that order).--check/-cvalidates without emitting the rewrite. Errors go to stderr with a non-zero exit.scripts/commit-msg.sh— gitcommit-msghook that runsnightshift commit normalize --fileon the message file, rewrites it into canonical form, and rejects non-conformant messages.Makefile—install-hooksnow also symlinks the commit-msg hook (alongside the existing pre-commit hook).docs/commit-messages.md— documents the format, allowed types, thecommit normalizecommand, and hook installation.Verification
gofmt -l .cleango vet ./...cleango build ./...cleango test ./internal/commits/...andgo test ./cmd/nightshift/commands/...pass (table-driven tests cover valid messages, scope handling, type lowercasing, trailing-period stripping, body wrapping, comment stripping, idempotency, and every error path)🤖 Generated with Claude Code
Automated by nightshift