Posted on by & filed under distributed teams, javascript, robots.

I was having a problem.

We use JIRA for ticket-tracking. It assigns each ticket a project code and ticket number, or key. I had been encouraging the team to refer to specific tickets in our chat room when discussing what they were working on, versus, “Hoping to finish up the thing with the error on the page.” My problem was that they started actually doing this, but there were now so many people collaborating that we had no idea what any individual “issue key” meant.

We needed someone to help us with the menial task of looking up the associated JIRA ticket and summarizing the current status in all of our chatrooms. This sounded like a job for a robot. What surprised me was that it was also a perfect job for something other than Python, specifically Node.js.

An automated notification from GitHub triggers a response from jirabot

The most popular chat robot today is Hubot, developed at GitHub. It even has a community plugin to do exactly what I describe in this post. You should use Hubot if you want to accomplish this specific task, but the post might give you ideas about your own robots that are actually unique.

As a programmer, I am most comfortable in Python, so I started my experiments with the Python-HipChat libraries. As I tried out quick implementations using each library, I got annoyed that the basic architectural approach wasn’t what I had wanted. Why couldn’t I just have a simple robot listen to chatroom conversations and blurt out useful context when a JIRA issue key was mentioned?

Event-driven programming existed long before Node.js, but boy does this programming paradigm work perfectly for robots:

var b = new wobot.Bot();

b.connect();

b.onInvite(function(roomJid, fromJid, reason) {
  var self = this;
  console.log(' -=- > Invited to and joining ' + roomJid + ' by ' + fromJid + ': ' + reason);
  self.join(roomJid);
});

b.onMessage(function(channel, from, message) {
  var self = this;
  var matches = message.match(jiraProjectRe);

  matches.forEach(function(jiraKey) { 
    var options = {
      path: '/rest/api/2/issue/' + jiraKey,
    };

    var req = https.request(options, function(res) {
      res.on('end', function() {
        var jiraData = JSON.parse(body);
        var clarification = jiraData.key + ': “' + jiraData.fields.summary + '” marked as ' + jiraData.fields.status.name + ' and assigned to ' + jiraData.fields.assignee.displayName;
        self.message(channel, clarification);
...

It’s difficult to express how delightful I find this code. While it’s not the work of a JavaScript artisan, I appreciate it primarily because the flow code almost exactly matches my verbal description of the problem:

My version of the HipChat-JIRA robot is based on wobot, a simple and clean event-based HipChat library for Node.js. Deploying it on Heroku was equally pain-free (after I figured out the basics, but that’s the subject of some other post).

Now we just need to figure out how to do the same thing when someone mentions a ticket on a video call….

Tags:

Trackbacks/Pingbacks

  1.  Opening the box, what is DevOps? | The Life of a SysAdmin