v0.3 Release – Improved bug link for bug 459727

The pushlog has a buglink feature that changes a string that contains reference to a bug number into a link to that bug on BugZilla. This is done on the server side by hgpoller/buglink.py file. However, when loading more entries on scroll the bug links do not work as buglink.py is not run on them. I have to make the links on the client side. I’ve streamlined by bug link implementation by using a regex.

Previous Implementation

The following is the bug link code used previously:

  //Create buglink
  var bugInDesc = (pushData[i].desc).toUpperCase().indexOf("bug"); 
  if(bugInDesc != -1) {
    var bugLinkName = (pushData[i].desc).substring(bugInDesc, bugInDesc + 10);
    var bugNumber = bugLinkName.substring(4, 10);
    var bugLink = 
      (pushData[i].desc).substring(0, bugInDesc) + 
      '<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=' + 
      bugNumber + 
      '">' + 
      bugLinkName + 
      '</a>' + 
    (pushData[i].desc).substring(bugInDesc + 10, (pushData[i].desc).length);
    } else { //No bug provided
        var bugLink = pushData[i].desc;
    }

With this implementation an indexOf() is performed to find the string, “bug” in the description string. If the string, “bug” is found then it is turned into a bug link. However, the problem is things like “debugger” also contain the string, “bug” are changed into a bug link as well which is obviously wrong. We want to avoid this.

New Implementation

The following is the new bug link code:

//Create buglink
re = new RegExp("[bB][uU][gG]\s\d{6}");
var bugInDesc = (pushData[i].desc).search(re); 
if(bugInDesc != -1) {
  var bugLinkName = (pushData[i].desc).substring(bugInDesc, bugInDesc + 10);
  var bugNumber = bugLinkName.substring(4, 10);
  var bugLink = 
    (pushData[i].desc).substring(0, bugInDesc) + 
    '<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=' + 
    bugNumber + 
    '">' + 
    bugLinkName + 
    '</a>' + 
    (pushData[i].desc).substring(bugInDesc + 10, (pushData[i].desc).length);
  } else { //No bug provided
      var bugLink = pushData[i].desc;
  }

Now with this regex strings like “debugger” are not turned into a bug link. Only valid strings like “bug 123456″ which match the regex pattern are turned into a link.

This entry was posted in Mercurial Project, Open Source and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>