Last active
December 20, 2016 07:34
-
-
Save Laisky/0af2b87956c70621b2c6b4b0be6e7db8 to your computer and use it in GitHub Desktop.
Git commit comment restrict rules
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
# Inspired by https://gist.githubusercontent.com/leftstick/29e4099a61d2c0182e1fda196eb9e071/raw/4270cf778d70202bfc5d76fdee7e87c628b198e5/commit-msg | |
#!/usr/bin/env bash | |
echo " | |
#!/usr/bin/env bash | |
# regex to validate in commit msg | |
commit_regex='([A-Z]{1,7}-[0-9]{1,7}: .{1,100}(\\\nReviewed by: [a-zA-Z0-9\\.]{1,25})?|(fix|docs|feat|style|refactor|perf|test|chore): .{1,100})' | |
if ! grep -iqE \"\$commit_regex\" \"\$1\"; then | |
echo '\\\033[31m Commit comment format not correct!' | |
echo '\\\033[31m Your commit message should follow:' | |
echo '\\\033[33m JIRA Trackable ==> [JIRA Ticket]: [short description]' | |
echo '\\\033[33m JIRA Trackable Plus ==> [JIRA Ticket]: [short description]\\\n Reviewed by: [reviewer]' | |
echo '\\\033[33m Commitizen Style ==> fix|docs|feat|style|refactor|perf|test|chore: [short description]' | |
exit 1 | |
fi | |
" > .git/hooks/commit-msg | |
chmod +x .git/hooks/commit-msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment