Skip to content

Instantly share code, notes, and snippets.

@bogy0
Last active June 11, 2019 16:22
Show Gist options
  • Save bogy0/327ffcb6e837542441341713be2e1980 to your computer and use it in GitHub Desktop.
Save bogy0/327ffcb6e837542441341713be2e1980 to your computer and use it in GitHub Desktop.
Commit hook to parse actual branch name. Try to find JIRA issue number in the branch name and ammend that to the end of the commit message.
TICKET_ID=$(git rev-parse --abbrev-ref HEAD 2> /dev/null | grep -oE "[A-Z]+-[0-9]+")
if [ -n "$TICKET_ID" ]; then
echo "$(cat $1)\n$TICKET_ID" > $1
fi
@bogy0
Copy link
Author

bogy0 commented Jun 11, 2019

Usage example with Husky

package.json fragment:

...
"husky": {
    "hooks": {
      "pre-commit": "npm run lint",
      "pre-push": "npm run test",
      "commit-msg": "./scripts/commit.sh ./.git/COMMIT_EDITMSG"
    }
  },
...

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