aboutsummaryrefslogtreecommitdiffstats
path: root/bugzillaBugTriage.js
blob: bfe1419ee41d33f5dc2972afa24a99d553c707fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// 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);