diff --git a/AGENTS.md b/AGENTS.md index 1fd3ae1..979eeef 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -54,3 +54,4 @@ go test ./... - **Style**: Standard Go (gofmt, govet). No magic, explicit is better. - **Errors**: Wrap with context, don't swallow. - **Tests**: Table-driven, in `_test.go` files alongside code. +- **Commit messages**: Conventional Commits (`()?: `), types: `feat, fix, chore, docs, refactor, perf, ci, test, build, style`. Run `make install-hooks` to enforce this locally via `scripts/commit-msg.sh`. diff --git a/Makefile b/Makefile index 088be01..9d0f10b 100644 --- a/Makefile +++ b/Makefile @@ -75,10 +75,12 @@ help: @echo " check - Run tests and lint" @echo " install - Build and install to Go bin directory" @echo " calibrate-providers - Compare local Claude/Codex session usage for calibration" - @echo " install-hooks - Install git pre-commit hook" + @echo " install-hooks - Install git pre-commit and commit-msg hooks" @echo " help - Show this help" -# Install git pre-commit hook +# Install git pre-commit and commit-msg hooks install-hooks: @ln -sf ../../scripts/pre-commit.sh .git/hooks/pre-commit @echo "✓ pre-commit hook installed (.git/hooks/pre-commit → scripts/pre-commit.sh)" + @ln -sf ../../scripts/commit-msg.sh .git/hooks/commit-msg + @echo "✓ commit-msg hook installed (.git/hooks/commit-msg → scripts/commit-msg.sh)" diff --git a/scripts/commit-msg.sh b/scripts/commit-msg.sh new file mode 100755 index 0000000..c9a412f --- /dev/null +++ b/scripts/commit-msg.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# commit-msg hook for nightshift +# Enforces Conventional Commits subject lines: https://www.conventionalcommits.org/ +# Install: make install-hooks (or: ln -sf ../../scripts/commit-msg.sh .git/hooks/commit-msg) +set -euo pipefail + +MSG_FILE="$1" +SUBJECT=$(head -n1 "$MSG_FILE") + +# Allow merge and revert commits through untouched. +if [[ "$SUBJECT" =~ ^Merge\ ]] || [[ "$SUBJECT" =~ ^Revert\ ]]; then + exit 0 +fi + +TYPES="feat|fix|chore|docs|refactor|perf|ci|test|build|style" +PATTERN="^(${TYPES})(\([a-zA-Z0-9_.-]+\))?!?: .+" + +printf "🪡 commit-msg check\n" +printf " %-20s" "conventional commit" + +if [[ "$SUBJECT" =~ $PATTERN ]]; then + echo "✓" +else + echo "✗ FAILED" + echo " Subject must match: ()?: " + echo " Allowed types: ${TYPES//|/, }" + echo " Got: \"$SUBJECT\"" + echo "" + echo "❌ commit message does not follow Conventional Commits. Fix it or use --no-verify to skip." + exit 1 +fi