Mozilla Mercurial - Filters changelogs

It creates a list of only the bugs related to Firefox for desktop in Mozilla Mercurial pushlogs

As of 2015-10-26. See the latest version.

// ==UserScript==
// @name        Mozilla Mercurial - Filters changelogs
// @namespace   darkred
// @description It creates a list of only the bugs related to Firefox for desktop in Mozilla Mercurial pushlogs
// @include     https://hg.mozilla.org/integration/mozilla-inbound/pushloghtml*
// @version     1
// @grant       GM_xmlhttpRequest
// @grant       GM_addStyle
// @grant       GM_getResourceText
// @require     http://code.jquery.com/jquery-2.1.4.min.js
// @require     http://code.jquery.com/ui/1.11.4/jquery-ui.min.js
// @resource    jqUI_CSS  http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css  
// ==/UserScript==



var jqUI_CssSrc = GM_getResourceText ("jqUI_CSS");
GM_addStyle (jqUI_CssSrc);









var bugNumbers = [];

var title;
var status;
var platforms = [];
var platform;
var whiteboards = [];
var whiteboard;
var unique = [];
var titles = [];
var product;
var products = [];
var component;
var components = [];
var irrelevant = [];



var bugsComplete = [];


var blackflag = 0;





var generalCounter = 0;








var thisIndex;






getUnique();                                            // Get the unique linkes in the page


for (var i = 0; i < unique.length ; i++) {                   // Retrieves the values for each bug (from it's bug target HTML page) // MUST ADD +1 to unique.length
  retrieveValues(unique[i],i);
}





while (blackflag == 1){
  alert (blackflag);
  onComplete();
  blackflag++;
}



















function getUnique() {
  var buglinks = $('tr.pushlogentry').length;      // counter (helper)
  var links = [];
  var linksTexts = [];

  for (var k = 2; k < buglinks+2; k++) {
    if (document.querySelector('tr.pushlogentry:nth-child(' + k + ') > td:nth-child(3) > strong:nth-child(1) > a:nth-child(1)')) {
      links.push(document.querySelector('tr.pushlogentry:nth-child(' + k + ') > td:nth-child(3) > strong:nth-child(1) > a:nth-child(1)'));
      linksTexts.push(document.querySelector('tr.pushlogentry:nth-child(' + k + ') > td:nth-child(3) > strong:nth-child(1) > a:nth-child(1)').href);

    }
  }

  unique = linksTexts.filter(function (element, index, array) {          // To get the unique elements/links in the page
    return index == array.indexOf(element);
  });

}










