Skip to content

Instantly share code, notes, and snippets.

@KarthikNayak
Created March 21, 2018 05:35
Show Gist options
  • Save KarthikNayak/f346f9e6fb6cdabe8a6e3b4abd63f29f to your computer and use it in GitHub Desktop.
Save KarthikNayak/f346f9e6fb6cdabe8a6e3b4abd63f29f to your computer and use it in GitHub Desktop.
Git prepare-commit-msg hook for projects dealing with JIRA
#!/bin/bash
# Succeed on all merge messages, as evidenced by MERGE_MSG existing
[ -f $GIT_DIR/MERGE_MSG ] && exit 0
BRANCH=$(git branch | grep '*' | sed 's/* //')
read -r -d '' HELP_TEXT << EOM
# 1. Separate subject from body with a blank line
# 2. Limit the subject line to 50 characters
# 3. Capitalize the subject line
# 4. Do not end the subject line with a period
# 5. Use the imperative mood in the subject line
# 6. Wrap the body at 72 characters
# 7. Use the body to explain what and why vs. how
EOM
# Don't apply this logic if we are in a 'detached head' state (rebasing, read-only history, etc)
if [[ ${BRANCH} != *"no branch"* ]]; then
JIRA_ID=$(echo $BRANCH | grep -Eow "SP-[0-9]+")
JIRA_LINK="https://springboard-edu.atlassian.net/browse/$JIRA_ID"
echo -e "\nFeature branch: $BRANCH" >> "$1"
echo -e "Jira Link: $JIRA_LINK\n" >> "$1"
fi
echo "$HELP_TEXT" >> $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment