Our engineering team uses both Pivotal Tracker and GitHub extensively to continuously update our SDK. Nick Petrella, one of our devs, wrote a script to connect the two a little more seamlessly.

“I finally got sick of always having to go look up the Pivotal ID for the story I am working on when I am committing changes in git,” Nick explained.

If you’d like to use his script, he has it hosted on Git. Below are his notes:

If you place the script in your local repository as an executable file called .git/hooks/prepare-commit-message it will connect to Pivotal, find the story/ies you are currently working on and put the [#STORYID] at the beginning of your commit.

Additional Setup
You must install GitPython:
sudo easy_install GitPython

You must set three local values in your Git config by running something like:
git config –local pivotal.token ##### (Ed. note: replace # with your API token found on your profile page)
git config –local pivotal.filter ‘mywork:NP current_state:started’
git config –local pivotal.projectid ###### (Ed. note: replace # with your specific project ID)

Change these values to match your preferred settings and token/project values. The filter in this case searches for all stories being worked on by NP (me) and in a state of started.

You must link your site packages directory:
The git commit runs with a specific env so on my Mac I had to create this symbolic link:
sudo ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ /Library/Python/2.7/site-packages

Once the setup is done, when you run a Git commit, it will add the stories it found to the commit message. You can look in your shell to see what stories it found. Unfortunately, the commit hooks don’t support interactivity, so my super cool “enter which stories you want included” won’t work and I default to all of the stories that match your defined filter. Also, remember that you must delete the line added to your commit message if you want to abort the commit so that the message you submit is blank.

Also, I made the setup repository specific, so those of you working on different repos/projects can adjust the settings accordingly for each repo you want to use this on.

Let us know in the comments if you end up using Nick’s script and how it works out for you.

Leave a Reply