Skip to content

Instantly share code, notes, and snippets.

@paunin
Last active August 29, 2015 14:05
Show Gist options
  • Save paunin/930d2f13d71b710ec5bc to your computer and use it in GitHub Desktop.
Save paunin/930d2f13d71b710ec5bc to your computer and use it in GitHub Desktop.
git hook prepare-commit-msg
#!/bin/sh
# @author paunin
# @url http://paunin.com
# @require jq[http://stedolan.github.io/jq/]
# @require curl
RM_KEY=""
RM_URL=""
if [ "$RM_URL" = "" ]
then
echo "You need to set RM_URL"
exit 1
fi
if [ "$RM_KEY" = "" ]
then
echo "You need to set RM_KEY"
exit 1
fi
branch_name=$(git symbolic-ref --short -q HEAD 2>/dev/null)
branch_description=$(git config branch.$branch_name.description)
if [ "$branch_description" = "" ]
then
task_id=$(echo "$branch_name" | egrep -o '(^[0-9]{1,9}|[0-9]{1,9}$)')
if [ "$task_id" = "" ]
then
#echo "No numbers in branch name ($branch_name) to detect task id"
exit 0
fi
rm_task_name=$(curl $RM_URL/issues/$task_id.json?key=$RM_KEY 2>/dev/null|jq '.issue.subject');
if [ "$rm_task_name" = "" ]
then
#echo "No task found in redmine by id $task_id"
exit 0
fi
branch_description="#$task_id $rm_task_name"
$(git config branch.$branch_name.description "$branch_description")
fi
#if [ "$branch_description" = "" ]
#then
# #echo "Add baranch description! Run next command:\n git config branch.$branch_name.description {YOUR_DESCRIPTION}"
# exit 0
#fi
message=$(cat $1)
echo "$branch_description" > "$1"
echo $message >> "$1"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment