Skip to content

Instantly share code, notes, and snippets.

@samnela
Last active June 8, 2020 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samnela/d97d897eb9b96aca0c48663074f5009c to your computer and use it in GitHub Desktop.
Save samnela/d97d897eb9b96aca0c48663074f5009c to your computer and use it in GitHub Desktop.
Add the jira ticket number from the branch name
#!/bin/bash
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
branchName=`git rev-parse --abbrev-ref HEAD`
branchToSkip=(master develop)
message=$(cat "$COMMIT_MSG_FILE")
for branch in ${branchToSkip[*]}
do
if [[ $branch == $branchName ]]
then
exit 0
fi
done
jiraId=$(echo $branchName | sed -nr 's,[a-z]+/([A-Z]+-[0-9]+)-.+,\1,p')
if [[ ! -z $jiraId ]] && ! [[ $message == $jiraId* ]]
then
echo "${jiraId}: $message" > $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment