Skip to content

feat(commits): add Conventional Commits message normalizer - #213

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

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

Conversation

@iamlasse

@iamlasse iamlasse commented Aug 11, 2026

Copy link
Copy Markdown

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 idempotent Normalize(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.gonightshift commit normalize [MESSAGE] cobra subcommand. Reads the message from a positional arg, --file/-f, or stdin (in that order). --check/-c validates without emitting the rewrite. Errors go to stderr with a non-zero exit.
  • scripts/commit-msg.sh — git commit-msg hook that runs nightshift commit normalize --file on the message file, rewrites it into canonical form, and rejects non-conformant messages.
  • Makefileinstall-hooks now also symlinks the commit-msg hook (alongside the existing pre-commit hook).
  • docs/commit-messages.md — documents the format, allowed types, the commit normalize command, and hook installation.

Verification

  • gofmt -l . clean
  • go vet ./... clean
  • go build ./... clean
  • go test ./internal/commits/... and go 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

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