<< 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.

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

Add a comment Send a TrackBack