-
-
Save jailson/74cbeedbf906f7a7dacfecd39b08a093 to your computer and use it in GitHub Desktop.
Hook script to validate any commit message checking for a JIRA Issue or 'Merge'.
This file contains hidden or 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 | |
| # | |
| # HOW TO INSTALL | |
| # | |
| # 1. Copy the file commit-msg.sh to .git/hooks/commit-msg: | |
| # curl https://gist.githubusercontent.com/jailson/74cbeedbf906f7a7dacfecd39b08a093/raw/21e8284398ba4fffd55faca3a8fb67a8ec3a9742/commit-msg.sh > .git/hooks/commit-msg | |
| # | |
| # 2. Delete the sample file: | |
| # rm .git/hooks/commit-msg.sample | |
| # | |
| # 3. Make the script executable: | |
| # chmod +x .git/hooks/commit-msg | |
| # | |
| commit_regex='([a-zA-Z]{1,10}-[0-9]+|merge)' | |
| error_msg="⚠️ Commit aborted! Your commit message is missing either a JIRA Issue (eg. 'ABCD-1234') or 'Merge'." | |
| 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