Created
October 8, 2013 17:27
-
-
Save kalupa/6888304 to your computer and use it in GitHub Desktop.
Bash commit-msg hook script to prepend JIRA issue ids based on the branch name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
is_project_id() | |
{ | |
project_ids=(BLOG OPS SYS IT PS PUB SS LP EX UBWEB) | |
found=0 | |
for id in "${project_ids}"; do | |
if [[ $id == $1 ]]; then | |
found=1 | |
break | |
fi | |
done | |
return $found | |
} | |
branch=$(git branch 2>/dev/null | grep -e ^* | tr -d ' *') | |
if [ -n "$branch" ] && [ "$branch" != "master" ]; then | |
OIFS=$IFS | |
IFS='-' | |
read -a pieces <<< "$branch" | |
IFS=$OIFS | |
if [ "${#pieces[@]}" -gt 1 ]; then | |
project=`tr '[a-z]' '[A-Z]' <<< "${pieces[0]}"` | |
issue="${pieces[1]}" | |
if is_project_id "$project" && [[ $issue =~ ^[0-9]+$ ]]; then | |
echo "$project-$issue $(cat $1)" > $1 | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment