feat(cli): add commit message normalizer - #237
Open
gregggreg wants to merge 1 commit into
Open
Conversation
Add internal/commitmsg, a stdlib-only package that parses, validates and normalizes Conventional Commits messages, and expose it three ways from one canonical spec string: a nightshift commit-msg subcommand, a commit-msg git hook installed by make install-hooks, and the orchestrator's plan and implement prompts. The exemption for git's own headers matches only what git writes (Merge branch/branches/tag/commit/pull request/remote-tracking branch, Revert ", fixup!, squash!, amend!), so merges and rebase --autosquash are never blocked while a hand-written "Merge ..." subject is still checked. Length limits count runes rather than bytes, and --fix takes trailers only from a trailer paragraph or the end of the final block, never from the middle of prose. 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.
What
Standardizes the commit message format this repository uses, going forward.
Scope assumption: this enforces one format on new commits. It does not rewrite history — that is destructive and out of scope.
New
internal/commitmsgpackage (stdlib only) parses, validates and normalizes Conventional Commits messages. A single canonical spec string inspec.gois the source of truth, quoted by all four consumers:nightshift commit-msgCLI —--check/--fix/--print-spec/--quiet, over a file or stdinscripts/commit-msg.shgit hook, installed bymake install-hookswebsite/docs/cli-reference.mdFormat:
type(scope)!: subject, 72-character header cap, blank line before the body, body wrapped at 72 columns (code blocks, lists, indented text and URLs left alone), and one trailing block of git trailers withNightshift-Task/Nightshift-Ref/Co-Authored-Bydeduped.Review fixes in this iteration
Supersedes #236 (same task, earlier iteration). Three defects from that review are fixed, each with tests:
^Mergeprefix, so a human subject like "Merge duplicate config loaders into one" silently skipped validation. It now matches only what git actually writes —Merge branch|branches|remote-tracking branch|pull request|tag|commit,Revert ",fixup!,squash!,amend!.subject-lengtherror, hard-blocking a valid commit via the hook.subject-lengthandbody-wrapnow useutf8.RuneCountInString, andwrapParagraphfills by characters.--fixrelocated body prose.splitTrailershoisted any known-trailer-key line from anywhere in the body, tearing a mid-paragraph sentence out and welding the surrounding text together — silent content loss, since--fixrewritesCOMMIT_EDITMSGin place. Hoisting is now restricted to a paragraph made entirely of trailers, or the run of known trailers ending the final block. A trailing prose paragraph (really: this is prose/not: a trailer) is no longer absorbed as trailers.Two smaller items folded in:
wrapParagraphno longer breaksSee <very-long-url>into a short line plus a still-over-limit line; a token that cannot fit on any line stays on the line it started, and such lines are exempt frombody-wrap.go run ./cmd/nightshift, and falls back to a globally installednightshiftonly if it actually supportscommit-msg— so an older install elsewhere onPATHcannot fail the hook with a confusing error.Verification
gofmt -l .clean,go vet ./...,go build ./...andgo test ./...all pass across the repo.End-to-end in a scratch repo with the hook installed:
git merge --no-ffsucceeds,git commit --fixupsucceeds,git rebase --autosquashsucceeds, and a humanMerge duplicate config loaders into onesubject is correctly rejected (the iteration-1 blocker and the iteration-2 regression, both covered).CLI smoke test:
printf 'Fixed the thing.' | nightshift commit-msg --check -exits 1 with actionable issues;--fixproducesfix: fixed the thing.Note on overlapping work
Draft PR #186, branch
chore/commit-message-normalizer, and PRs #231/#232 cover overlapping scope with different designs. Only one of these should land.Nightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift
🤖 Generated with Claude Code