Last active
January 23, 2019 14:53
-
-
Save taylordaughtry/4e6a54fa021b5d21a39e74d16ab05b74 to your computer and use it in GitHub Desktop.
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
| #!/bin/sh | |
| # DEV: Add this project's JIRA symbol here. | |
| PROJ="REPLACE-ME" | |
| # Don't edit below this line. | |
| MESSAGE_FILE=$1 | |
| FIRST_LINE=`head -n1 $MESSAGE_FILE` | |
| REQUIRED_PATTERN="^\[[[:upper:]]+-[[:digit:]]+\][[:space:]]" | |
| if ! [[ $FIRST_LINE =~ $REQUIRED_PATTERN ]]; then | |
| NC='\033[0m' | |
| RED='\033[0;31m' | |
| YELLOW='\033[1;33m' | |
| printf "\n${RED}Commit Message Errors:${NC}\n\nYour commit message requires a JIRA issue: ${YELLOW}[${PROJ}-123] Example commit message${NC}\n\n" | |
| exit 1 | |
| fi |
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
| # =================== | |
| # CONFIGURATION | |
| # =================== | |
| commitHooks = https://gist.githubusercontent.com/taylordaughtry/4e6a54fa021b5d21a39e74d16ab05b74/raw/commit-msg | |
| # =================== | |
| # COMMANDS | |
| # =================== | |
| .PHONY: init | |
| init: | |
| @ mkdir -p .githooks \ | |
| && curl -s $(commitHooks) --output .githooks/commit-msg \ | |
| && chmod -R +x .githooks \ | |
| && git config core.hooksPath .githooks \ | |
| && echo "Githooks created and initialized. Add your project's symbol to the .githooks/commit-msg file." |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation
make initin your project rootUsage
When a developer clones your project, they should run
make initas a part of the setup process. That runs a script that tells git to look in your.githooksdirectory when running hooks. It then makes files in that directory executable, since git won't run them if they don't have that permission.Ideally, you'd extend your makefile to compile other aspects of your projects, like Webpack, PostCSS, Composer, and so forth—this would mean a developer could start your project with a single
make readycommand.Assumptions
.githooksdirectory in your projectmakefilefor your project. (Highly recommended; you can do so much with makefiles.)Screenshot