aboutsummaryrefslogblamecommitdiffstats
path: root/bugzillaBugTriage.js
blob: bfe1419ee41d33f5dc2972afa24a99d553c707fb (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12

                                                     
 

                                        
 





                                           
                                                         


                                                                



                                                                 


                                                                 

                                                                        


                   



                                                                            

















                                         
































                                                                                          
 
                             





                                                                     
         

                  
 
                                                                








                                                                                         
                                 


                                               
                                                                                            


                                    
                                                     




                          
                                                                               
                      



















                                                                               
             
           
         
 

                         


   
                                      
  

                                     
  
   


                                                         

 
                        

   
                                                                                  
  
   








                                                             


                                                                          
  


                                                      

               
   
                                            
                            


                                                                    



                                               

                                                               






                                                                           

                                                           


                                                                




                                                    

          







                                                                                  
 

 
                              
                                  
  
 

                   
                                                 

                                                  
                                        
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php

jetpack.future.import("pageMods");
jetpack.future.import("storage.simple");

var RHColor = "#9E292B";
var FedoraColor = "#002867";
var RawhideColor = "#007700"; // or "green"
var RHITColor = "#660066";
var SalmonPink = "#FFE0B0";
var ReporterColorHex = "#FFFFA6";
var XMLRPCurl = "https://bugzilla.redhat.com/xmlrpc.cgi";
var myConfig = jetpack.storage.simple;

//==============================================================
// CONFIGURE: The easiest method how to set up the configuration
// value is to uncomment the following line with proper URL as
// the second parameter. Then reload the bug page and comment out
// again.
// myConfig.JSONURL = "URL-somewhere-with-your-JSON";
var jsonDataURL = myConfig.JSONURL ? myConfig.JSONURL : 
    "http://mcepl.fedorapeople.org/scripts/BugZappers_data.json";
var PCIIDsURL = "http://mcepl.fedorapeople.org/scripts/drm_pciids.json";
//var debug = GM_getValue("debug",false);
var reqCounter = 0;
var msgStrs = {};

var CommentRe = RegExp("^\\s*#");
var BlankLineRe = RegExp("^\\s*$");
var ChipsetRE = RegExp("^\\(--\\) ([A-Za-z]+)\\([0-9]?\\): Chipset: (.*)$");
var ATIgetIDRE = RegExp("^.*\\(ChipID = 0x([0-9a-fA-F]+)\\).*$");

// For identification of graphics card
var manuChipStrs = [
    ["ATI Radeon","ATI","1002"],
    ["ATI Mobility Radeon","ATI","1002"],
    ["Intel Corporation","INTEL","8086"],
    ["NVIDIA","NV","10de"]
];
var backTranslateManufacturerPCIID = [{
        regexp: "ATI Technologies Inc",
        addr: "1002"
    },{
        regexp: "Intel Corporation",
        addr: "8086"
    },{
        regexp: "nVidia Corporation",
        addr: "10de"
}];
// Initialize data from remote URL
var XMLHTTPRequestDone = false;
var hashBugzillaName = Array();
var hashBugzillaWholeURL = Array();
var defAssigneeList = Array();
var signatureFedoraString = "";
// TODO we should have an array SpecialFlags instead of multiple Boolean variables
var queryButtonAvailable = false;
var chipIDsGroupings = Array();
var AddrArray = Array();
var PCI_ID_Array = Array();
var XorgLogAttList = Array();
var XorgLogAttListIndex = 0;

// Get JSON configuration data
var JSONXHR = new XMLHttpRequest();
JSONXHR.open("GET",jsonDataURL,true);
JSONXHR.onreadystatechange = function(response) {
	var data = JSON.parse(response.responseText);
	console.log("data = " + data);
	msgStrs = data['strings'];
	signatureFedoraString = data['signature'];
	hashBugzillaName = data['bugzillalabelNames'];
	hashBugzillaWholeURL = data['bugzillaIDURLs'];
	// [{'regexp to match component':'email address of an universal maintainer'}, ...]
	AddrArray = data['CCmaintainer'],
	console.log("AddrArray = " + AddrArray);
	defAssigneeList = data['defaultAssignee'],
	queryButtonAvailable = data['queryButton'];
	chipIDsGroupings = data['chipIDsGroupings'];
	buildButtons(data['topRow'],data['bottomRow']);
};
JSONXHR.send(null);

// Get card translation table
var PCIXHR = new XMLHttpRequest();
PCIXHR.open("GET",PCIIDsURL,true);
PCIXHR.onreadystatechange = function(response) {
    if (response.readyState == 4) {  
        if (response.status == 200)  
		    PCI_ID_Array = JSON.parse(response.responseText);
	}
};
PCIXHR.send(null);

//==============================================================

/**
 * select element of the array where regexp in the first element matches second parameter
 * 		of this function
 * @param list array with regexps and return values
 * @param chosingMark string by which the element of array is to be matched
 * @return string chosen element
 */
function filterByRegexp(list,chosingMark) {
	var chosenPair = Array();
	if (list.length > 0) {
		chosenPair = list.filter(
				function(pair){
					return RegExp(pair['regexp'],"i").test(chosingMark);
				});
	};
	if (chosenPair.length > 0) {
		return $.trim(chosenPair[0]['addr']);
	} else {
		return "";
	}
}

///////////////////////////////////////////////////////////////////////////////
function bzPage(doc) {
    this.doc = $(doc);
    this.reporter = $("#bz_show_bug_column_2 > table .vcard:first > a",
        this.doc).attr("title");
    this.product   = $("#product option:selected:first",this.doc).text();
    this.component = $("#component option:selected:first",this.doc).text();
    console.log("component = " + this.component);
    console.log("AddrArray = " + AddrArray.toSource());
    this.version   = $("#version option:selected:first",this.doc).text();
    this.its       = $.trim($("#cf_issuetracker",this.doc).text());
    this.maintCCAddr = filterByRegexp(AddrArray,this.component).toLowerCase();
    console.log("maintCCAddr = " + this.maintCCAddr);

    // Take care of signature for Fedora bugzappers
    if (signatureFedoraString.length > 0) {
        // (or a form named "changeform")
        $("form::nth-child(2)",this.doc).submit(function () {
        	var cmntText = $("#comment",this.doc);
            if ((signatureFedoraString.length > 0) &&
                    ($.trim(cmntText.text()).length > 0)) {
            	cmntText.text($.trim(cmntText.text()) + signatureFedoraString);
            }
        });
	}

    this.setBranding();
    this.checkComments();
}

/**
 * Check for the presence of a keyword
 *
 * @param str string with the keyword
 * @return Boolean
 *
 */
bzPage.prototype.hasKeyword = function(str) {
	 var kwd = $.trim($('keywords',this.doc).text());
	 return (RegExp(str).test(kwd));
}

/* Bugzilla functions.*/

/**
 * Set background color of all comments made by reporter in ReporterColorHex color
 *
 */
bzPage.prototype.checkComments = function() {
    var reporter = this.reporter;
    $("#comments .bz_comment",this.doc).each(function (i) {
        var email = $(".vcard a",this).text();
        if (RegExp(reporter).test(email)) {
            $(this).css("background-color",ReporterColorHex);
        }
    });
};

/**
 * Set branding colours to easily distinguish between Fedora and RHEL bugs
 *
 * @param brand string with product of the current bug
 * @param version string with the version of the bug
 * @param its string with the IsueTracker numbers
 * @return none
 *
 */
bzPage.prototype.setBranding = function () {
	var brandColor = "";
	
	if (RegExp("Red Hat Enterprise Linux").test(this.product)) {
		if (this.its.length > 0) {
			brandColor = RHITColor;
		} else {
			brandColor = RHColor;
		}
	} else if (RegExp("Fedora").test(this.product)) {
		if (RegExp("rawhide","i").test(this.version)) {
			brandColor = RawhideColor;
		} else {
			brandColor = FedoraColor;
		}
	}

	// Comment each of the following lines to get only partial branding
	$("body",this.doc).css("background",brandColor);
	$("#titles",this.doc).css("background",brandColor);

	 // Make background-color of the body of bug salmon pink
    // for security bugs.
	 if (this.hasKeyword("Security")) {
		  $("#bugzilla-body",this.doc).css({
		    'background-image' : 'none',
		    'background-color' : SalmonPink
		  });
	 }

//	// we should make visible whether maintCCAddr is in CCList
//	if (isInList(maintCCAddr, CCList)) {
//		var switchCCEdit=document.getElementById("cc_edit_area_showhide");
//		//switchCCEdit.textContent = "*"+switchCCEdit.textContent;
//		switchCCEdit.style.color = "navy";
//		switchCCEdit.style.fontWeight = "bolder";
//		switchCCEdit.style.textDecoration = "underline";
//	}

}

var callback = function(doc) {
    var curPage = new bzPage(doc);
};

var options = {};
options.matches = [
     "https://bugzilla.redhat.com/show_bug.cgi*",
     "https://bugzilla.redhat.com/process_bug.cgi"
     ];
jetpack.pageMods.add(callback, options);