forked from jdm/bugsahoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magic.js
456 lines (411 loc) · 17.5 KB
/
magic.js
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
var bugzilla = bz.createClient();
var categoryMapping = {};
var groups = {};
function addSearchMapping(group, cat, searchParams) {
if (!(cat in categoryMapping))
categoryMapping[cat] = [];
categoryMapping[cat].push(searchParams);
if (!groups[group]) {
groups[group] = [];
}
groups[group].push(cat);
}
function addSimpleMapping(group, cat, prod, components) {
var params = {product: prod};
if (components) {
if (typeof(components) == "string")
components = [components];
params.component = components;
}
addSearchMapping(group, cat, params);
}
function timeFromModified(lastChangeTime) {
var lastModified = new Date(lastChangeTime);
var today = new Date();
var one_day = 1000*60*60*24;
return(Math.ceil((today.getTime() - lastModified.getTime()) / (one_day)));
}
function addComponentMapping(cat, prod, components) {
addSimpleMapping('components', cat, prod, components);
}
function addLanguageMapping(cat, language) {
addSearchMapping('langs', cat, {status_whiteboard: 'lang=' + language});
}
var githubMapping = {};
function addGithubMapping(group, cat, repos, tags) {
if (!(cat in githubMapping))
githubMapping[cat] = [];
if (typeof repos == "string")
repos = [repos];
if (typeof tags == "string")
tags = [tags];
for (var i = 0; i < repos.length; i++)
for (var j = 0; j < tags.length; j++)
githubMapping[cat].push({
repo: repos[i],
tag: tags[j]
});
if (!groups[group])
groups[group] = [];
groups[group].push(cat);
}
function addGithubComponentMapping(cat, repos, tags) {
addGithubMapping('components', cat, repos, tags);
}
addComponentMapping('a11y', 'Core', 'Disability Access APIs');
addComponentMapping('build', 'Core', ['Build Config']);
addComponentMapping('build', 'MailNews Core', ['Build Config']);
addComponentMapping('gfx', 'Core',
['Graphics', 'GFX: Color Management',
'Canvas: WebGL', 'Canvas: 2D', 'ImageLib', 'Graphics',
'Graphics: Layers', 'Graphics: Text']);
addComponentMapping('net', 'Core',
['Networking',
'Networking: HTTP',
'Networking: Cookies',
'Networking: File',
'Networking: JAR',
'Networking: WebSockets',
'Networking: DNS',
'WebRTC: Networking']);
addComponentMapping('layout', 'Core',
['Layout',
'Layout: Block and Inline',
'Layout: Floats',
'Layout: Form Controls',
'Layout: HTML Frames',
'Layout: Images',
'Layout: Misc Code',
'Layout: R & A Pos',
'Layout: Tables',
'Layout: Text',
'Layout: View Rendering']);
addComponentMapping('dom', 'Core',
['Style System (CSS)',
'SVG', 'DOM',
'DOM: Core & HTML',
'DOM: CSS Object Model',
'DOM: Device Interfaces',
'DOM: Events',
'DOM: IndexedDB',
'DOM: Mozilla Extensions',
'DOM: Other',
'DOM: Traversal-Range',
'DOM: Validation',
'DOM: Workers',
'Geolocation',
'HTML: Form Submission',
'Event Handling', 'HTML: Parser',
'MathML', 'XML', 'XSLT']);
addComponentMapping('editor', 'Core', ['Editor', 'Selection', 'Keyboard: Navigation',
'Drag and Drop', 'Spelling Checker']);
addComponentMapping('internals', 'Core', ['General', 'Widget', 'Document Navigation', 'XPCOM',
'Embedding: APIs', 'Embedding: GRE Core', 'Embedding: GTK Widget',
'Embedding: Mac', 'Embedding: Packaging',
'File Handling', 'Find Backend', 'Gecko Profiler',
'History (Global)', 'Image Blocking', 'Installer', 'IPC',
'MFBT', 'Plug-ins', 'Preferences: Backend', 'Print Preview',
'Printing: Output', 'Printing: Setup', 'Profile: BackEnd',
'Profile: Migration', 'Profile: Roaming', 'RDF',
'Rewriting and Analysis', 'Security', 'Security: CAPS', 'Security: PSM',
'Security: S/MIME', 'Security: UI',
'Serializers', 'SQL', 'String', 'XBL', 'XTF', 'XUL',
'Widget', 'Widget: Android', 'Widget: BeOS', 'Widget: Cocoa',
'Widget: Gtk', 'Widget: OS/2', 'Widget: Photon', 'Widget: Qt',
'Widget: Win32', 'XP Toolkit/Widgets: XUL', 'XP Toolkit/Widgets: Menus',
'Identity', 'Localization']);
addComponentMapping('internals', 'NSPR');
addComponentMapping('internals', 'NSS');
addComponentMapping('mobile', 'Fennec');
addComponentMapping('mobile', 'Firefox for Android');
addComponentMapping('mobile', 'Core', ['Widget: Android', 'mozglue']);
addComponentMapping('jseng', 'Core',
['Javascript Engine',
'js-ctypes',
'XPConnect',
'Nanojit']);
addComponentMapping('media', 'Core', ['Video/Audio', 'WebRTC', 'WebRTC: Audio/Video',
'WebRTC: Signalling']);
addComponentMapping('ff', 'Firefox');
addComponentMapping('ff', 'Toolkit');
addComponentMapping('ff', 'Mozilla Services', 'Firefox Sync: UI');
addComponentMapping('ff', 'Input', ['Frontend', 'General']);
addComponentMapping('devtools', 'Firefox',
['Developer Tools',
'Developer Tools: Console',
'Developer Tools: Debugger',
'Developer Tools: Inspector',
'Developer Tools: Scratchpad',
'Developer Tools: Style Editor']);
addComponentMapping('releng', 'mozilla.org', ['Release Engineering',
'Release Engineering: Automation (General)',
'Release Engineering: Developer Tools',
'Hg: Customizations']);
addComponentMapping('automation', 'Testing');
addGithubComponentMapping('automation', ['automatedtester/automation-services-bot',
'automatedtester/powerball-platform',
'automatedtester/testdaybot',
'automatedtester/unittest-zero',
'davehunt/flynnid',
'davehunt/pytest-mozwebqa',
'mozilla/bidpom',
'mozilla/memchaser',
'mozilla/moz-grid-config',
'mozilla/mozdownload',
'mozilla/mozmill-ci',
'mozilla/nightlytt',
'whimboo/mozmill-automation',
'whimboo/mozmill-crowd',
'mozilla/mozmill-dashboard',
'whimboo/mozmill-environment'], 'mentored');
addComponentMapping('sync', 'Mozilla Services', ['Firefox Sync: Backend',
'Firefox Sync: Build',
'Firefox Sync: Crypto',
'Firefox Sync: UI',
'Android Sync',
'Server: Sync']);
addComponentMapping('thunderbird', 'Thunderbird');
addComponentMapping('thunderbird', 'MailNews Core');
addComponentMapping('seamonkey', 'SeaMonkey');
addComponentMapping('calendar', 'Calendar');
addComponentMapping('b2g', 'Boot2Gecko');
addComponentMapping('b2g', 'Core', ['DOM: Device Interfaces', 'Hardware Abstraction Layer (HAL)']);
addGithubComponentMapping('b2g', 'mozilla-b2g/gaia', 'mentored');
addComponentMapping('metro', 'Firefox for Metro');
addLanguageMapping('py', 'py');
addLanguageMapping('sh', 'shell');
addSimpleMapping('langs', 'sh', 'Core', 'Build Config');
addSimpleMapping('langs', 'sh', 'MailNews Core', 'Build Config');
addSimpleMapping('langs', 'java', 'Core', 'Widget: Android');
addSimpleMapping('langs', 'java', 'Mozilla Services', 'Android Sync');
addLanguageMapping('java', 'java');
addLanguageMapping('js', 'js');
addSimpleMapping('langs', 'js', 'Mozilla Services', 'Firefox Sync: Backend');
addLanguageMapping('cpp', 'c');
addLanguageMapping('html', 'html');
addLanguageMapping('html', 'css');
addSearchMapping('ownership', 'unowned',
{assigned_to: ['[email protected]', '[email protected]']}
);
var interestingComponents = [];
var resultsCache = {};
var unfinishedResults = {};
function rebuildTableContents() {
var t = document.getElementById('bugs');
t.removeChild(document.getElementById('bugs_content'));
function unique_list(list, tr) {
var uniq = {};
for (var idx in list) {
var elem = list[idx];
uniq[tr(elem).toString()] = elem;
}
var new_list = [];
for (var prop in uniq) {
new_list.push(uniq[prop]);
}
return new_list;
}
var orderedBugList = [];
var results = {};
for (var group in groups) {
results[group] = [];
}
for (var idx in interestingComponents) {
var cat = interestingComponents[idx];
if (!(cat in resultsCache))
continue;
// Take unions within groups
for (var group in groups) {
if (groups[group].indexOf(cat) != -1) {
var tmp = results[group].concat(resultsCache[cat]);
results[group] = unique_list(tmp, function(bug) { return bug.id; });
}
}
}
// And take intersections between groups
// First get all the bugs
for (var group in results) {
var tmp = orderedBugList.concat(results[group]);
orderedBugList = unique_list(tmp, function(bug) { return bug.id; });
}
// Then remove those not in a given group
for (var group in results) {
if (!results[group].length) {
// gross. don't intersect if no components are selected, but do if there are no results from
// the selected components (ie. searching Python vs. Python+RelEng).
if ('components' != group ||
interestingComponents.filter(
function(cat) { return groups['components'].indexOf(cat) != -1; }
).length == 0)
continue;
}
var intersect_ids = results[group].map(function(bug) { return bug.id; });
orderedBugList = orderedBugList.filter(function(bug) {
return intersect_ids.indexOf(bug.id) != -1;
});
}
orderedBugList.sort(function(a, b) { return b.id - a.id; }); // sort by ID descending
var content = document.createElement('div');
content.id = "bugs_content";
for (idx in orderedBugList) {
var bug = orderedBugList[idx];
var elem = document.createElement('div');
var inner = document.createElement('span');
var link = document.createElement('a');
elem.setAttribute('tabindex', '0');
var url = bug.html_url || "http://bugzil.la/" + bug.id;
link.setAttribute('href', url);
link.setAttribute('target', "_blank");
var text = document.createTextNode(bug.id);
var text2 = document.createTextNode(" - " + bug.summary);
elem.appendChild(inner);
link.appendChild(text);
inner.appendChild(link);
inner.appendChild(text2);
var daysOld = timeFromModified(orderedBugList[idx].last_change_time);
elem.setAttribute('class', "bug moreInfo");
if (daysOld !== 1) {
elem.setAttribute('alt', daysOld + " days since last update<br /> Assigned to : " + orderedBugList[idx].assigned_to.real_name);
}else{
elem.setAttribute('alt', daysOld + " day since last update<br /> Assigned to : " + orderedBugList[idx].assigned_to.real_name);
}
content.appendChild(elem);
}
if (orderedBugList.length == 0 || interestingComponents.length == 0) {
var elem = document.createElement('div');
var inner = document.createElement('span');
var text = document.createTextNode(interestingComponents.length == 0 ?
'No categories specified' :
'No bugs found');
inner.appendChild(text);
elem.appendChild(inner);
content.appendChild(elem);
elem.setAttribute('class', 'bug');
}
t.appendChild(content);
document.getElementById('total').textContent = '(' + orderedBugList.length + ')';
document.getElementById('throbber').style.visibility = "hidden";
jQuery('.moreInfo').each(function(count){
var qt = jQuery(this).qtip({
content: jQuery(this).attr('alt'),
prerender: true,
show: {
event: 'focus mouseover'
},
position: {
my: 'center left',
at: 'center right',
target: jQuery('.moreInfo:eq('+count+')')
},
style: {
classes: 'ui-tooltip-light ui-tooltip-shadow'
},
hide: {
fixed: true,
event: 'blur mouseout',
delay: 50,
leave: true
},
events: {
show: function(ev) {
$(qt).qtip("api").elements.tooltip[0].setAttribute('role', 'tooltip');
return true;
}
}
});
});
}
function retrieveResults(category) {
if (category in resultsCache) {
rebuildTableContents();
return;
}
document.getElementById('throbber').style.visibility = "visible";
var mapping = categoryMapping[category];
var ghMapping = githubMapping[category] || [];
var expectedResults = mapping.length + ghMapping.length;
function processResult(msg, results) {
if (!(category in unfinishedResults))
unfinishedResults[category] = [];
unfinishedResults[category].push.apply(unfinishedResults[category],
results);
expectedResults--;
if (expectedResults == 0) {
unfinishedResults[category] =
unfinishedResults[category].sort(function(a, b) { return b.id - a.id; });
resultsCache[category] = [];
if (unfinishedResults[category].length > 0)
resultsCache[category].push(unfinishedResults[category][0]);
for (var i = 1; i < unfinishedResults[category].length; i++) {
if (unfinishedResults[category][i].id != unfinishedResults[category][i-1].id)
resultsCache[category].push(unfinishedResults[category][i]);
}
delete unfinishedResults[category];
rebuildTableContents();
}
}
for (var i = 0; i < mapping.length; i++) {
var searchParams = {status_whiteboard: 'mentor=',
whiteboard_type: 'contains_all',
bug_status: ["NEW","ASSIGNED","REOPENED", "UNCONFIRMED"],
/*component_type: 'equals',*/
product: ''};
for (var param in mapping[i]) {
if (!(param in searchParams))
searchParams[param] = [];
if (typeof(searchParams[param]) == "string")
searchParams[param] += " " + mapping[i][param];
else {
for (var j = 0; j < mapping[i][param].length; j++)
searchParams[param].push(mapping[i][param][j]);
}
}
bugzilla.searchBugs(searchParams, processResult);
}
for (var i = 0; i < ghMapping.length; i++) {
(function(i) {
var curMap = ghMapping[i];
var user = curMap.repo.split('/')[0];
var name = curMap.repo.split('/')[1];
var apiCall = 'repos/' + user + '/' + name + '/issues?labels=' + curMap.tag;
$.getJSON('cgi-bin/githubapi.cgi?url=' + encodeURIComponent(apiCall),
null, function(data) {
for (var d in data) {
data[d].id = data[d].number;
data[d].assigned_to = data.assignee || {real_name: "nobody"};
data[d].summary = user + '/' + name + ' - ' + data[d].title;
data[d].last_change_time = data[d].updated_at;
}
processResult(null, data);
}).error(function() { processResult(null, []); });
})(i);
}
}
function toggleCategory(e)
{
var id = e.target.getAttribute('id');
var extra = document.getElementById(id + "-extra");
if (e.target.checked) {
interestingComponents.push(id);
if (extra)
extra.style.display = "table";
retrieveResults(id);
} else {
var idx = interestingComponents.indexOf(id);
if (idx != -1)
interestingComponents.splice(idx, 1);
if (extra)
extra.style.display = "none";
rebuildTableContents();
}
var query = [];
var checks = document.getElementsByTagName("input");
for (var i = 0; i < checks.length; i++) {
if (checks[i].type != "checkbox")
continue;
if (checks[i].checked) {
query.push(checks[i].id + "=1");
}
}
history.replaceState(null, '', window.location.pathname + '?' + query.join('&'));
}