Last active
December 6, 2015 19:16
-
-
Save joemidi/8de7fdd3bf83d9508c48 to your computer and use it in GitHub Desktop.
Post-Receive Git Hook to post a comment to an Asana task
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 | |
project_name="project-name" | |
# Generate your personal access token from your profile settings — apps. | |
# See: https://asana.com/guide/help/api/api | |
personal_access_token="" | |
task_id="" | |
print_comment="New preview available at: https://example.com/${project_name}" | |
while read oldrev newrev ref | |
do | |
if [[ $ref =~ .*/deploy$ ]]; then | |
echo "Deploy ref received. Deploying branch to preview…" | |
git — work-tree=/var/www/html/${project_name} — git-dir=/var/www/html/${project_name}/git checkout -f deploy | |
if [ “$task_id” ]; then | |
echo "Notifying users on Asana." | |
curl -H "Authorization: Bearer ${personal_access_token}" \ | |
https://app.asana.com/api/1.0/tasks/${task_id}/stories \ | |
-d "text=${print_comment}" > /dev/null 2>&1 | |
fi | |
else | |
echo "Ref $ref successfully received. Doing nothing: no work-tree with that branch name found on this server." | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment