Created
May 3, 2023 07:27
-
-
Save jonatkinson/9243328de14e17e1e4200b9a1ca97d72 to your computer and use it in GitHub Desktop.
Conventional Commits Git Hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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