Question

Pivotal Tracker and Github have great integration: Once it's set up, each commit which is prefixed by the Pivotal Tracker ID will appear under the corresponding Pivotal Ticket automatically, for an example:

git commit -am '[#1234567] my new changes'
git push origin

will add the comment 'my new changes' automatically to the 1234567 Pivotal Ticket among with the github commit link.

However, it's easy to forget to add the ticket ID each time. How could it be simplified / automated?

Was it helpful?

Solution

The solution is to use Git-Hooks and feature branches. (The Github-flow is recommended).

You have to install this Git-Hook (copy a file to your local repository):

https://github.com/ktamas77/git_hooks

Before you start working on a particular Pivotal Ticket, you create a branch prefixed with the Pivotal Tracker ID, for an example:

git checkout 1234567_build_new_form

then add all your changes as you'd do normally:

git commit -am 'form added'
git commit -am 'styles added'
git push origin

you'll see, the git hook script will automatically extract the Pivotal Tracker ID from the feature branch name and add it to the front of each comment. You can still manually override it (with another ID) if you want.

In this way you don't have to worry about adding the Pivotal ID manually for every single commit. It also works with GUIS (such as GIT Tower) since these GUIs are using the standard GIT libraries / executables.

OTHER TIPS

Here's a simple shell version based on Tamas' solution. It takes the ID from the end of the branch name.

"my-feature-branch-12345678" => "My commit mssg [#12345678]".

Move to .git/hooks/prepare-commit-msg and make it executable:

#!/bin/bash
if story_id=`git branch | grep -oP '^\*.*\-\K[0-9]+$'`
then
  echo "[#$story_id]" >> "$1"
fi

Install the 'git-pivotal-tracker-integration' gem, https://github.com/nebhale/git-pivotal-tracker-integration

It adds commands to git like start and finish to Git to automatically prefix branches and commits with the tracker story ID and it also posts your commit messages to tracker. When you call 'git start' it will pull master to make sure you are up to date, create a branch for you and start the story in tracker for you. Do the work then call 'git finish' and it will merge your branch back in to master and update tracker.

My teams are using git_tracker. Each developer must run

$ git tracker init

once for every project on Pivotal Tracker. Then they need to name each new branch with a special convention, suffixing it with the Pivotal Tracker story id. For instance:

$ git checkout -b the-great-feathure-123456789

where 123456789 would be the Pivotal Tracker story id.

And here you go, you'll automatically have each commit refering to the story. Bonus point, if you use GitHub to perform pull requests, you can ask reviewers who merge the story to add to the merge commit:

[Fixes #123456789] ...

This way, you never have to click on the Finish button, GitHub will do it for you.

I am using a bookmarklet, which also sets the commit message from the story title.

[#69609212] Add new Todo

You can get it from here

A late comment, but maybe still a useful one. I wanted the same solution as provided by @Sjoerd, but I'm a mac user ;)

The resulting code looks like this;

story_id=`git symbolic-ref --short -q HEAD | grep -o "^[[:digit:]]*"`
if [ ! -z "$story_id" -a "$story_id" != " " ]
then
  echo "[#$story_id] $(cat $1)" > "$1"
fi

Note that we prepend the issue ID to the branch name, but it's pretty basic to modify the regex to match the end of the string, not the beginning. We also add the issue ID to the start of the comment, as this gives a more clear overview in the git log. If the above script is ues, each commit message will be prepended with [#<issue ID>], except when the branch name does not start with an actual issue ID.

It should be noted that it probably is best if this code is added before any other code in the prepare-commit-msg hook, as this will result in all commits to be prepended, even automatic merges and the like.

Hope this helps!

Here is a gem that does exactly what you want:

http://github.com/bogdan/git-storyid

It allows to select a story from a nicely formed menu:

[1] Removing Billing Page
[2] Welcome Email
[3] Tag campaign insertion points and campaigns with an identifier

Indexes(csv): 3
[campaign-tags 3020407]  [#44116647] Initial implementation of campaign tags
 1 file changed, 101 insertion(+), 2 deletions(-)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top