function retrieveValues(x,i) {


    // thisIndex = i;


    var target = x;
    var details = GM_xmlhttpRequest({
      method: 'GET',
      url: target,
      synchronous: false, // Asynchronous request
      onload: function (response) {


        // thisIndex = i;


        var regex;
        // var result;




        // get bugNo
        var bugNo;
        regex = /https:\/\/bugzilla\.mozilla\.org\/show_bug\.cgi\?id=(.*)/;
        bugNo = x.match(regex)[1];
        bugNumbers[i] = bugNo;




        // get bug title
        regex = /<title>.*\ &ndash;\ (.*)<\/title>/;
        if (response.responseText.match(regex)){
          title = response.responseText.match(regex)[1];
          titles[i] = title;                                            // Helper array that stores the bugs titles
        }

        // get bug title (full// in case it's a restricted one "Access Denied")
        regex = /<title>(.*)<\/title>/;                //
        title2 = response.responseText.match(regex)[1];                // No Helper array needed



        // get status
        // regex = /<span id="static_bug_status">(.*)/;
        // regex = /<span id="static_bug_status">(.*)\n\ *(.*)/;
        regex = /<span id="static_bug_status">(.*)\n\ *<\/span>/;
        if (response.responseText.match(regex)){
          status = response.responseText.match(regex)[1];                // No Helper array needed
          alert (status);
        } else {
          regex = /<span id="static_bug_status">(.*)\n\ *(.*)\n.*<\/span>/;
          if (response.responseText.match(regex)){
          status = response.responseText.match(regex)[1] + ' ' + response.responseText.match(regex)[2];                // No Helper array needed
          alert (status);
          }
        }


        regex = /"field_container_product" >(.*)/;
        if (response.responseText.match(regex)){
          product = response.responseText.match(regex)[1];
          products[i] = product;                                       // Helper array that stores the bugs Product value
        }


        regex = /"field_container_component" >(.*)/;
        if (response.responseText.match(regex)){
          component = response.responseText.match(regex)[1];
          components[i] = component;                                   // Helper array that stores the bugs Component value
        }


        // regex = /<label for="rep_platform" accesskey="h">Platform<\/label>:.*\n.*<\/th>\n.*<td class="field_value">(.*)\n/;
        regex = /<label for="rep_platform" accesskey="h">Platform<\/label>:.*\n.*<\/th>\n.*<td class="field_value">(.*)\n\ *(.*)/;
        if (response.responseText.match(regex)){
          platform = response.responseText.match(regex)[1] + '/' + response.responseText.match(regex)[2] ;
          if (platform == 'Unspecified/Unspecified'){
            platform = 'Uns';
          }
          platforms[i] = platform;
        }

        // ΦΤΙΑΞΕ ΤΟ whiteboard
        // regex = />Whiteboard:<\/a>\n<\/label>\n<\/th><td colspan="2">(.*)/;
        regex = />Whiteboard:<\/a>\n<\/label>\n<\/th><td colspan="2">(.*)\ ./;
        if (response.responseText.match(regex)){
          whiteboard = response.responseText.match(regex)[1];
          whiteboards[i] = whiteboard;
        }




        generalCounter++;

        console.log('----------------------------------------------------------------------------------------------------------------------------------');
        console.log(generalCounter +"/"+unique.length);                                                      // Progression counter
        console.log('BugNo: ' + bugNo + '\nTitle: ' + title + '\nStatus: '+status + '\nProduct: '+product+'\nComponent: '+component + '\nPlatform: ' + platform + '\nWhiteboard: ' + whiteboard);
        // console.log('BugNo: ' + bugNo + '\nTitle: ' + title + '\nStatus: '+status + '\nProduct: '+product+'\nComponent: '+component);






        if (title2 == 'Access Denied'){
          console.log (unique[i]+' \n is IRRELEVANT because of it\'s has restricted access');
          irrelevant[i] = 'true';
          // return;
        } else if (status != 'RESOLVED'        &&
                   status != 'RESOLVED FIXED'  &&
                   status != 'VERIFIED'){
          console.log (unique[i]+' \n is IRRELEVANT because of it\'s Status --> '+status);
          irrelevant[i] = 'true';
        } else if (component == 'Build Config' && (product == 'Toolkit' || product == 'Firefox' )){
            console.log (unique[i]+' \n is IRRELEVANT because of it\'s Product --> '+product + 'having component --> ' + component);
            irrelevant[i] = 'true';
            // return;
        } else if (product != 'Add-on SDK'      &&
                   product != 'Cloud Services'  &&
                   product != 'Core'            &&
                   product != 'Firefox'         &&
                   product != 'Hello (Loop)'    &&
                   product != 'Toolkit') {
            console.log (unique[i]+' \n is IRRELEVANT because of it\'s Product --> '+product);
            irrelevant[i] = 'true';
            // return;
        } else if (component == 'AutoConfig'                  ||
                   component == 'Build Config'                ||
                   component == 'DMD'                         ||
                   component == 'Embedding: GRE Core'         ||
                   component == 'Embedding: Mac'              ||
                   component == 'Embedding: MFC Embed'        ||
                   component == 'Embedding: Packaging'        ||
                   component == 'Hardware Abstraction Layer'  ||
                   component == 'mach'                        ||
                   component == 'Nanojit'                     ||
                   component == 'QuickLaunch'                 ||
                   component == 'Widget: Gonk') {
            console.log (unique[i]+' \n is IRRELEVANT because of it\'s Component --> '+component);
            irrelevant[i] = 'true';
            // return;
        } else {
          irrelevant[i] = 'false';
          console.log('                                                                   OK  '+unique[i]);
          // return;
        }

         
         // blackflag++;

         var orio = unique.length -1;
          // alert ('blackflag= ' + blackflag + '| Orio= ' + orio);
          if (blackflag == orio ) {                                   // Don/t put `unique.length -1` inside parentheses, i.e. NOT `(unique.length -1)''
          // blackflag = 1;
            onComplete();
          // return;
          }
          blackflag++;
          return;


        









   } });}

















// while ( i == unique.length -1 ){

function onComplete(){



var tmp;
// alert (irrelevant[7]);
for (var z=0; z < unique.length; z++){
  if (irrelevant[z] == 'true'){
    continue;
  } else {
    // tmp = '<a href="' + unique[z] + '">#'+ bugNumbers[z] + '</a>' +  ' (' + products[z] + ': ' + components[z] + ') ' + titles[z] + '<br>';
    tmp = '<a href="' + unique[z] + '">#'+ bugNumbers[z] + '</a>' +  ' (' + products[z] + ': ' + components[z] + ') ' + titles[z] + '[' + platforms[z] + ']' + '[' + whiteboards[z] + ']' + '<br>';
    bugsComplete.push(tmp);
  }
}







// SORTING based on the bugs 'Product' value
var rx = /.*<\/a>\ (.*)/;
bugsComplete.sort(function(x,y){
    return getSortingKey(x) > getSortingKey(y);      // If you use `<` instead, you'll get sorting in descending order
});

function getSortingKey(value) {
    return value.match(rx)[1];
}






// Variable that will contain all values of the bugsComplete array, and will be displayed in the 'dialog' below
var docu ='';
docu = bugsComplete.join("");




var div = document.createElement('div');
$('div.page_nav').append(div);
div.id = 'dialog';
docu = '<div id="dialog" title="Relevant Bugs">' + docu + '</div>';
div.innerHTML = docu;
$("#dialog").hide();







$(function() {
  $( "#dialog" ).dialog({
    title: 'List of relevant bugs ('+ bugsComplete.length + ')',
    /*
    buttons: [
      {
      click: function() {
        $( this ).dialog( "close" );
      }
    }
   ],
   */
    // width: 'auto'
    width: '1350px'
  });
});


console.log ('ALL IS DONE');


// }


// i++;
}