<< Using Kernel-based Virtualization | Home | Adding Presence to Your Website >>

Extracting Jira Worklogs from Subversion

Time tracking through Subversion Commit Messages

We are using Atlassian's Jira for issue and time tracking.
Time tracking discipline has been varying mainly because it interrupts your flow if you have to leave the IDE to log work done. As we already include the corresponding Jira issue key in all our Subversion commit messages the natural idea was to just add the time spent to the commit message.

The worklog above is created from the first line of this commit message:

[BAS-70] Added README file (20m)
[BAS-61] Removed old stuff and did so
 much that it doesn't fit on a line (1w2d4h)

svn-worklog.rb is the Ruby script I wrote to extract worklog information from commit messages and attach them to the associated Jira issue. It is called from the post-commit hook.

To be able to extract the worklog the following rules must be be applied:

  • The issue key (e.g. BAS-70) must be encloced by brackets and appear at the beginning of a line
  • The time must be enclosed in braces and appear at the end of a line
  • Multiple lines per issue are ok
  • Multiple issues (and worklogs) per commit message are ok
  • time format is the same you would use on Jira's web UI

Installation

svn-worklog.pl is available here from our svn repo.
To install and configure it follow these steps:

  1. Make sure Ruby is installed
  2. Install Soap4R
  3. Install the latest Jira4R
  4. Deploy the modified atlassian-jira-rpc-plugin with support for impersonation
  5. Make sure "Accept remote API calls" in Jira's General Settings is set to "ON"
  6. Add a new Jira user and set the "allowImpersonate" property to "true"
  7. Add svn-worklog.rb to the post-commit hook of your svn repo

Step 1: Make sure Ruby is installed

Ruby probably already comes with your distribution. On Ubuntu 7.10 you would install it through apt-get:

apt-get install ruby irb rubygems ruby1.8-dev
gem update --system

Step 2: Install Soap4R

svn-worklog.rb communicates with Jira through SOAP so you need the Ruby SOAP library. Install it through gem:

gem install soap4r

Step 3: Install the latest Jira4R

You can either download the latest Jira4R from their svn repo or grab the gem here. Install it through gem:

gem install jira4r-0.0.1.gem

Step 4: Deploy the modified atlassian-jira-rpc-plugin with support for impersonation

svn-worklog.rb must be able to add the worklog for the user perfoming the svn commit but it does not know that user's password. Therefore I've added support for impersonation to the Jira RPC Plugin.
You can either download the patch and compile it on your own or grab a precompiled version for Jira 3.11.
Shut down Jira and replace the plugin with the original version in the /WEB-INF/lib directory of your Jira instance.

Step 5: Make sure "Accept remote API calls" in Jira's General Settings is set to "ON"

To be able to communicate with Jira through SOAP you must enable RPC calls in Jira. Go to "Administration/Global Permissions" and set "Accept remote API calls" to "ON".

Step 6: Add a new Jira user and set the "allowImpersonate" property to "true"

svn-worklog.rb will use a master user with the permissions to perform actions on behalf of other users.
Create a new user in Jira (the example uses "issues") and set the "allowImpersonate" user property to "true".

Step 7: Add svn-worklog.rb to the post-commit hook of your svn repo

Download svn-worklog.rb and place it in the /usr/local/bin directory. Make it executable (chmod +x /usr/local/bin/svn-worklog.rb).
Create the configuration file /etc/subversion/svn-worklog.conf:

$username = "issues"
$password = "secret"

Use the username and password of the master user created in step 6.

Add svn-worklog.rb to the post-commit hook of your repository. For example /var/lib/svn/repos/hooks/post-commit:

#!/bin/sh
REPOS="$1"
REV="$2"

# Log work to Jira
LOG=/tmp/svn-worklog.log
echo "== REPOS=$REPOS, REV=$REV ==" >> $LOG
date >> $LOG
/usr/local/bin/svn-worklog.rb "$REPOS" "$REV" >>$LOG 2>&1
echo >> $LOG

exit 0

Of course you can later remove the logging to /tmp/svn-worklog.log but make sure the output of svn-worklog.rb is redirected to /dev/null then as Jira4R currently contains some puts debugging statements that would otherwise confuse Subversion.

Update 2009-10-15

If you are using Fisheye the same and more can now be accomplished by the official Atlassian plugins. See Dragon Slayer Supplement: Action Issues with Commit Commands. Cool!

References



Re: Extracting Jira Worklogs from Subversion

The allowImpersonate feature is a winner. I've added some comments at http://jira.atlassian.com/browse/JRA-13176 that may be useful Peter

Re: Extracting Jira Worklogs from Subversion

Hi,

This is clever but I wonder how you know whether your timings are accurate. For accurate timing, you need help! My app may be able to help you there:

http://worklogassistant.com/

I'd be interested in any comments you have about it.

Re: Extracting Jira Worklogs from Subversion

I already saw your application and think it's quite nice for Windows users (being a Linux user myself I guess it won't work here).
It is not fundamentally different from the Atlassian IDE Plugin for IDEA which also includes a "Log Work" dialog that does not require switching to a browser. However this only works for developers not for QA.
My main motivation for the subversion integration is that we are now able to correlate changes to the code base to the effort we've spent and the issue that was worked on. It works on any platform, causes a minimum overhead and doesn't require switching applications.
What do you mean by "I wonder how you know whether your timings are accurate"? They are only as accurate as the user that enters them is. This is also the case with your tool, isn't it?

Re: Extracting Jira Worklogs from Subversion

Stefan,

Actually, I just finished creating a first draft of the Ubuntu package yesterday. So Linux support is on its way. In fact, I developed it on Linux and use it about 50/50 on Linux and Windows. If you are interested in giving it a test run (and maybe blog or let me know about the benefits/shortcomings), let me know.

The main difference between JIRA's "Log Work" functionality (I can't speak to IDEA's, I use Emacs) is that the "how long did I work on this" is automatically filled in. This makes it immensely easier to accurately track time. This is what I mean by "how do you know your timings are accurate?" If the computer isn't tracking it for you, you're left to guess. You may be interested in this blog post I wrote. I want to avoid "random but realistic looking guesses" and quite frankly, it's not that hard!

I can see the attraction to your solution though, esp if you don't want to switch apps.

Myself, whenever I make a context switch I usually stare blankly at the issue list and decide what I want to do next so for me the app switch isn't huge. However, I have been considering reworking things to never require a mouse, including adding global shortcuts. What do you think?

As for SVN, correlating changes related to an issue from SVN is VERY important, as you obviously understand.

Hope that clarifies some things and let me know if you want to have a stab at the Ubuntu package.

Re: Extracting Jira Worklogs from Subversion

PS: Seems that link didn't quite work:

http://blog.worklogassistant.com/2008/12/why-write-worklog-assistant.html

is the link to the post.

Sorry about that.

Re: Extracting Jira Worklogs from Subversion

Sorry for the triple post, but the Linux build (via .deb package) is available if you want to give it a shot!

http://worklogassistant.com/download.html

Re: Extracting Jira Worklogs from Subversion

No problem.
Do you also have a build for amd-64?

Re: Extracting Jira Worklogs from Subversion

Actually, not on hand. I guess the 386 version needs extra 386 libraries to run on amd64?

Add a comment Send a TrackBack