Skip to content

Instantly share code, notes, and snippets.

@brunohq
Created May 11, 2012 14:37
Show Gist options
  • Save brunohq/2660130 to your computer and use it in GitHub Desktop.
Save brunohq/2660130 to your computer and use it in GitHub Desktop.
git post-commit hook to update referenced task status in Asana with commit message
#!/bin/bash
apikey=$(git config user.asana-key)
if [ $apikey == '' ] ; then exit 0; fi
comment=$(git log --pretty=oneline -n1)
taskid_pattern='.*#([0-9]*).*'
if [[ $comment =~ $taskid_pattern ]]; then
taskid=${BASH_REMATCH[1]}
apikey=$(git config user.asanakey)
else
echo -n "Asana: would you like to add this commit to a task ([y]es, [n]o, [l]ist my tasks)? "
read -n 1 option < /dev/tty
if [ "$option" = "l" ] ; then
workspace=$(git config user.asana-workspace)
project=$(git config user.asana-project)
if [ "$workspace" != "" ] ; then
curl -u ${apikey}: "https://app.asana.com/api/1.0/workspaces/${workspace}/tasks?opt_pretty&assignee=me"
elif [ "$project" != "" ] ; then
curl -u ${apikey}: "https://app.asana.com/api/1.0/projects/${project}/tasks?opt_pretty&assignee=me"
fi
elif [ "$option" = "n" ] ; then
echo -en "\n"
exit 0
fi
echo -en "\nAsana: which is the task-id? "
read taskid < /dev/tty
fi
curl -u ${apikey}: https://app.asana.com/api/1.0/tasks/${taskid}/stories \
-d "text=just commited ${comment/ / with message:%0A}" > /dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment