How to reference Bitbucket commits to Asana
tl;dr: Use this post-commit hook.
I found this great git post-commit hook by Spaceman Labs. It works by adding a comment to your Asana ticket when you reference your commit message by id. For example, “Fixing issue #12345." This adds a comment to your ticket:
Just committed %commit-id with message: "Fixing issue #1234" to repository %repo-name
This works by making a curl request to Asana’s REST API on your behalf while sending the above message as the comment. While this is great, it could be better by providing links to your Bitbucket changeset. I’ve made the necessary edits to do so in the post-commit hook. The updated message now looks like this:
Committed %link-to-commit with message: "Fixing issue #1234" to repository %repo-name
How it works
I loop through all the remote repositories configured for the repo and search for either a bitbucket.org or github.com in their URLs. Once one is found, I extract the repo name from the URL and build the link to the changeset.
Note: If you are using Github then I recommend using the free Asana service provided. I merely included the GitHub code as an example.
The original code from here takes over and parses out the ticket number and does the curl request.
Installation
Grab my edited post-commit hook from github and drop it into your repos
.git/hooks
directory. Make sure to chmod
the file to 0755
. Lastly, grab
your Asana key and run git config --global user.asana-key "MY_ASANA_API_KEY"
.
Afterthoughts
Please let me know if you have any suggestions. I’m thinking of possibly editing the git commit message to link back to the Asana ticket for the sake of cross-linking but this might require additional configuration… Unless project id is added as part of the ticket number. Ie: #12345/98765. Please feel free to add your input! :)