#!/usr/bin/env sh
# Validates that commit messages follow Conventional Commits format.
# Activate with: git config core.hooksPath .githooks

msg=$(cat "$1")
pattern='^(feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert)(\([a-z0-9_-]+\))?(!)?: .{1,72}'

if ! echo "$msg" | grep -qE "$pattern"; then
  echo ""
  echo "  ERROR: commit message does not follow Conventional Commits."
  echo ""
  echo "  Expected: <type>[(scope)][!]: <description>"
  echo "  Example:  feat(scan): add JSON output format"
  echo ""
  echo "  Types: feat fix docs style refactor perf test chore ci build revert"
  echo ""
  exit 1
fi
