-
-
Save webspectyler/3807735 to your computer and use it in GitHub Desktop.
git post-commit hook to update referenced task status in Asana amd FreshBooks with commit message
This file contains hidden or 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/sh | |
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]} | |
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 | |
project=$(git config user.asana-project) | |
if [ "$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 \ | |
--data "text=just commited ${comment/ / with message:%0A}" > /dev/null 2>&1 | |
apiurl=$(git config user.freshbooks-url) | |
authtoken=$(git config user.freshbooks-key) | |
project=$(git config user.freshbooks-project) | |
if [ $authtoken == '' ] ; then exit 0; fi | |
echo -n "FreshBooks: would you like to add this commit to time tracking ([y]es, [n]o, [l]ist my tasks)? " | |
read -n 1 option < /dev/tty | |
if [ "$option" = "l" ] ; then | |
if [ "$project" != "" ] ; then | |
curl -u ${authtoken}:X "${apiurl}" -d "<?xml version=\"1.0\" encoding=\"utf-8\"?><request method=\"task.list\"><project_id>${project}</project_id></request>" | |
fi | |
elif [ "$option" = "n" ] ; then | |
echo -en "\n" | |
exit 0 | |
fi | |
echo -en "\nFreshBooks: which is the task-id? " | |
read taskid < /dev/tty | |
echo -en "\nFreshBooks: how many hours? " | |
read hoursworked < /dev/tty | |
curl -u ${authtoken}:X "${apiurl}" -d "<?xml version=\"1.0\" encoding=\"utf-8\"?><request method=\"time_entry.create\"><time_entry><project_id>${project}</project_id><task_id>${taskid}</task_id><notes>just commited ${comment/ / with message: }</notes><hours>${hoursworked}</hours></time_entry></request>" > /dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment