Skip to content

Instantly share code, notes, and snippets.

@taylordaughtry
Last active January 23, 2019 14:53
Show Gist options
  • Select an option

  • Save taylordaughtry/4e6a54fa021b5d21a39e74d16ab05b74 to your computer and use it in GitHub Desktop.

Select an option

Save taylordaughtry/4e6a54fa021b5d21a39e74d16ab05b74 to your computer and use it in GitHub Desktop.
#!/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
# ===================
# 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."
@taylordaughtry
Copy link
Author

taylordaughtry commented Oct 12, 2018

Installation

  1. Run make init in your project root

Usage

When a developer clones your project, they should run make init as a part of the setup process. That runs a script that tells git to look in your .githooks directory 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 ready command.

Assumptions

  1. You're comfortable having a .githooks directory in your project
  2. You're okay with using a makefile for your project. (Highly recommended; you can do so much with makefiles.)

Screenshot

screen shot 2018-10-12 at 2 35 50 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment