#!/bin/bash
commit_msg_file="$1"
commit_msg=$(cat "$commit_msg_file")

# Check commit message format
if ! echo "$commit_msg" | grep -qE '^(feat|fix|docs|style|refactor|test|chore)\([[:alnum:]_-]+\): .+'; then
    echo "Error: Commit message format does not follow convention"
    echo "Expected format: type(scope): description"
    echo "Valid types: feat, fix, docs, style, refactor, test, chore"
    exit 1
fi

# Check first line length
if [ $(echo "$commit_msg" | head -n 1 | wc -c) -gt 72 ]; then
    echo "Error: First line of commit message must not exceed 72 characters"
    exit 1
fi

echo "Commit message format validated ✓"
exit 0
