#!/bin/sh
# noslop commit-msg: enforce Conventional Commits, block skip-ci tricks
MSG_FILE="$1"
SUBJECT=$(head -n1 "$MSG_FILE")

# Block skip-ci patterns (subject line only — body may legitimately discuss these)
if echo "$SUBJECT" | grep -qiE '\[skip ci\]|skip-checks|--no-verify'; then
  echo "noslop: commit subject contains a CI-bypass pattern." >&2
  echo "  Blocked: [skip ci], skip-checks, --no-verify" >&2
  echo "  Remove the pattern from your commit subject. CI checks are required and cannot be skipped." >&2
  exit 1
fi

# Enforce Conventional Commits pattern (subject line only)
PATTERN='^(feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert)(\(.+\))?(!)?: .{1,100}$'
if ! echo "$SUBJECT" | grep -qE "$PATTERN"; then
  echo "noslop: commit message does not follow Conventional Commits." >&2
  echo "  Expected: type(scope): description" >&2
  echo "  Types: feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert" >&2
  echo "  Example: feat(auth): add OAuth2 login flow" >&2
  exit 1
fi
