Mozilla Mercurial - Filters changelogs

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

目前為 2015-10-20 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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
// @require     http://code.jquery.com/jquery-2.1.4.min.js
// @require     http://code.jquery.com/ui/1.11.4/jquery-ui.min.js
// ==/UserScript==




// CSS rules used for jQuery 'display' containing the relevant bugs list 
var stylesheet = '		                               \
<style>											                         \
.ui-dialog {                                         \
   background-color: white;                          \
   border: solid;                                    \
	border-width: 1px;                                 \
}                                                    \
button.ui-button:nth-child(2) {                      \
  position: absolute;                                \
 right: .3em;                                        \
 top: 10%;                                           \
 width: 40px;                                        \
 margin: -10px 0 0 0;                                \
 padding: 1px;                                       \
 height: 25px;                                       \
}                                                    \
#ui-id-1 {                                           \
background-color: rgb(225, 225, 225) !important;     \
font-size: 14px !important;                          \
}                                                    \
</style>';

$('head').append(stylesheet);














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);
  });

}





// Array with relevant 'Status' values
var statusYES = [
  'RESOLVED',
  'RESOLVED FIXED',
  'VERIFIED'
];





// Array with relevant 'Product' values
var productYES = [
  'Add-on SDK',
  'Cloud Services',
  'Core',
  'Firefox',
  'Hello (Loop)',
  'Toolkit'
];




// Array with irrelevant 'Component' values (relevant is only the ommited one 'Embedding: APIs' )
var ComponentNO = [
  'AutoConfig',
  'Build Config',
  'DMD',
  'Embedding: GRE Core',
  'Embedding: Mac',
  'Embedding: MFC Embed',
  'Embedding: Packaging',
  'Hardware Abstraction Layer',
  'mach',
  'Nanojit',
  'QuickLaunch',
  'Widget: Gonk'
];





var bugNumbers = [];

var title;
var status;
var product;
var component;



function retrieveValues(x,i) {
  
    var thisIndex = i;
  
  
    
    var target = x;
    var details = GM_xmlhttpRequest({
      method: 'GET',
      url: target,
      synchronous: true, // Synchronous request
      onload: function (response) {
        

        /*
        setTimeout(function() {
          1 + 1 == 2;
       }, 3000);
        */
        
        var regex;
        var result;
        
        
        
        
        // get bugNo
        var bugNo;
        regex = /https:\/\/bugzilla\.mozilla\.org\/show_bug\.cgi\?id=(.*)/;
        bugNo = x.match(regex)[1];
        // alert (bugNo);
        bugNumbers.push(bugNo);
        
        
                
        
        // get bug title     
        regex = /<title>.*\ &ndash;\ (.*)<\/title>/;        
        title = response.responseText.match(regex)[1];        
        titles.push(title);                                                // Helper array that stores the bugs titles
        
        
        // get status
        regex = /<span id="static_bug_status">(.*)/;        
        status = response.responseText.match(regex)[1];                    // No Helper array
        
                
        regex = /"field_container_product" >(.*)/;        
        product = response.responseText.match(regex)[1];
        products.push(product);                                            // Helper array that stores the bugs Product value
        
                
        regex = /"field_container_component" >(.*)/;
        component = response.responseText.match(regex)[1];
        components.push(component);                                        // Helper array that stores the bugs Component value

        
        
        
        console.log('----------------------------------------------------------------------------------------------------------------------------------');
        console.log(i+1 +"/"+unique.length);                                                      // Progression counter        
        console.log('BugNo: ' + bugNo + '\nTitle: ' + title + '\nStatus: '+status + '\nProduct: '+product+'\nComponent: '+component);
        
        
   
        
        
        
        // hasNoData[i] = true;    
        var flag = 0;

        

        if (status != 'RESOLVED' && status != 'RESOLVED FIXED'  && status != 'VERIFIED'){
          console.log (unique[i]+' \n is IRRELEVANT because of it\'s Status --> '+status);
          hasNoData[i] = true;          
          return;      
          
        }
            
            
              


        
        
        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);          
          hasNoData[i] = true;          
          return;  
          
        }
        
  
        
        
        
        
        flag = 0;       
        
        // (For filtering out bugs with irrelevant 'COMPONENT' values)
        // loop3:
        for (var t = 0; t < ComponentNO.length; t++) {          
          if (component == ComponentNO[t]) {
            console.log (unique[i]+' \n is IRRELEVANT because of it\'s Component --> '+component);    
            hasNoData[i] = true;          
            return;
          }
        }
        
        
        
            

        
     
        
        console.log('                                                                   OK  '+unique[i]);
        // hasNoData[i] = true;    
        return;
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
          }
      });
        
  
  
}
    





var bugsComplete = [];



  
/*

function removeIrrelevant(){  
}
*/



var unique = [];

var titles = [];
var products = [];
var components = [];
// var irrelevant = [];
var hasNoData = [];





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)
  retrieveValues(unique[i],i);  
}







var tmp;
for (var z=0; z < unique.length; z++){    
  if (hasNoData[z] !== true && typeof products[z] !== 'undefined'){     
    tmp = '<a href="' + unique[z] + '">#'+ bugNumbers[z] + '</a>' +  ' (' + products[z] + ': ' + components[z] + ') ' + titles[z] + '<br>';          
    alert (typeof products[z]);
    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: '1000px'
  });
});


console.log ('ALL IS DONE');