Skip to content

feat(hooks): add Conventional Commits normalizer#174

Open
pistell wants to merge 1 commit into
marcus:mainfrom
pistell:feature/commit-normalize
Open

feat(hooks): add Conventional Commits normalizer#174
pistell wants to merge 1 commit into
marcus:mainfrom
pistell:feature/commit-normalize

Conversation

@pistell
Copy link
Copy Markdown

@pistell pistell commented May 26, 2026

Summary

  • Adds a language-agnostic POSIX shell commit message normalizer (scripts/commit-normalizer.sh) wired into a commit-msg git hook (.githooks/commit-msg).
  • Enforces Conventional Commits format <type>(<scope>)!: <subject> with a 72-char subject limit; lowercases the type, trims whitespace, preserves bodies and trailers.
  • Skips merge, fixup/squash/amend, and revert commits.
  • Ships with a .gitmessage template, scripts/setup-hooks.sh (configures core.hooksPath and commit.template), docs/commit-conventions.md, and a fixture-driven test harness (12 cases, all passing).
  • Adds make setup-hooks and make test-commit-normalizer targets.

Standard

<type>(<scope>)!: <subject>

<body — wrapped at 72 chars>

<trailers>

Allowed types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert. Append ! to mark a breaking change. Trailers like Co-Authored-By, Fixes, Signed-off-by, Nightshift-Task are preserved verbatim.

Enable on a clone

./scripts/setup-hooks.sh
# or
make setup-hooks

Bypass once: COMMIT_NORMALIZER=0 git commit -m "...".

Test coverage

tests/commit-normalizer/cases/ covers:

  1. Valid Conventional Commit (no-op)
  2. Missing type (rejected)
  3. Oversized subject (rejected)
  4. Mixed-case type (normalized → lowercase)
  5. Trailing/extra whitespace (trimmed)
  6. Preserved trailers (Co-Authored-By, Nightshift-*, Signed-off-by)
  7. Merge commit (skipped)
  8. Fixup commit (skipped)
  9. Unknown type (rejected)
  10. Breaking-change marker ! (preserved)
  11. Comment-line stripping (# lines removed)
  12. Empty description (rejected)

Test plan

  • make test-commit-normalizer → 12/12 passing
  • Dogfooded — this PR's commit message passes through the normalizer unchanged
  • Reviewer enables locally with make setup-hooks and confirms a malformed git commit -m "foo" is rejected with a helpful error

Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift

Standardize commit messages with a POSIX shell normalizer wired to the
commit-msg hook. Lowercases the type, trims whitespace, enforces a
72-char subject limit, preserves trailers, and skips merge/fixup/revert
commits. Ships with .gitmessage template, scripts/setup-hooks.sh,
docs/commit-conventions.md, and 12 fixture-driven test cases.

Enable for a clone with: scripts/setup-hooks.sh

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