Last active
July 15, 2021 03:28
-
-
Save bhupal4all/f43c7b426c9e6c8af1789e75d09eca6a to your computer and use it in GitHub Desktop.
Git Commit Hook to enforce User to have JIRA or BUG ID and commit should start with ID. Copy the script to *.git/hooks/* fodler
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
#!/bin/sh | |
# echo -e command takes color code | |
# \e[32m -- Green | |
# \e[31m -- Red | |
# \e[0m -- Reset/Normal Color | |
GREEN="\e[32m" | |
RED="\e[31m" | |
ENDCOLOR="\e[0m" | |
export MESSAGE=$(<$1) | |
# Issue example, JIRA-0001, BUG-0001 and so on.. | |
# Commit Message should start with ISSUE ID | |
export ISSUE_TAG='^([A-Z]+)-([0-9]+)' | |
if [[ $MESSAGE =~ $ISSUE_TAG ]]; then | |
echo -e "${GREEN}Good, Commit has Ticket Number and Valid format!!!${ENDCOLOR}" | |
echo | |
exit 0; | |
fi | |
echo -e "${RED}Oh Buddy... Commit does not have Ticket Number or Not in Valid format !!!${ENDCOLOR}" | |
exit 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment