From 39768fdd45e7a1e47ce66dab660f8a9deaa59038 Mon Sep 17 00:00:00 2001 From: Barry Walker Date: Tue, 13 Jan 2026 18:28:31 -0500 Subject: [PATCH] ci: add local git hook for conventional commit validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Run `git config core.hooksPath .githooks` to enable. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .githooks/commit-msg | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 .githooks/commit-msg diff --git a/.githooks/commit-msg b/.githooks/commit-msg new file mode 100755 index 0000000..fd0d8be --- /dev/null +++ b/.githooks/commit-msg @@ -0,0 +1,37 @@ +#!/bin/sh +# Conventional Commits validation hook +# https://www.conventionalcommits.org/ + +commit_msg_file="$1" +commit_msg=$(cat "$commit_msg_file") + +# Skip merge commits +if echo "$commit_msg" | grep -qE "^Merge "; then + exit 0 +fi + +# Conventional commit pattern +# type(scope)?: description +# type!: breaking change +pattern="^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?\!?: .{1,}" + +if ! echo "$commit_msg" | grep -qE "$pattern"; then + echo "" + echo "ERROR: Commit message does not follow Conventional Commits format." + echo "" + echo "Your message:" + echo " $commit_msg" + echo "" + echo "Expected format:" + echo " type(scope)?: description" + echo "" + echo "Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert" + echo "" + echo "Examples:" + echo " feat: add user authentication" + echo " fix(api): handle null response" + echo " docs: update README" + echo " feat!: breaking change to API" + echo "" + exit 1 +fi