Skip to content

Instantly share code, notes, and snippets.

@bhupal4all
Last active July 15, 2021 03:28
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 bhupal4all/f43c7b426c9e6c8af1789e75d09eca6a to your computer and use it in GitHub Desktop.
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
#!/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