Skip to content

feat(commits): add Conventional Commits message normalizer#178

Open
iamlasse wants to merge 1 commit into
marcus:mainfrom
iamlasse:feat/commit-normalizer-lib
Open

feat(commits): add Conventional Commits message normalizer#178
iamlasse wants to merge 1 commit into
marcus:mainfrom
iamlasse:feat/commit-normalizer-lib

Conversation

@iamlasse

Copy link
Copy Markdown

Summary

Adds a reusable Conventional Commits commit-message normalizer for nightshift, exposed both as a library and a CLI subcommand, plus an installable commit-msg hook.

Changes

  • internal/commits/normalizer.go — pure, dependency-free Normalize(msg string) (string, error) plus typed validation. Enforces the allowed type set (feat/fix/docs/style/refactor/test/chore/perf/build/ci), lowercases the type, requires a lowercase subject ≤ 72 chars, trims whitespace and trailing periods, strips git comment lines, and hard-wraps the body at 72 columns. Normalization is idempotent.
  • internal/commits/normalizer_test.go — table-driven tests covering valid messages, scope handling, comment stripping, body wrapping, missing/unknown type, missing subject, capitalized subject, overlong subject, empty input, and idempotency.
  • cmd/nightshift/commands/commit.gonightshift commit normalize subcommand accepting a positional argument, --file (for the commit-msg hook), or stdin, with --check for validate-only.
  • scripts/commit-msg.sh — git commit-msg hook that normalizes the message file in place and rejects non-conforming messages.
  • docs/commit-messages.md — documents the format, the command, and hook installation.

Verification

  • go build ./...
  • go vet ./...
  • go test ./... ✅ (all packages pass, including new internal/commits)
  • Manual smoke test of nightshift commit normalize (positional, --file, valid + rejected cases)

Closes the commit-normalize task.

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 (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
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