Skip to content

Instantly share code, notes, and snippets.

@perchrh
Created March 26, 2019 09:12
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 perchrh/3b6cc50e2ae8891e9177885cd916adaa to your computer and use it in GitHub Desktop.
Save perchrh/3b6cc50e2ae8891e9177885cd916adaa to your computer and use it in GitHub Desktop.
.git/hooks/commit-msg for verifiying Jira id is present in commit message
#!/usr/bin/env bash
# set this to your active development branch
# based on https://gist.github.com/pgilad/5d7e4db725a906bd7aa7
develop_branch="develop"
current_branch="$(git rev-parse --abbrev-ref HEAD)"
# regex to validate in commit msg
commit_regex='(VUDDF-[0-9]+|merge)'
error_msg="Aborting commit. Your commit message is missing either a JIRA Issue ('VUDDF-1111') or 'Merge'"
# only check commit messages on main development branch
[ "$current_branch" != "$develop_branch" ] && exit 0
if ! grep -iqE "$commit_regex" "$1"; then
echo "$error_msg" >&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment