Created
May 23, 2023 08:52
-
-
Save pratheeshrussell/c97f35721c2a0ffabf23ca702df2088c to your computer and use it in GitHub Desktop.
husky commit message 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
#!/usr/bin/env sh | |
. "$(dirname -- "$0")/_/husky.sh" | |
commit_msg_file=$1 | |
commit_msg=$(cat "$commit_msg_file") | |
pattern="^(add|fix|bump|make|refactor|reformat|optimise|document|merge)\/ticket-\d+\/[A-Za-z0-9_]*$" | |
if ! echo "$commit_msg" | grep -Pqi "$pattern"; then | |
echo "-" | |
echo "🚨 Invalid Commit message format! 😕" | |
echo "The commit message must have this format:" | |
echo "<verb >/ticket-<ticket number>/<what_was_done>" | |
echo "Allowed verbs: add, fix, bump, make, refactor, reformat, optimise, document, merge" | |
echo "Example: add/ticket-12/login_button" | |
echo "-" | |
echo "Your commit message was:" | |
echo $commit_msg | |
echo "-" | |
echo "For more information, check script in .husky/commit-msg" | |
echo "-" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment