feat(commits): add Conventional Commits message normalizer - #208
Open
iamlasse wants to merge 1 commit into
Open
Conversation
Add internal/commits with pure Normalize/validate functions enforcing the project's Conventional Commits rules: known lowercase type set (including revert), optional scope, breaking-change "!" marker, lowercase non-capitalized subject, rune-based 72-char subject limit, comment stripping, whitespace and trailing-period cleanup, and 72-rune body wrapping while preserving paragraph breaks. Wire it into the CLI as "nightshift commit normalize" (positional, --file, and stdin sources; --check 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
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.
Summary
Adds a Conventional Commits message normalizer to the nightshift CLI, addressing all review feedback from PR #207 (iteration 2).
internal/commits— pureNormalize/validate package enforcing the project's rules: known lowercase type set (feat fix docs style refactor test chore perf build ci revert), optional(scope), breaking-change!marker, lowercase non-capitalized subject, rune-based 72-char subject limit, git-comment stripping, whitespace/trailing-period cleanup, and 72-rune body wrapping that preserves paragraph breaks. Idempotent. Errors are wrapped,errors.Is-matchable sentinels.nightshift commit normalizeaccepting a positional message,--file, or stdin, plus--checkfor validate-only. Registered on the root command.scripts/commit-msg.sh— git commit-msg hook that normalizes the message in place and rejects invalid messages with a friendly diagnostic block.docs/commit-messages.md— format rules, type list, command examples, and hook installation.Fixes from iteration-1 review
--checkis now truly validate-only — it no longer prints the rewritten message; it prints nothing on success and exits non-zero on failure.NORMALIZED="$(...)" || STATUS=$?tolerates the failing command substitution underset -euo pipefail, so the expected-format/types/--no-verifyguidance now actually prints.SilenceUsage/SilenceErrorson the command; no moreError:+ full Usage dump on every validation failure.mktemp(cleaned via a trap) instead of a fixed/tmp/nightshift-commit-msg.err.ErrSubjectLowercase→ErrSubjectCapitalized(matches its "must not be capitalized" message).feat!breaking-change support —feat!:/feat(scope)!:parse and round-trip instead of producing a confusing "unknown type" error;revertadded to the allowed type set.Verification
go build ./...,go vet ./...,gofmt -l .— cleango test ./internal/commits/...— pass--checkvalidate-only, single-line error output, rewrite mode, breaking-change outputNightshift-Task: commit-normalize
Nightshift-Ref: https://github.com/marcus/nightshift