Wednesday, October 17, 2012

Trello Bugzilla Integration

Here is a GreaseMonkey script that provides simplistic integration of Bugzilla into Trello.com.


So far it supports:
  • Decorating cards that have 'Bug \d+' in their card title with a badge that is a hyper link to Bugzilla.

  • Auto-completion of new card titles starting with 'Bug \d+' 

The script also works in Chrome with the Tampermonkey extension installed.

You can get the code on GitHub


// ==UserScript==
// @name Trello Bugzilla Integration
// @namespace http://www.navicon.dk/
// @version 0.1
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// @description Looks for card titles with 'Bug \d+' and adds badge/links to bugzilla. Also autocompletes new card titles that starts with 'Bug \d+' from bugzilla. Autocomplete is actived when pressing spacebar after 'Bug \d+'.
// @match https://trello.com/board/*
// @copyright 2012+, Carsten Madsen
// ==/UserScript==

// grey bugz icon
var bugzillaImg = '';

// edit me to point somewhere else
var bugzillaLink = 'http://bugzilla.mozilla.com/show_bug.cgi?id=';

var addBugzillaBadge = function() {
    $(".list-card-title").each(function(i,val){
    if ($(this).html().match(/Bug \d+/)) {
        var regExpMatch = $(this).html().match(/Bug (\d+)/);
        if ($(this).parent().find(".bugz").length < 1){
        $(this).parent().children('.badges').append(''+bugzillaImg+'');}
    }
    });
};

// intercept spacebar press when creating new cards and look in
// bugzilla to do possible autocomplete

unsafeWindow.$("body").delegate(".js-card-title", "keypress", function(e){
    var code = (e.keyCode ? e.keyCode : e.which);
    if(code == 32) { //Space keycode
    var text = $(this).val();
    var regExpMatch = text.match(/Bug (\d+)/);
    var textarea = $(this);
    if (regExpMatch) {
        // see http://stackoverflow.com/questions/11007605/gm-xmlhttprequest-why-is-it-never-firing-the-onload-in-firefox
        setTimeout(function() {GM_xmlhttpRequest({
        method: "GET",
        url: bugzillaLink+regExpMatch[1],
        onload: function(response) {
            var jq = $(response.responseText);
            textarea.val(jq.find(".bz_alias_short_desc_container b").text().replace(String.fromCharCode(160)," ")+ " - " + jq.find("#short_desc_nonedit_display").text());
        }
        })}, 0);
    }   
    }
});

setInterval(addBugzillaBadge, 5000);

Live Traffic Map