Skip to content

Instantly share code, notes, and snippets.

@jmaumene
Created July 31, 2020 22:00
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/599b16656eb4d4d8453bf02709d36c3f to your computer and use it in GitHub Desktop.
Save jmaumene/599b16656eb4d4d8453bf02709d36c3f to your computer and use it in GitHub Desktop.
Check git commit message format : <type>(<scope>) <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:]])+\) [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>) <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