#!/usr/bin/env bash

# 校验 commit message 格式：
#   [AI-assist] type: description
#   [Human] type: description
# type = feat|fix|refactor|test|docs|chore

MSG=$(head -1 "$1")
PATTERN='^\[(AI-assist|Human)\] (feat|fix|refactor|test|docs|chore): .+'

if ! echo "$MSG" | grep -qE "$PATTERN"; then
  echo ""
  echo "ERROR: commit message 格式不符合规范。"
  echo ""
  echo "  要求格式: [AI-assist] type: description"
  echo "         或 [Human] type: description"
  echo ""
  echo "  type: feat | fix | refactor | test | docs | chore"
  echo ""
  echo "  你的 message: $MSG"
  echo ""
  exit 1
fi
