Fixing up our Atlassian suite.

FishEye, git, and HipChat in harmonious coexistence.

At the consulting firm I work at we use a handful of pieces of the Atlassian suite: JIRA, FishEye, HipChat.

HipChat we've only just started using. It's exciting for me since we didn't have a good group chat solution prior to this. As a long-time IRC junkie, I jumped on the idea of having bots and in-channel notifications and such. Admittedly a lot of this kind of stuff can be of no true value beyond it being kind of fun, but there were a couple interactions that ended up being of value. The highest priority HipChat integration for me was getting Git announcing pushes to our HipChat rooms.

Rather than using the managed Git repository features of FishEye (or something like Gitorious, Stash, BitBucket, GitHub), we have our own central Git repository called vm-repos. It's just a collection of bare repositories accessible via SSH which serves as the origin for most of our private code. Nothing fancy, but as a consulting firm we have lots of different projects, and lots of different repos.

Something we had been wanting to set up for a while was getting FishEye to automatically pull in new Git repositories that had been added to vm-repos. We mostly use FishEye as a code search utility, so getting repos added was less crucial than if we were using the full Crucible/FishEye setup for code reviews and commenting. Manually adding our projects was tedious, and since it was low priority too, it meant that a lot of projects never ended up in FishEye. This lead to a vicious cycle of FishEye neglect.

Exacerbating the problem, we don't have a DevOps team, which means that unless our internal infrastructure gets critically broken, we typically don't have time to work on it. Our developers are busy working on client work, or more interesting internal stuff (like HipChat bots, apparently).

Setting up HipChat integrations finally gave me the motivation to execute this.

HipChat and Git Integration

This ended up being really easy thanks to the efforts of some other folks in the community. I wanted a post-receive hook that would notify HipChat of new commits. I started from a HipChat post-receive hook that I found on GitHub. I dropped this in place and then I just set up a little shell script that installs a post-receive hook in all of our bare repositories that don't have a hook already:

find /data/repos/git -name hooks -type d \! -exec test -e '{}/post-receive' \; \
    -exec cp ~/serverscripts/vm-repos/post-receive.template {}/post-receive \;

The post-receive.template file is:

while read oldrev newrev refname
        echo $oldrev $newrev $refname | /bin/bash ~/serverscripts/vm-repos/
        echo $oldrev $newrev $refname | /bin/bash ~/serverscripts/vm-repos/

        # Other post-receive hooks can go here, following the same pattern.

The main thing I had to fix with the HipChat post receive hook was that this script only notified single rooms. We typically have one HipChat room per project, and we didn't want everything going all to the same place. (Although we did create a room just for push announcements; that's the $DEFAULT_ROOM you see below).

So I updated the script to read from a rooms.conf file, and depending on the repo that had just been pushed to, announce to different rooms or to multiple rooms:

# Near the top
ROOM_IDS=$DEFAULT_ROOM,$(grep "^$REPO=" rooms.conf | grep -o '[0-9,]\+

And then rooms.conf is just a simple mapping of repo directories to HipChat room IDs.


The next change was FishEye support, so that repo names and changesets linked to FishEye:


This is what lead into finally fixing our FishEye setup. A lot of these FishEye links being generated were bogus because our repo names in FishEye didn't line up with our repo names on vm-repos, or in some cases, we just didn't have the FishEye repos created at all.

FishEye Automatic Discovery of Git Repos

There are some FishEye plugins out there that theoretically do this, like the FishEye Directory Scanner. We're on FishEye 3.x though, and this plugin hasn't been updated yet. The REST API for FishEye also doesn't seem to support the creation of repos. I was poking around at FishEye to try to figure out how to do this. I was about to do this with browser automation using Fluent Automation and ScriptCS, but noticed that repos are actually defined in plain text in the config.xml file. I tested it out by adding a repo and sure enough, after restarting FishEye, it picked this up and indexed it right away.

So I wrote another script that would find all of our Git repositories and rewrite FishEye's config.xml to include them. Caveat: I'd never call bash scripting an area of expertise; this is a quick-and-dirty hack and I freely admit that, but it works great!


This script echoes out a new config.xml. A parent script just shuts down FishEye, executes this and drops the new config.xml in place, and then restarts FishEye.

Directory syncing, done!

Post receive hooks for FishEye updates

FishEye was previously polling repos every 15 minutes for changes. This is pretty ugly and inflicts some server load. Thanks to our newly perfectly-aligned FishEye and Git repo names though, writing a post-receive hook to update FishEye via the API became trivial:


Harmonious coexistence

FishEye, git, and HipChat working happily together

Now when we do a Git push, we get a message like the one depicted. Project names link to the FishEye project, JIRA ticket numbers link correctly, commit hashes link to the changeset in FishEye, and FishEye's post-receive hook helps make sure that the commit number links are working in a matter of seconds. Server load is down on both the FishEye and Git servers since we're not polling every 15 minutes on every repository anymore. And our FishEye coverage is now 100%.

Huzzahs are in order.


comments powered by Disqus