Skip to content

Instantly share code, notes, and snippets.

@chandeeland
Last active May 24, 2018 23:01
Show Gist options
  • Save chandeeland/950cb4570ee78fa93516241bd47b6fb9 to your computer and use it in GitHub Desktop.
Save chandeeland/950cb4570ee78fa93516241bd47b6fb9 to your computer and use it in GitHub Desktop.
this will try to detect your Jira ticket id from your branch name and insert it into your commit message
#!/bin/bash
BRANCH_NAME=$(git symbolic-ref --short HEAD)
if [ -z "$BRANCH_NAME" ]; then
exit 0
fi
if [ "master" = "$BRANCH_NAME" ]; then
exit 0
fi
IS_A_RELEASE_BRANCH=$(printf "%s\n" "${BRANCH_NAME}" | grep -c "^release")
if [ $IS_A_RELEASE_BRANCH -eq 1 ]; then
exit 0
fi
JIRA_ISSUE_ID=$(printf "%s" ${BRANCH_NAME} | sed -E 's/^[^\/]*\/?([A-Za-z]{2}-[0-9]+).*/\1/g' )
if [ -n "$JIRA_ISSUE_ID" ]; then
sed -i.bak -E "1s/^(\[$JIRA_ISSUE_ID\] )?/[$JIRA_ISSUE_ID] /" $1
fi
@chandeeland
Copy link
Author

dont forget to

chmod 755 .git/hooks/prepare-commit-msg

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