Created
February 28, 2024 08:46
-
-
Save tiagosiebler/081576e5091c11e6cd60062239ff966b to your computer and use it in GitHub Desktop.
precommit hook for husky for conv commits
This file contains hidden or 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" | |
red=$(tput setaf 1) # ANSI escape code for red color | |
reset=$(tput sgr0) # ANSI escape code to reset color | |
#Commit message check | |
commit_msg=$(git log -1 --pretty=%B) | |
if ! echo "$commit_msg" | grep -qE "^(feat|fix|chore|docs|test|style|refactor|perf|build|ci|revert)(\(.+?\))?:? .{1,}$ | |
"; then | |
echo "${red}Error${reset}: Invalid commit format, try: feat(feature): description." >&2 | |
exit 1 | |
fi | |
if [ ${#commit_msg} -gt 88 ]; then | |
echo "${red}Error${reset}: Invalid commit length. Your commit message is too long." >&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment