aboutsummaryrefslogtreecommitdiffstats
path: root/data/rhlib/rhbzpage.js
blob: a130306950d602342c3ae2384c2c8f410723afa0 (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
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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php

// For identification of graphics card
var manuChipStrs = [ [ "ATI Radeon", "ATI", "1002" ],
                     [ "ATI Mobility Radeon", "ATI", "1002" ],
                     [ "Intel Corporation", "INTEL", "8086" ], [ "NVIDIA", "NV", "10de" ] ];

// http://en.wikipedia.org/wiki/HSL_color_space
// when only the value of S is changed
// stupido!!! the string is value in hex for each color
var RHColor = new Color(158, 41, 43); // RGB 158, 41, 43; HSL 359, 1, 39
var FedoraColor = new Color(0, 40, 103); // RGB 0, 40, 103; HSL 359, 1, 39
var RawhideColor = new Color(0, 119, 0); // or "green", or RGB 0, 119, 0, or
// HSL
// 120, 0, 23
var RHITColor = new Color(102, 0, 102); // RGB 102, 0, 102; HSL 300, 0, 20
var titleParsedAttachment = "Part of the thread where crash happened";

// [ 126.386] (--) NOUVEAU(0): Chipset: "NVIDIA NVaf"
var logAnalyzeLogic = {
    "AnalyzeInterestingLine": {
      /*
       * [ 126.378] (--) PCI:*(0:4:0:0) 10de:08a0:106b:00c2 rev 162, Mem @
       * 0xd2000000/16777216, \ 0xc0000000/268435456, 0xd0000000/33554432, I/O @
       * 0x00001000/128, BIOS @ 0x????????/131072
       */
      re: [
           "^(\\[[ .0-9]+\\])?\\s*\\(--\\) PCI:\\*\\([0-9:]+\\)\\s*" +
           "([0-9a-f:]+).*$",
           "^\\s*\\[?[ 0-9.]*\\]?\\s*\\(--\\) "+
           "([A-Za-z]+)\\([0-9]?\\): Chipset: (.*)$",
           ],
           func: chipsetMagic
    },
    /*
     * [ 126.385] (WW) Falling back to old probe method for vesa [ 126.385] (WW)
     * Falling back to old probe method for fbdev [ 126.386] (--) NOUVEAU(0):
     * Chipset: "NVIDIA NVaf" Backtrace: [ 33.158] Kernel command line: ro
     * root=LABEL=root rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8
     * SYSFONT=latarcyrheb-sun16 KEYTABLE=us drm.debug=0x04
     *
     */
    "AnalyzeXorgLogBacktrace": {
      re:  "^\\s*(\\[[0-9 .]*\\])?\\s*(\\((EE|WW)\\)|.* [cC]hipset:.*)|\\s*(Backtrace|Kernel command line)",
      func: analyzeXorg
    }
};

var ProfessionalProducts = [
                            "Red Hat Enterprise Linux",
                            "Red Hat Enterprise MRG"
                            ];

// END OF CONSTANTS

var btSnippet = null;


function RHOnMessageHandler(msg, nextHandler) {
  switch (msg.cmd) {
  case "Error":
    alert("Error " + msg.data);
    break;
  case "Unhandled":
    break;
  case "AddAttachmentCallback":
    addAttachmentCallback(msg.data);
    break;
  case "FixAttachmentMIMECallback":
    XMLRPCcallback();
    break;
  case "AnalyzeInterestingLine":
  case "AnalyzeXorgLogBacktrace":
    findInterestingLine(msg.data, msg.cmd);
    break;
  case "queryUpstream":
    queryUpstreamCallback(msg.data, constantData.queryUpstreamBug);
    break;
  default:
    if (nextHandler) {
      var nextHandler = nextHandlerList.splice(0, 1);
      if (nextHandler[0]) {
        nextHandler[0](msg, nextHandlerList);
      }
    }
    else {
      console.error("Error: unknown RPC call " + msg.toSource());
    }
  break;
  }
}

// RHBugzillaPage object

/**
 * Auxiliary function to compute more complicated resolution
 */
function closeSomeRelease() {
  // for RAWHIDE close as RAWHIDE,
  // if active selection -> CURRENTRELEASE
  // and put the release version to
  // "Fixed in Version" textbox
  // otherwise -> NEXTRELEASE
  selectOption("bug_status", "CLOSED");
  var text = getSelection();
  var resolution = "";

  if (text.length > 0) {
    resolution = "CURRENTRELEASE";
    document.getElementById("cf_fixed_in").value = text;
  }
  else if (document.getElementById("version").value === "rawhide") {
    resolution = "RAWHIDE";
  }
  else {
    resolution = "NEXTRELEASE";
  }
  centralCommandDispatch("resolution", resolution);
}

/**
 * Additional commands specific for this subclass, overriding superclass one.
 */
function RHcentralCommandDispatch(cmdLabel, cmdParams) {
  switch (cmdLabel) {
  // Set up our own commands
  case "closeUpstream":
    addClosingUpstream();
    break;
  case "computeResolution":
    closeSomeRelease();
    break;
  case "queryStringUpstreamBugzilla":
    queryUpstream(constantData.queryUpstreamBug);
    break;
  case "sendBugUpstream":
    sendBugUpstream();
    break;
  case "markTriaged":
    markBugTriaged();
    break;
  case "chipMagic":
    fillInWhiteBoard(cmdParams);
    break;
    // If we don't have it here, call superclass method
  default:
    if (MozCentralCommandDispatch) {
      MozCentralCommandDispatch(cmdLabel, cmdParams);
    }
    else {
      console.error("Unknown command:\n" + cmdLabel + "\nparameters:\n" + cmdParams);
    }
  break;
  }
}

/* === Bugzilla functions === */

/**
 * Make it sailent that the some attachments with bad MIME type are present
 *
 * @param atts
 *          Array of attachments subarrays
 * @return none
 */
function markBadAttachments(atts) {
  var badMIMEArray = [ "application/octet-stream", "text/x-log", "undefined" ];
  if (!constantData.passwordState.passAvailable) {
    console.myDebug("markBadAttachments : No password, no XML-RPC calls; sorry");
    return null;
  }

  var badAttachments = atts.filter(function(att) {
    return (isInList(att[2], badMIMEArray));
  });

  if (badAttachments.length > 0) {
    var titleElement = document.
    getElementsByClassName("bz_alias_short_desc_container")[0];
    titleElement.style.backgroundColor = "olive";

    createDeadLink("fixAllButton", "Fix all", titleElement, function() {
      Array.forEach(badAttachments, function(x) {
        fixAttachById(x[1], constantData.XMLRPCData[window.location.hostname].url);
      });
    }, [], false, null, "f");
    badAttachments.forEach(function(x, i, a) {
      addTextLink(x, constantData.XMLRPCData[window.location.hostname].url);
    });
  }
}

/**
 * Open a tab in the upstream bugzilla to create a new bug
 *
 * @return none
 */
function sendBugUpstream() {
  var admitMsg = "(originally filed as " + window.location.href + ")\n\n";
  var urlStr = filterByRegexp(constantData.newUpstreamBug, getComponent());
  if (!urlStr) {
    return null;
  }
  
  self.postMessage(new Message("OpenBugUpstream", {
    url: urlStr,
    subject: document.getElementById("short_desc_nonedit_display").
    textContent.trim(),
    comment: admitMsg + collectComments()
  }));
}

/**
 * Add a link opening selected lines of Xorg.0.log
 *
 * @return none
 */
function addCheckXorgLogLink(attList) {
  if (config.XorgLogAnalysis) {
    attList.forEach(function (row) {
      var elemS = row[4].getElementsByTagName("td");
      var elem = elemS[elemS.length - 1];
      createDeadLink("xorgLogAnalyzeLink", "check", elem,
          analyzeXorgLog, [row[1], "AnalyzeXorgLogBacktrace"], "br");
    });
  }
}

/**
 * Given line to be parsed, find out which chipset it is and fill in the
 * whiteboard
 *
 * @param PCIidArrObj
 *          object with two fields id Array manufacturer-ID and product-ID (PCI
 *          IDs) chipsetLine whole line containing PCI ID.
 * @param driverStr
 *          String with the driver name
 * @return None
 *
 */
function fillInWhiteBoard(cardName) {
  console.myDebug("fillInWhiteBoard: cardName = " + cardName);
  clickMouse("editme_action");
  var titleElem = document.getElementById('short_desc');
  titleElem.value = '[' + cardName + ']\u00A0' + titleElem.value;
  document.getElementById("fillin_btn").style.display = "none";
}

/**
 * Get attached Xorg.0.log, parse it and find the value of chip. Does not fill
 * the whiteboard itself, just adds button to do so,paramList so that slow
 * XMLHttpRequest is done in advance.
 *
 * @param log
 *          array of XorgLogAttList
 * @return None
 */
function fillInChipMagic(XlogID) {
  analyzeXorgLog(XlogID, "AnalyzeInterestingLine");
}

/**
 * Creates a button to change summary by adding a graphic chip label
 *
 * @param Array
 *          with matching results of re.exec()
 */
function chipsetMagic (interestingLineArr) {
  // parse Xorg.0.log
  var cardStr = "";
  console.myDebug("interestingLineArr[1] = " + interestingLineArr[1]);

  if (interestingLineArr.length >0) {
    var interestingArray = interestingLineArr[0];
    if (interestingArray.length > 1) {
      var interestingPCIID = interestingArray[2].trim().split(":");
      // If we have Chipset line, we should parse it as well and
      // add to the button
      if (interestingLineArr.length > 1) {
        var PCIid = (interestingPCIID[0] + "," + interestingPCIID[1]).
        toUpperCase();
        // Nvidia driver provides good code in the Chipset line
        if (interestingPCIID[0].toLowerCase() == "10de") {
          cardStr = interestingLineArr[1][2].
          replace(/\s*nvidia\s*/ig,"").
          replace('"','','g');
        } else {
          try {
            cardStr = constantData.chipNames[PCIid][0];
          } catch (e if e instanceof TypeError)  {
            PCIid = PCIid.toLowerCase().replace(",",":");
            cardStr = null;
            alert("PCI ID " + PCIid + " is not known!");
            self.postMessage(new Message("SetClipboard", PCIid.toString()));
          } catch (e) {
            throw e;
          }
        }
      }
      else {
        cardStr = null;
      }

      if (cardStr) {
        createNewButton("short_desc_nonedit_display", false, {
          "name": "Fill In",
          "chipMagic": cardStr
        });
      }
    }
  }
}

function analyzeXorg(results) {
  var innerString = "";

  if (results.length > 0) {
    results.splice(0, 1); // remove headers
    results.sort();

    results.forEach(function(lRE) {
      innerString += lRE.input + "<br>\n";
    });
    innerString += "----------<br>\n" +
    results.length + " interesting lines found.";
  }
  else {
    innerString += "No matching lines found!";
  }

  self.postMessage(new Message("OpenStringInPanel",
      '<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">' +
      "<html><head><title>Xorg.0.log analysis</title></head><body><pre>\n" +
      innerString.trim() +
  "\n</pre></body></html>"));
}

function analyzeXorgLog(attachID, backMsg) {
  self.postMessage(new Message("GetURL", {
    url: "https://" + window.location.hostname + "/attachment.cgi?id=" + attachID,
    backMessage: backMsg
  }));
}

function findInterestingLine(wholeLog, backMsg) {
  var REstr = logAnalyzeLogic[backMsg].re;
  var REarr = [];
  if (typeof REstr == "string") {
    REarr = [new RegExp(REstr)];
  }
  else if (Array.isArray(REstr)) {
    REarr = REstr.map(function (reone) {
      return new RegExp(reone);
    });
  }
  console.myDebug("Current REs:");
  REarr.forEach(function (re) {
    console.myDebug("re: " + re.source);
  });

  var results = [];
  wholeLog.split("\n").
  forEach(function(line) {
    REarr.forEach(function (re, reIdx) {
      if (re.test(line)) {
        console.myDebug("Found match on line:\n" + line);
        console.myDebug("Result: " + re.exec(line).toSource());
        results.push(re.exec(line));
      }
    });
  });
  console.myDebug("results = " + results.toSource());
  logAnalyzeLogic[backMsg].func(results);
}

/**
 * Add information about the upstream bug upstream, and closing it.
 *
 * @param evt
 *          Event which called this handler
 * @return none
 */
function addClosingUpstream() {
  var refs = document.getElementById("external_bugs_table")
  .getElementsByTagName("tr");

  // that's a bad id, if there is a one. :)
  var inputBox = document.getElementById("inputbox");
  var externalBugID = 0;
  var wholeURL = "";

  // Fix missing ID on the external_id SELECT
  document.getElementsByName("external_id")[0].setAttribute("id",
  "external_id");

  if (inputBox.value.match(/^http.*/)) {
    wholeURL = inputBox.value;
    // TODO this is probably midlly ineffective ... we do parseURL here,
    // and getBugNoFromURL does it as well.
    externalBugID = getBugNoFromURL(wholeURL);
    if (externalBugID) {
      inputBox.value = externalBugID;
    }
    // get bugzillaName and set the label
    var bugzillaName = getBugzillaName(parseURL(wholeURL).host,
      constantData.bugzillaLabelNames);
    selectOptionByLabel("external_id", bugzillaName);
  }
  else if (!isNaN(inputBox.value)) {
    externalBugID = parseInt(inputBox.value, 10);
    var bugzillaHostname = document.getElementById("external_id").value;
    wholeURL = bugzillaHostname+"show_bug.cgi?id="+externalBugID;
  }
  else {
    // no inputBox.value -- maybe there is an external bug from
    // the previous commit?
  }

  // It is not good to close bug as UPSTREAM, if there is no reference
  // to the upstream bug.
  if ((externalBugID > 0) || (refs.length > 2)) {
    var msgStr = constantData.commentStrings.sentUpstreamString;
    msgStr = msgStr.replace("§§§", wholeURL);
    centralCommandDispatch("comment",msgStr);
    centralCommandDispatch("status", "CLOSED");
    centralCommandDispatch("resolution", "UPSTREAM");
  }
  else {
    console.myDebug("No external bug specified among the External References!");
  }
}

/**
 *
 */
function parseBacktrace (ret) {
  var signalHandler = new RegExp("^\\s*#[0-9]*\\s*<signal handler called>");
  var frameNo = new RegExp("^\\s*#([0-9]*)\\s");

  var splitArray = ret.split("\n");
  var i = 0, ii = splitArray.length;
  var outStr = "", curLine = "", numStr = "";
  var lineCounter = 0, endLineNo = 0;

  // TODO shouldn't we just cut off and analyze whole thread?
  while (i < ii) {
    if (signalHandler.test(splitArray[i])) {
      break;
    }
    i++;
  }

  if (i < ii) {
    lineCounter = parseInt(frameNo.exec(splitArray[i])[1], 10);
    endLineNo = lineCounter + NumberOfFrames;
    curLine = splitArray[i];
    while ((lineCounter < endLineNo) && (curLine.trim().length > 0)
        && (i < ii)) {
      outStr += curLine + '\n';
      numStr = frameNo.exec(curLine);
      if (numStr) {
        lineCounter = parseInt(numStr[1], 10);
      }
      i++;
      curLine = splitArray[i];
    }
    return outStr;
  }
  return "";
}

function RHBZinit(attachments) {
  // inheritance ... call superobject's constructor
  var AbrtRE = new RegExp("^\\s*\\[abrt\\]");
  var btSnippet = "";

  var chipMagicInterestingLine = "";

  // getBadAttachments
  var XorgLogAttList = [];
  var XorgLogAttListIndex = 0;
  markBadAttachments(attachments);

  var parsedAttachments = attachments.filter(function (att) {
    return (new RegExp(titleParsedAttachment).test(att[0]));
  });

  if (constantData.defaultAssignee) {
    setDefaultAssignee();
  }

  if (constantData.xorgBugsCategories) {
    var XBZlist = filterByRegexp(constantData.
        xorgBugsCategories, getComponent());
    if (XBZlist) {
      makeBugCategoriesList(XBZlist);
    }
  }

  // setup logging only when we ask for it
  if (config.submitsLogging && (window.location.hostname == "bugzilla.redhat.com")) {
    setUpLogging();
  }

  // Dig out backtrace protection against double-firing?
  btSnippet = "";

  var parseAbrtBacktraces = config.parseAbrtBacktraces;
  if (parseAbrtBacktraces && AbrtRE.test(getSummary())) {
    pasteBacktraceInComments(parsedAttachments);
  }

  // Find out Xorg.0.log attachment URL
  XorgLogAttList = attachments.filter(function (value) {
    // Xorg.0.log must be text, otherwise we cannot parse it
    return (/[xX].*log/.test(value[0]) && /text/.test(value[2]));
  });

  // Just add a link to every Xorg.0.log link analyzing it.
  addCheckXorgLogLink(XorgLogAttList);

  setBranding(XorgLogAttList);

  // Don't allow to submit a page which would change the bug to 0xFFFF component
  document.forms.namedItem("changeform").addEventListener(
      "submit", function(aEvt) {
        if (getComponent() == "0xFFFF") {
          alert("Don't change the component to 0xFFFF");
          aEvt.stopPropagation();
          aEvt.preventDefault();
        }
      }, false);

  // Uncheck "set default assignee" when the assignee is changed by other means
  document.getElementById("assigned_to").addEventListener("change",
      function() {
    changeAssignee(null);
  }, false);
}