Skip to content

Instantly share code, notes, and snippets.

@michaelwoods
Forked from bartoszmajsak/prepare-commit-msg.sh
Last active July 16, 2018 15:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelwoods/250fe600327f6fd32056 to your computer and use it in GitHub Desktop.
Save michaelwoods/250fe600327f6fd32056 to your computer and use it in GitHub Desktop.
Regex matching of JIRA story keys to prepend git commits.
#!/bin/bash
STORY_KEY=$(git symbolic-ref --short HEAD | grep -Eo '^[a-zA-Z0-9]{3,}[-_][0-9]{1,5}' | awk '{sub(/_/, "-"); print toupper($0)}')
if [ -n "$STORY_KEY" ]; then
sed -i.bak -e "1s/^/[$STORY_KEY] /" $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment