Skip to content

Instantly share code, notes, and snippets.

@jmaumene
Last active July 31, 2020 21:58
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 jmaumene/a192070f5ea7711573fb5557cd1046db to your computer and use it in GitHub Desktop.
Save jmaumene/a192070f5ea7711573fb5557cd1046db to your computer and use it in GitHub Desktop.
Check git commit message format : <type>(<scope>) #00000 <Short summary>
#!/usr/bin/env bash
# regex to validate in commit msg
commit_regex='^(feat|fix|docs|refactor|style|test|ci)\([a-z](-|[[:alnum:]]|[[:space:]])+\) #[[:digit:]]+ [A-Z]'
if ! grep -E "$commit_regex" "$1"; then
echo ""
echo -e "\033[0;31m[POLICY] Your message is not formatted correctly!\033[0m" >&2
echo ""
echo "Message format must be like:"
echo "<type>(<scope>) #00000 <Short summary>"
echo " "
echo "Commit Type: feat|fix|docs|refactor|style|test|ci lowercase"
echo "(Scope): Name of module / package / scope. Start with lowercase and after accept : space - a-z A-Z 0-9"
echo "Summary : Short tile. Start with UpperCase"
echo ""
echo "---------------------------"
grep -v '^#' "$1"
echo "---------------------------"
echo ""
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment