Skip to content

feat(commits): Conventional Commits normalizer + commit-msg hook#179

Open
iamlasse wants to merge 1 commit into
marcus:mainfrom
iamlasse:feat/commit-normalize-iter2
Open

feat(commits): Conventional Commits normalizer + commit-msg hook#179
iamlasse wants to merge 1 commit into
marcus:mainfrom
iamlasse:feat/commit-normalize-iter2

Conversation

@iamlasse

Copy link
Copy Markdown

Summary

Adds a reusable, dependency-free Conventional Commits message normalizer, exposed as nightshift commit normalize and backed by an installable commit-msg git hook.

This is iteration 2 of the commit-normalize task. It fixes the two defects found in review of the prior attempt:

  1. --check is no longer a no-op. --check now validates only — it prints an ok confirmation instead of the rewritten message, and exits non-zero on validation failure. The default (no flag) path still prints the normalized message.
  2. Conventional Commits 1.0.0 breaking-change markers are accepted. feat!: and feat(api)!: now parse, validate, and re-emit correctly instead of failing with "commit type is not in the allowed set".

Changes

  • internal/commits/normalizer.go — pure Normalize with table-driven validation (type set, scope, ! marker, subject length/capitalization, comment stripping, trailing whitespace/period, 72-col body wrapping).
  • internal/commits/normalizer_test.go — table-driven tests + idempotency, including the breaking-change marker cases.
  • cmd/nightshift/commands/commit.gonightshift commit normalize [--check] [--file FILE] [MSG].
  • scripts/commit-msg.sh — installable hook (rewrites the message file; rejects unfixable messages; uses mktemp for its scratch file).
  • docs/commit-messages.md and Makefile (install-hooks) — docs + install wiring.

Verification

  • `go build ./...`, `go vet ./...`, `go test ./...` all pass; `gofmt` clean.
  • Behavioral checks:
    • `feat!: redesign api` and `feat(api)!: redesign api` → normalized and preserved.
    • `--check` prints `ok` (exit 0); default prints the normalized message.
    • Invalid messages exit non-zero in both modes.

Closes the commit-normalize task.

Add a dependency-free internal/commits package that validates and rewrites
commit messages to Conventional Commits form, expose it as
`nightshift commit normalize`, and ship an installable commit-msg hook.

Parse and preserve the Conventional Commits 1.0.0 breaking-change marker
(`feat!:` / `feat(api)!:`). Make the `--check` flag validate-only: it emits
an `ok` confirmation instead of rewriting the message, with a non-zero exit
on validation failure.

Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant