Files
613b4bac7f chore: add commit-msg hook to enforce semantic commits (#6727)
* chore: add commit-msg hook to enforce semantic commits

Adds a Husky commit-msg hook that validates commit messages follow the
conventional commit format (e.g., "feat(scope): description"). This
ensures PR titles are properly formatted since GitHub uses the first
commit message as the default PR title.


Co-authored-by: Hanzo Dev <dev@hanzo.ai>

* fix: address review comments

- Add set -euo pipefail for robust error handling
- Remove undocumented breaking change syntax


Co-authored-by: Hanzo Dev <dev@hanzo.ai>

---------

Co-authored-by: Hanzo Dev <dev@hanzo.ai>
2025-11-26 16:16:31 +01:00

56 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
# Validate commit message follows conventional commit format
# Format: type(scope): description OR type: description
# Examples:
# feat(auth): add login functionality
# fix: resolve null pointer exception
# tests(e2e): fix regression
# chore(deps): update dependencies
commit_msg_file="$1"
commit_msg=$(cat "$commit_msg_file")
# Skip merge commits
if echo "$commit_msg" | grep -qE "^Merge "; then
exit 0
fi
# Skip revert commits
if echo "$commit_msg" | grep -qE "^Revert "; then
exit 0
fi
# Valid commit types
types="feat|fix|docs|style|refactor|perf|test|tests|build|ci|chore|revert"
# Regex pattern for conventional commits
# type(scope): description OR type: description
pattern="^($types)(\([a-zA-Z0-9_-]+\))?: .+"
if ! echo "$commit_msg" | head -1 | grep -qE "$pattern"; then
echo "======================================"
echo "ERROR: Invalid commit message format!"
echo "======================================"
echo ""
echo "Your commit message:"
echo " $(head -1 "$commit_msg_file")"
echo ""
echo "Expected format:"
echo " type(scope): description"
echo " type: description"
echo ""
echo "Valid types: feat, fix, docs, style, refactor, perf, test, tests, build, ci, chore, revert"
echo ""
echo "Examples:"
echo " feat(auth): add login functionality"
echo " fix: resolve null pointer exception"
echo " tests(e2e): fix regression"
echo " chore(deps): update dependencies"
echo ""
exit 1
fi
exit 0