How can I automate Pivotal Tracker & Github Integration?
Asked Answered
H

7

18

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?

Hedgerow answered 14/12, 2012 at 22:46 Comment(0)
H
19

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.

Hedgerow answered 14/12, 2012 at 22:46 Comment(0)
S
4

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
Sanjuana answered 17/4, 2013 at 13:20 Comment(1)
Doesn't work on OS X Lion because -P (Perl regexes) aren't supported in grep.Basilicata
U
4

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.

Ulrika answered 14/8, 2013 at 14:36 Comment(0)
H
3

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.

Hurlyburly answered 2/4, 2014 at 8:46 Comment(1)
Some update. As some of my teams forgot to add "Fixes" in their merge message, then the Pivotal Tracker dashboard ended up desynchronized. So I built this to automatically Finish a story as soon as the Merge button is hit!Ify
D
0

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

Driskell answered 17/4, 2014 at 5:51 Comment(0)
K
0

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!

Kristynkrock answered 23/5, 2014 at 15:8 Comment(0)
A
0

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(-)
Amathist answered 6/2, 2015 at 16:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.