Skip to content

Instantly share code, notes, and snippets.

@jonatkinson
Created May 3, 2023 07:27
Show Gist options
  • Save jonatkinson/9243328de14e17e1e4200b9a1ca97d72 to your computer and use it in GitHub Desktop.
Save jonatkinson/9243328de14e17e1e4200b9a1ca97d72 to your computer and use it in GitHub Desktop.
Conventional Commits Git Hook
#!/bin/bash
commit_msg_file=$1
commit_msg=$(cat $commit_msg_file)
# Define the pattern for conventional commit messages
pattern="^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(.+\))?: .+"
if [[ ! ${commit_msg} =~ $pattern ]]; then
echo "ERROR: The commit message does not follow the conventional commit format."
echo "Valid types: build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test"
echo "Format: type(scope): subject"
exit 1
fi
# If commit message matches the pattern, continue with the commit
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment