Mozilla Mercurial - generate list of recently fixed bugs related to Firefox for desktop

It generates a list of recently fixed bugs related to Firefox for desktop in Mozilla Mercurial pushlogs

اعتبارا من 05-11-2015. شاهد أحدث إصدار.

// ==UserScript==
// @name        Mozilla Mercurial - generate list of recently fixed bugs related to Firefox for desktop
// @namespace   darkred
// @description It generates a list of recently fixed bugs related to Firefox for desktop in Mozilla Mercurial pushlogs
// @include     /^https?:\/\/hg\.mozilla\.org.*pushloghtml.*/
// @version     2
// @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
// ==/UserScript==



// theme for the jQuery dialog
$("head").append(
    '<link ' +
    'href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/redmond/jquery-ui.min.css" ' +
    // 'href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.min.css" ' +                 // uncomment this (and comment #19)  in order to change theme
    'rel="stylesheet" type="text/css">'
);







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 flag = 0;
var counter = 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)
    retrieveValues(unique[i], i);
}





while (flag == 1) {
    onComplete();
    flag++;
}












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

    var BugNumbers = [];

    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);
            bugNumbers.push(document.querySelector('tr.pushlogentry:nth-child(' + k + ') > td:nth-child(3) > strong:nth-child(1) > a:nth-child(1)').innerHTML.substring(4));


        }
    }

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

}











function retrieveValues(x, i) {


    // Example target: https://bugzilla.mozilla.org/rest/bug/1196053?include_fields=summary,status,resolution,product,component,platform,whiteboard
    var target = 'https://bugzilla.mozilla.org/rest/bug/' + x + '?include_fields=summary,status,resolution,product,component,platform,op_sys,whiteboard';
    var details = GM_xmlhttpRequest({
        method: 'GET',
        url: target,
        synchronous: false, // Asynchronous request
        onload: function(response) {





            var regex;




            bugNo = x;
            bugNumbers[i] = x;




            // get bug title
            regex = /.*summary&quot;\ :\ &quot;(.*)&quot;/;
            if (response.responseText.match(regex)) {
                title = response.responseText.match(regex)[1];
                title = title.replace(/\\/g, ''); // strip the \ from the titles
                title2 = title;
                titles[i] = title; // Helper array that stores the bugs titles
            }






            // get status
            var temp1, temp2;
            regex = /.*status&quot;\ :\ &quot;(.*)&quot;/;
            if (response.responseText.match(regex)) {
                temp1 = response.responseText.match(regex)[1];
            }
            regex = /.*resolution&quot;\ :\ &quot;(.*)&quot;/;
            if (response.responseText.match(regex)) {
                temp2 = response.responseText.match(regex)[1];
            }
            if (temp2 !== '') {
                status = temp1 + ' ' + temp2;
            } else {
                status = temp1;
            }


            regex = /.*product&quot;\ :\ &quot;(.*)&quot;/;
            if (response.responseText.match(regex)) {
                product = response.responseText.match(regex)[1];
                products[i] = product; // Helper array that stores the bugs products
            }


            regex = /.*component&quot;\ :\ &quot;(.*)&quot;/;
            if (response.responseText.match(regex)) {
                component = response.responseText.match(regex)[1];
                components[i] = component; // Helper array that stores the bugs components
            }



            regex = /.*platform&quot;\ :\ &quot;(.*)&quot;/;
            if (response.responseText.match(regex)) {
                platform = response.responseText.match(regex)[1];
                if (platform == 'Unspecified') {
                    platform = 'Uns';
                }

            }
            regex = /.*op_sys&quot;\ :\ &quot;(.*)&quot;/;
            var temp3;
            if (response.responseText.match(regex)) {
                temp3 = response.responseText.match(regex)[1];
                if (temp3 !== '' && temp3 != 'Unspecified') {
                    platform += '/' + temp3;
                }
            }
            platforms[i] = platform; // Helper array that stores the bugs  platforms





            regex = /.*whiteboard&quot;\ :\ &quot;(.*)&quot;/;
            if (response.responseText.match(regex)) {
                whiteboard = response.responseText.match(regex)[1];
                whiteboards[i] = whiteboard; // Helper array that stores the bugs whiteboard
            }









            counter++;

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






            if (title2 == 'Access Denied') {
                console.log(unique[i] + ' \n is IRRELEVANT because of it\'s has restricted access');
                irrelevant[i] = 'true';
            } else if (status != 'RESOLVED' &&
                status != 'RESOLVED FIXED' &&
                status != 'VERIFIED' &&
                status != 'VERIFIED FIXED') {
                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';
            } 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';
            } 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';
            } else {
                irrelevant[i] = 'false';
                console.log('                                                                   OK  ' + 'https://bugzilla.mozilla.org/show_bug.cgi?id=' + unique[i]);
            }



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


        }
    });
}


















function onComplete() {



    var tmp;
    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] + ' [' + 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 + ')',
            width: '1350px'
        });
    });


    console.log('ALL IS DONE');

}


// $(function() {
$("#dialog").dialog({
        modal: false,
        title: "Draggable, sizeable dialog",
        position: {
            my: "top",
            at: "top",
            of: document,
            collision: "none"
        },
        width: "auto",
        minWidth: 400,
        minHeight: 200,
        zIndex: 3666
    })
    .dialog("widget").draggable("option", "containment", "none");

//-- Fix crazy bug in FF! ...
$("#dialog").parent().css({
    position: "fixed",
    top: 0,
    left: "4em",
    width: "75ex"
});