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: #1234598765. Please feel free to add your input! :)

Jan 31, 2015 Servers

Support this blog

Buy yourself ANYTHING!

That's right! Shop as you normally would using Amazon.com with my affiliate link and the commissions made go directly into keeping this blog healthy. It's that simple! The hardware and software costs used for this site comes out of my own pocket and it's expensive. Lets keep this site ad free :)

Start shopping on Amazon.com now!

Thank you!
Richard S.