Skip to content

Instantly share code, notes, and snippets.

@tiagosiebler
Created February 28, 2024 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagosiebler/081576e5091c11e6cd60062239ff966b to your computer and use it in GitHub Desktop.
Save tiagosiebler/081576e5091c11e6cd60062239ff966b to your computer and use it in GitHub Desktop.
precommit hook for husky for conv commits
#!/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