die () {
  TEXT=$(cat <<'EOF'

\e[31mError: Commit messages should follow the conventional commits standard, and should have a Signed-off-by line\e[0m

Example:

```
feat: My feature.

Some description.

Signed-off-by: Your Name <your email address>
```

EOF
  )

  echo "${TEXT}"

  exit 1
}

COMMIT_MESSAGE=$(cat $1)

COMMIT_HEAD="^merge.+|(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert|types|i18n)(\(.+\))?: .{1,50}"
COMMIT_SIGNED_OFF="signed-off-by: .*<.*@.*>"

if ! echo "$COMMIT_MESSAGE" | grep -iqE "$COMMIT_HEAD"; then
  die
fi

if ! echo "$COMMIT_MESSAGE" | grep -iqE "$COMMIT_SIGNED_OFF"; then
  die
fi
