Last active
June 20, 2018 19:07
-
-
Save ajardin/da187e281f6602114dfece5a690251db to your computer and use it in GitHub Desktop.
Git commit-msg hook to validate message format.
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 bash | |
set -euo pipefail | |
# ==================================================================================================== | |
# The script below allows to check automatically a commit message before saving it. | |
# In order to use it, you have to copy this code in .git/hooks/commit-msg inside your project. | |
# Don't forget to add proper permissions if you create a new file (chmod +x). Bash 3+ is required. | |
# ==================================================================================================== | |
COMMIT_MSG=$(cat $1) | |
MODULES=`find app/code/local/MyMagento -depth 1 -type d -exec basename {} \; | sort | paste -sd "|" -` | |
EXTRA="Design" | |
REGEX="(MyTicket-[[:digit:]]+|N\/A):[[:space:]]\[(${MODULES}|${EXTRA})\][[:space:]].+" | |
if [[ ("${COMMIT_MSG}" =~ ${REGEX}) || ("${COMMIT_MSG}" =~ Merge.+branch.+into.+) ]]; then | |
echo -e "\033[0;32mYour commit message has been successfully validated.\033[0m" | |
CODE=0 | |
else | |
echo -e "\033[0;31mYour commit message is invalid, please check the regular expression below.\033[0m" | |
echo -e "\033[0;34m${REGEX}\033[0m" | |
CODE=1 | |
fi | |
exit ${CODE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment