diff options
author | Matěj Cepl <mcepl@redhat.com> | 2011-02-10 18:24:18 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2011-02-10 18:24:18 +0100 |
commit | 838c1d4abd72bd87dcc8ee41310ca3a8af498c96 (patch) | |
tree | f22b0cf123a08fc51c3c779ee5b0971aa2a174c0 | |
parent | ba0b4d6110e5b50c15ce722a5a123bcf26bafe3e (diff) | |
download | bugzilla-triage-838c1d4abd72bd87dcc8ee41310ca3a8af498c96.tar.gz |
All functions should be (theoretically) either working or commented out.
-rw-r--r-- | data/bzpage.js | 34 | ||||
-rw-r--r-- | data/rhbzpage.js | 373 | ||||
-rw-r--r-- | data/util.js | 17 | ||||
-rw-r--r-- | lib/libbugzilla.js | 88 | ||||
-rw-r--r-- | lib/main.js | 27 |
5 files changed, 290 insertions, 249 deletions
diff --git a/data/bzpage.js b/data/bzpage.js index 47f14c0..b980e96 100644 --- a/data/bzpage.js +++ b/data/bzpage.js @@ -16,6 +16,7 @@ var EmptyLogsColor = new Color(0, 255, 0); var FullLogsColor = new Color(0, 40, 103); // global variables +var config = {}; var constantData = {}; // This should be probably eliminated ASAP or // or done by other means. TODO var submitHandlerInstalled = false; // for setUpLogging @@ -53,15 +54,12 @@ onMessage = function onMessage(msg) { case "ReloadThePage": document.location.reload(true); break; - case "RetClipboard": - if (msg.data.cmd == "queryLocal") { - queryInNewTab(msg.data.data, getComponent(), getProduct()); - } else if (msg.data.cmd == "queryUpstream") { - // - } + case "queryLocal": + queryInNewTab(msg.data.data, getComponent(), getProduct()); break; case "CreateButtons": constantData = msg.data.constData; + config = msg.data.config; generateButtons(msg.data.instPkgs, msg.data.kNodes); break; case "Error": @@ -491,6 +489,15 @@ function parseMailto(aElement) { } /** + * Get the current title of the bug + * + * @return string + */ +function getSummary() { + return document.getElementById("short_desc_nonedit_display").textContent; +} + +/** * Get the current email of the reporter of the bug. * * @return string @@ -730,6 +737,8 @@ function getDefaultBugzillaMaintainer (component) { * @return array with string name of the attachment, integer its id number, * string of MIME type, integer of size in kilobytes, and the whole * element itself + * + * TODO error handling is missing ... it's bleee */ function parseAttachmentLine(inElem) { var MIMEtype = ""; @@ -737,19 +746,18 @@ function parseAttachmentLine(inElem) { // Skip over obsolete attachments if (inElem.getElementsByClassName("bz_obsolete").length > 0) { - return ( []); + return ([]); } // getting name of the attachment - // TODO probably could use url.URL object var attName = inElem.getElementsByTagName("b")[0].textContent.trim(); + // TODO probably could use url.URL object var aHrefsArr = inElem.getElementsByTagName("a"); var aHref = Array.filter(aHrefsArr, function(x) { return x.textContent.trim() === "Details"; })[0]; - var id = parseInt(aHref.getAttribute("href").replace( - /^.*attachment.cgi\?id=/, ""), 10); + var id = getParamsFromURL(aHref.getAttribute("href")).id; // getting MIME type and size var stringArray = inElem.getElementsByClassName("bz_attach_extra_info")[0].textContent. @@ -995,7 +1003,7 @@ function startup() { } // TODO Probably could be ignored ... used only once on line 973 of rhbzpage.js - // if (parseAbrtBacktraces && this.RE.Abrt.test(this.title)) { + // if (parseAbrtBacktraces && this.RE.Abrt.test(getSummary())) { // title = document.getElementById("short_desc_nonedit_display").textContent; // So, now we know we are logged in, so we can get to @@ -1009,6 +1017,10 @@ function startup() { location: window.location.href, login: getLogin() })); + + if (RHBZinit) { + RHBZinit(); + } } startup(); diff --git a/data/rhbzpage.js b/data/rhbzpage.js index 484fbff..60dda35 100644 --- a/data/rhbzpage.js +++ b/data/rhbzpage.js @@ -1,4 +1,3 @@ -/*jslint onevar: false, browser: true, evil: true, laxbreak: true, undef: true, nomen: true, eqeqeq: false, bitwise: true, maxerr: 1000, immed: false, white: false, plusplus: false, regexp: false, undef: false */ // Released under the MIT/X11 license // http://www.opensource.org/licenses/mit-license.php "use strict"; @@ -20,18 +19,6 @@ var RawhideColor = new Color(0, 119, 0); // or "green", or RGB 0, 119, 0, or // 120, 0, 23 var RHITColor = new Color(102, 0, 102); // RGB 102, 0, 102; HSL 300, 0, 20 -var RE = { - Comment: new RegExp("^\\s*#"), // unsused - BlankLine: new RegExp("^\\s*$"), // unused - // new line - // [ 65.631] (--) intel(0): Chipset: "845G" - Chipset: new RegExp("^\\s*\\[?[ 0-9.]*\\]?\\s*\\(--\\) "+ - "([A-Za-z]+)\\([0-9]?\\): Chipset: (.*)$"), - ATIgetID: new RegExp("^.*\\(ChipID = 0x([0-9a-fA-F]+)\\).*$"), - Abrt: new RegExp("^\\s*\\[abrt\\]"), - soughtLines: new RegExp("^\\s*(\\[[0-9 .]*\\])?\\s*(\\((EE|WW)\\)|.* [cC]hipsets?: )|\\s*Backtrace") -}; - var ProfessionalProducts = [ "Red Hat Enterprise Linux", "Red Hat Enterprise MRG" @@ -55,14 +42,18 @@ function RHOnMessageHandler(msg) { case "FixAttachmentMIMECallback": XMLRPCcallback(); break; + case "AnalyzeXorgLogBacktrace": + analyzeXorgLogBacktrace(msg.data); + break; + case "queryUpstream": + queryUpstreamCallback(msg.data); + break; default: console.error("Error: unknown RPC call " + msg.toSource()); + break; } } - - -// ==================================================================================== // RHBugzillaPage object /** @@ -71,21 +62,9 @@ function RHOnMessageHandler(msg) { * @return String what would be a default assignee if * we haven't set it up. */ -nonTestedFunction getDefaultAssignee() { - return filterByRegexp(this.constantData.defaultAssignee, - this.getComponent()).toLowerCase(); -} - - -function removeDuplicates (arr) { - for (var i = 0; i < arr.length; i++) { - for (var j = i + 1; j < arr.length; j++) { - if (arr[i] == arr[j]) { - arr.splice (j, 1); - } - } - } - return arr; +function getDefaultAssignee() { + return filterByRegexp(constantData.defaultAssignee, + getComponent()).toLowerCase(); } /** @@ -201,9 +180,9 @@ function addAttachment(data, callback, param) { /* === Bugzilla functions === */ /** - * + * */ -nonTestedFunction pasteBacktraceInComments() { +function pasteBacktraceInComments(atts) { /* Let's comment it out, and we'll see if anything breaks. TODO This paragraph looks suspicous ... what is it? @@ -216,6 +195,9 @@ nonTestedFunction pasteBacktraceInComments() { notedLabel.parentNode.removeChild(notedLabel); */ + // FIXME BROKEN and its depending functions are even more broken + return null; + var abrtQueryURL = "https://bugzilla.redhat.com/buglist.cgi?" + "cmdtype=dorem&remaction=run&namedcmd=all%20NEW%20abrt%20crashes&"+ "sharer_id=74116"; @@ -231,9 +213,9 @@ nonTestedFunction pasteBacktraceInComments() { } if (!(isTriaged() || idContainsWord("status_whiteboard", - 'btparsed') || (parsedAttachments.length > 0))) { + 'btparsed') || (atts.length > 0))) { var btAttachments = attachments - .filter(function(att, idx, arr) { + .filter(function(att) { return (/File: backtrace/.test(att[0])); }); // TODO we need to go through all backtrace attachments, but @@ -259,10 +241,10 @@ nonTestedFunction pasteBacktraceInComments() { }, this); } // Add "show BT" links - if (this.parsedAttachments.length > 0) { + if (parsedAttachments.length > 0) { this.parsedAttachments.forEach(function (att) { - that.addShowParsedBTLink(att); - }, that); + addShowParsedBTLink(att); + }); } } @@ -289,9 +271,9 @@ function addShowParsedBTLink(att) { } /** - * Unfinished ... see above + * Unfinished ... see above FIXME BROKEN AND DOESN'T WORK */ -nonTestedFunction addNewAttachmentRow(origAtt, +function addNewAttachmentRow(origAtt, newAttId, newAttSize) { var that = this; var oldAddBTLink = document.getElementById("attachBacktraceActivator"); @@ -342,11 +324,13 @@ nonTestedFunction addNewAttachmentRow(origAtt, */ function addCheckShowLink(oldAtt, snippet) { var elem = oldAtt[4].querySelector("td:last-of-type"); +/* createDeadLink("attachBacktraceActivator", "add parsed BT", elem, function(x) { // pass function and parameters as two separate parameters, the function to be called from // addAttachment addAttachment(snippet, addNewAttachmentRow, oldAtt); }, [], true); +*/ } /** @@ -355,31 +339,30 @@ function addCheckShowLink(oldAtt, snippet) { * @param atts Array of attachments subarrays * @return none */ -nonTestedFunction markBadAttachments(atts) { - var that = this; +function markBadAttachments(atts) { var badMIMEArray = [ "application/octet-stream", "text/x-log", "undefined" ]; if (!constantData.passwordState.passAvailable) { console.log("No password, no XML-RPC calls; sorry"); return null; } - var badAttachments = atts.filter(function(att, idx, arr) { + 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]; + var titleElement = document. + getElementsByClassName("bz_alias_short_desc_container")[0]; titleElement.style.backgroundColor = "olive"; - this.createDeadLink("fixAllButton", "Fix all", titleElement, function() { + createDeadLink("fixAllButton", "Fix all", titleElement, function() { Array.forEach(badAttachments, function(x) { - this.fixAttachById(x[1]); - }, that); + fixAttachById(x[1]); + }); }, [], false, null, "f"); badAttachments.forEach(function(x, i, a) { - this.addTextLink(x); - }, this); + addTextLink(x); + }); } } @@ -485,28 +468,30 @@ function setBranding() { } /** + * + */ +function queryUpstreamCallback(text) { + var searchData = filterByRegexp(constantData.queryUpstreamBug, getComponent()); + var urlBase = searchData.url; + text = searchData.searchBy+":"+searchData.fillIn+" "+text.trim(); + if (searchData.fillIn == "$$$") { + text = text.replace("$$$", getComponent()); + } + text = encodeURIComponent(text).replace("%20","+"); + postMessage(new Message("OpenURLinTab", urlBase + text)); +} + +/** * Search simple query in the upstream bugzilla appropriate for the component * * @return none */ -nonTestedFunction queryUpstream() { - var text = this.getSelectionOrClipboard(); - if (text) { - var queryUpstreamBugsURLArray = this.constantData.queryUpstreamBug; - var searchData = filterByRegexp(queryUpstreamBugsURLArray, this.getComponent()); - var urlBase = searchData.url; - text = searchData.searchBy+":"+searchData.fillIn+" "+text.trim(); - if (searchData.fillIn == "$$$") { - text = text.replace("$$$", this.getComponent()); - } - text = encodeURIComponent(text).replace("%20","+"); - tabs.open({ - url: urlBase + text, - inBackground: true, - onReady: function (tab) { - tab.activate(); - } - }); +function queryUpstream() { + var text = getSelection(); + if (!text) { + postMessage(new Message("GetClipboard", "queryUpstream")); + } else { + queryUpstreamCallback(text); } } @@ -515,24 +500,18 @@ nonTestedFunction queryUpstream() { * * @return none */ -nonTestedFunction sendBugUpstream() { - var that = this; - var urlStr = filterByRegexp(JSON.parse(self.data.load("newUpstreamBug.json")), this - .getComponent()); +function sendBugUpstream() { + var urlStr = filterByRegexp(constantData.newUpstreamBug, getComponent()); + if (!urlStr) { + return null; + } - tabs.open({ + postMessage(new Message("OpenBugUpstream", { url: urlStr, - inBackground: true, - onOpen: function (tab) { - var otherDoc = tab.contentDocument; - var otherElems = otherDoc.forms.namedItem("Create").elements; - otherElems.namedItem("short_desc").value = that.doc - .getElementById("short_desc_nonedit_display").textContent - .trim(); - otherElems.namedItem("comment").value = that.collectComments(); - tabs.activeTab = tab; - } - }); + subject: document.getElementById("short_desc_nonedit_display"). + textContent.trim(), + comment: collectComments() + })); } /** @@ -540,13 +519,13 @@ nonTestedFunction sendBugUpstream() { * * @return none */ -nonTestedFunction addCheckXorgLogLink() { - if (this.xorglogAnalysis) { - this.XorgLogAttList.forEach(function (row) { +function addCheckXorgLogLink(attList) { + if (config.xorglogAnalysis) { + attList.forEach(function (row) { var elemS = row[4].getElementsByTagName("td"); var elem = elemS[elemS.length - 1]; - that.createDeadLink("xorgLogAnalyzeLink", "check", elem, - that.analyzeXorgLog, row[1], "br"); + createDeadLink("xorgLogAnalyzeLink", "check", elem, + analyzeXorgLog, row[1], "br"); }); } } @@ -559,11 +538,11 @@ nonTestedFunction addCheckXorgLogLink() { * @param driverStr String with the driver name * @return None */ -nonTestedFunction fillInWhiteBoard(iLine, driverStr) { - var that = this; +function fillInWhiteBoard(iLine, driverStr) { + var ATIgetID = new RegExp("^.*\\(ChipID = 0x([0-9a-fA-F]+)\\).*$"); function groupIDs(manStr, cardStrID) { - var outStr = filterByRegexp(that.constantData.chipIDsGroupings, + var outStr = filterByRegexp(constantData.chipIDsGroupings, manStr + "," + cardStrID); if (outStr.length === 0) { outStr = "UNGROUPED_" + manStr + "/" + cardStrID; @@ -580,7 +559,7 @@ nonTestedFunction fillInWhiteBoard(iLine, driverStr) { */ function checkChipStringFromID(manufacturerNo, cardNo) { var soughtID = (manufacturerNo + "," + cardNo).toUpperCase(); - var outList = that.constantData.PCI_ID_Array[soughtID]; + var outList = constantData.PCI_ID_Array[soughtID]; if (outList) { return outList; } else { @@ -593,7 +572,7 @@ nonTestedFunction fillInWhiteBoard(iLine, driverStr) { var cardIDArr = []; chipSwitchboard: if (driverStr === "RADEON") { - var cardID = iLine.replace(this.RE.ATIgetID, "$1"); + var cardID = iLine.replace(ATIgetID, "$1"); cardIDArr = checkChipStringFromID("1002", cardID); if (cardIDArr.length > 0) { cardIDStr = cardIDArr[0]; @@ -609,7 +588,7 @@ nonTestedFunction fillInWhiteBoard(iLine, driverStr) { } } else { // Intel Corporation, NVIDIA - cardIDArr = this.manuChipStrs.filter(function(el, ind, arr) { + cardIDArr = this.manuChipStrs.filter(function(el) { return new RegExp(el[0], "i").test(iLine); }); if (cardIDArr && (cardIDArr.length > 0)) { @@ -628,7 +607,7 @@ nonTestedFunction fillInWhiteBoard(iLine, driverStr) { outStr = iLine; } } - this.addStuffToTextBox("status_whiteboard", ("card_" + outStr).trim()); + addStuffToTextBox("status_whiteboard", ("card_" + outStr).trim()); document.getElementById("chipMagic_btn").style.display = "none"; } @@ -638,20 +617,22 @@ nonTestedFunction fillInWhiteBoard(iLine, driverStr) { * XMLHttpRequest is done in advance. * * @return None + * FIXME CURRENTLY BROKEN AND COMMENTED OUT */ -nonTestedFunction fillInChipMagic() { - var that = this; +function fillInChipMagic(XorgLogAttList, XorgLogAttListIndex) { + var ChipsetRE = new RegExp("^\\s*\\[?[ 0-9.]*\\]?\\s*\\(--\\) "+ + "([A-Za-z]+)\\([0-9]?\\): Chipset: (.*)$"); var XorgLogURL = ""; var XorgLogAttID = ""; var XorgLogFound = false; var attURL = "", interestingLine = ""; var interestingArray = []; - if (this.XorgLogAttList.length === 0) { + if (XorgLogAttList.length === 0) { return; } - XorgLogAttID = this.XorgLogAttList[this.XorgLogAttListIndex][1]; + XorgLogAttID = XorgLogAttList[XorgLogAttListIndex][1]; attURL = "https://bugzilla.redhat.com/attachment.cgi?id="+XorgLogAttID; // parse Xorg.0.log @@ -660,17 +641,17 @@ nonTestedFunction fillInChipMagic() { onComplete: function (response) { if (response.status == 200) { var interestingLineArr = response.text.split("\n"). - filter(function (v,i,a) { - return that.RE.Chipset.test(v); + filter(function (v) { + return ChipsetRE.test(v); }); if (interestingLineArr.length >0) { // TODO we are parsing only the first found line; is it alright? - interestingArray = that.RE.Chipset.exec(interestingLineArr[0]); + interestingArray = ChipsetRE.exec(interestingLineArr[0]); interestingLine = interestingArray[2]. replace(/[\s"]+/g," ").trim(); // Persuade createNewButton to have mercy and to actually add // non-default button - that.constantData.chipMagicTrigger = true; + constantData.chipMagicTrigger = true; // FIXME packages don't exist anymore // that.packages["rh-xorg"].chipMagic.chipMagic = interestingLine+"\t"+interestingArray[1] // .toUpperCase(); @@ -682,45 +663,39 @@ nonTestedFunction fillInChipMagic() { this.XorgLogAttListIndex++; } -nonTestedFunction analyzeXorgLog(attachID) { - var infoWin = this.win.open("", "Check att. " + attachID, - "width=640,height=640,status=no,location=no"); - var doc = infoWin.document; - doc.body.innerHTML = "<pre id='textPre'></pre>"; - // TODO var oldCursor = doc.body.style.cursor; - // doc.body.style.cursor = "wait"; - var preElem = doc.getElementById("textPre"); +function analyzeXorgLog(attachID) { + postMessage(new Message("GetURL", { + url: "https://bugzilla.redhat.com/attachment.cgi?id=" + attachID, + backMessage: "AnalyzeXorgLogBacktrace" + }; +} - var attURL = "https://bugzilla.redhat.com/attachment.cgi?id=" + attachID; - var that = this; - Request({ - url: attURL, - onComplete: function(response) { - if (response.status == 200) { - var results = response.text.split("\n"). - filter(function(line) { - return (that.RE.soughtLines.test(line)); - }); - results.sort(); - results = removeDuplicates(results); - // Remove headers - if (results.length >= 1) { - results.splice(0, 1); - } - if (results.length > 0) { - results.forEach(function(l) { - preElem.innerHTML += l + "\n"; - }); - // Add a summary - preElem.innerHTML += "----------\n" + - results.length + " interesting lines found."; - } else { - preElem.innerHTML += "No matching lines found!"; - } - } - // doc.body.style.cursor = oldCursor; - } - }).get(); +function analyzeXorgLogBacktrace(reponseText) { + var soughtLines = new RegExp("^\\s*(\\[[0-9 .]*\\])?\\s*(\\((EE|WW)\\)|.*"+ + " [cC]hipsets?: )|\\s*Backtrace"); + var innerString = ""; + var results = response.text.split("\n"). + filter(function(line) { + return (soughtLines.test(line)); + }); + results.sort(); // FIXME why? + results = removeDuplicates(results); + // Remove headers + if (results.length >= 1) { + results.splice(0, 1); + } + if (results.length > 0) { + results.forEach(function(l) { + innerString += l + "\n"; + }); + // Add a summary + innerString += "----------\n" + + results.length + " interesting lines found."; + } else { + innerString += "No matching lines found!"; + } + postMessage(new Message("OpenStringInPanel", + "<pre>\n" + innerString.trim() + "\n</pre>")); } /** @@ -729,9 +704,9 @@ nonTestedFunction analyzeXorgLog(attachID) { * @param URLhostname String hostname of the external bugzilla * @return String with the string for the external_id SELECT */ -nonTestedFunction getBugzillaName(URLhostname) { +function getBugzillaName(URLhostname) { var bugzillaID = ""; - var bzLabelNames = JSON.parse(self.data.load("bugzillalabelNames.json")); + var bzLabelNames = constantData.bugzillaLabelNames; if (bzLabelNames[URLhostname]) { bugzillaID = bzLabelNames[URLhostname]; } else { @@ -758,7 +733,6 @@ function XMLRPCcallback() { } } -// FIXME this whole goes to libbzpage.js /** * The worker function -- call XMLRPC to fix MIME type of the particular * attachment @@ -830,7 +804,7 @@ function addTextLink(row) { * @param evt Event which called this handler * @return none */ -nonTestedFunction addClosingUpstream() { +function addClosingUpstream() { var refs = document.getElementById("external_bugs_table") .getElementsByTagName("tr"); @@ -844,14 +818,13 @@ nonTestedFunction addClosingUpstream() { "external_id"); if (inputBox.value.match(/^http.*/)) { - wholeURL= new url.URL(inputBox.value); - externalBugID = getBugNoFromURL(wholeURL); + externalBugID = getBugNoFromURL(inputBox.value); if (externalBugID) { inputBox.value = externalBugID; } // get bugzillaName and set the label - var bugzillaName = this.getBugzillaName(wholeURL.host); - this.selectOptionByLabel("external_id", bugzillaName); + var bugzillaName = getBugzillaName(wholeURL.host); + selectOptionByLabel("external_id", bugzillaName); } else if (!isNaN(inputBox.value)) { externalBugID = parseInt(inputBox.value, 10); var bugzillaHostname = document.getElementById("external_id").value; @@ -864,7 +837,7 @@ nonTestedFunction addClosingUpstream() { // 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 = this.commentStrings.sentUpstreamString; + var msgStr = constantData.commentStrings.sentUpstreamString; msgStr = msgStr.replace("§§§", wholeURL); centralCommandDispatch("comment",msgStr); centralCommandDispatch("status", "CLOSED"); @@ -874,30 +847,19 @@ nonTestedFunction addClosingUpstream() { } } -nonTestedFunction markBugTriaged() { - // Now we lie completely, we just set keyword Triaged, - // this is not just plain ASSIGNED, but - // modified according to +function markBugTriaged() { // https://fedoraproject.org/wiki/BugZappers/Meetings/Minutes-2009-Oct-27 - // and // http://meetbot.fedoraproject.org/fedora-meeting/2009-11-24\ // /fedora-meeting.2009-11-24-15.11.log.html - // and // http://meetbot.fedoraproject.org/fedora-meeting/2009-11-24\ // /fedora-meeting.2009-11-24-15.11.log.html - // for F13 and later, ASSIGNED is "add Triaged keyword" (as well) - // for <F13 it is "add both" (ASSIGNED status and Triaged keyword) - var ver = document.getElementById("version").value; - if ((!this.isEnterprise()) && (ver <= 12)) { - this.selectOption("bug_status", "ASSIGNED"); - } - this.addStuffToTextBox("keywords","Triaged"); + addStuffToTextBox("keywords","Triaged"); } /** * */ -nonTestedFunction parseBacktrace (ret) { +function parseBacktrace (ret) { var signalHandler = new RegExp("^\\s*#[0-9]*\\s*<signal handler called>"); var frameNo = new RegExp("^\\s*#([0-9]*)\\s"); @@ -933,89 +895,82 @@ nonTestedFunction parseBacktrace (ret) { return ""; } -nonTestedFunction RHBugzillaPage(win, config) { +function RHBZinit() { // inheritance ... call superobject's constructor - BZPage.call(this, win, config); + var AbrtRE = new RegExp("^\\s*\\[abrt\\]"); + var btSnippet = ""; - var that = this; - this.reqCounter = 0; - this.signaturesCounter = 0; - this.chipMagicInterestingLine = ""; - -/* FIXME this would require RPC call - this.maintCCAddr = null; - if (this.constantData.CCmaintainer) { - this.maintCCAddr = filterByRegexp(this.constantData.CCmaintainer, - this.getComponent()); - } -*/ + var signaturesCounter = 0; + var chipMagicInterestingLine = ""; - if (!this.constantData.ProfessionalProducts) { - this.constantData.ProfessionalProducts = - JSON.parse(self.data.load("professionalProducts.json")); + var maintCCAddr = null; + if (constantData.CCmaintainer) { + maintCCAddr = filterByRegexp(constantData.CCmaintainer, + getComponent()); } // getBadAttachments - this.XorgLogAttList = []; - this.XorgLogAttListIndex = 0; - this.attachments = this.getAttachments(); - this.markBadAttachments(this.attachments); + var XorgLogAttList = []; + var XorgLogAttListIndex = 0; + var attachments = getAttachments(); + markBadAttachments(attachments); - this.parsedAttachments = this.attachments.filter(function (att) { + parsedAttachments = attachments.filter(function (att) { return (new RegExp(titleParsedAttachment).test(att[0])); }); - if (this.constantData.defaultAssignee) { - this.setDefaultAssignee(); + if (constantData.defaultAssignee) { + setDefaultAssignee(); } // Dig out backtrace protection against double-firing? - this.btSnippet = ""; + btSnippet = ""; var parseAbrtBacktraces = config.gJSONData.configData.parseAbrtBacktraces; - if (parseAbrtBacktraces && this.RE.Abrt.test(this.title)) { - this.pasteBacktraceInComments(); + if (parseAbrtBacktraces && AbrtRE.test(getSummary())) { + pasteBacktraceInComments(parsedAttachments); } // Find out Xorg.0.log attachment URL - this.XorgLogAttList = this.attachments.filter(function (value, index, array) { + 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])); }); - this.addCheckXorgLogLink(); - - // TODO Get compiz bugs as well - if (this.constantData.PCI_ID_Array && - (this.XorgLogAttList[0]) && - (this.maintCCAddr === "xgl-maint@redhat.com")) { - // Add find chip magic button + addCheckXorgLogLink(XorgLogAttList); + + /* fillInChipMagic needs to be fixed first, but it can wait. + TODO Get compiz bugs as well + if (constantData.PCI_ID_Array && + (XorgLogAttList[0]) && + (maintCCAddr === "xgl-maint@redhat.com")) { + Add find chip magic button var whiteboard_string = document.getElementById("status_whiteboard").value; if (!/card_/.test(whiteboard_string)) { - this.fillInChipMagic(); + fillInChipMagic(); // FIXME add parameters of the call } } + */ // Take care of signature for Fedora bugzappers - if (config.gJSONData.configData.signature.length > 0) { - var signatureFedoraString = config.gJSONData.configData.signature; + if (config.signature.length > 0) { + var signatureFedoraString = config.signature; document.forms.namedItem("changeform").addEventListener("submit", function(aEvt) { - if (that.signaturesCounter < 1) { - that.addStuffToTextBox("comment", signatureFedoraString); - that.signaturesCounter += 1; + if (signaturesCounter < 1) { + addStuffToTextBox("comment", signatureFedoraString); + signaturesCounter += 1; } }, false); } - this.setBranding(); + setBranding(); // set default assignee on change of the component var compElement = document.getElementById("component"); if (compElement && (compElement.options)) { document.getElementById("component").addEventListener("change", function() { - that.changeAssignee("default"); + changeAssignee("default"); }, false); } - } diff --git a/data/util.js b/data/util.js index 7753458..5e8afcc 100644 --- a/data/util.js +++ b/data/util.js @@ -192,3 +192,20 @@ function killNodes(doc, target, remove) { } }); } + +/** + * Remove duplicate elements from array + * + * @param arr Array which needs to be cleaned up + * @return cleaned up array + */ +function removeDuplicates (arr) { + for (var i = 0; i < arr.length; i++) { + for (var j = i + 1; j < arr.length; j++) { + if (arr[i] == arr[j]) { + arr.splice (j, 1); + } + } + } + return arr; +} diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js index 337a72e..41aa27a 100644 --- a/lib/libbugzilla.js +++ b/lib/libbugzilla.js @@ -11,6 +11,7 @@ var passUtils = require("passwords"); var Request = require("request").Request; var selfMod = require("self"); var urlMod = require("url"); +var dataUtils = require("utils/data"); var xrpc = require("xmlrpc"); var panelMod = require("panel"); @@ -20,6 +21,7 @@ var BTSPrefNS = "bugzilla-triage.setting."; var BTSPassRealm = "BTSXMLRPCPass"; var passwords = {}; // hash of passwords indexed by a hostname +var config = exports.config = {}; function Message(cmd, data) { console.log("Message: cmd = " + cmd + ", data = " + data); @@ -125,7 +127,7 @@ exports.changeJSONURL = function changeJSONURL() { login: getLogin() } */ -exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, config, callback) { +exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, callback) { var installedPackages = {}; var enabledPackages = []; var location = locationLoginObj.location; @@ -177,6 +179,12 @@ exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, c } } + if ("sentUpstreamString" in config.gJSONData.commentStrings) { + config.constantData.commentStrings = {}; + config.constantData.commentStrings.sentUpstreamString = + config.gJSONData.commentStrings["sentUpstreamString"]; + } + // Investigate situation about password /* passwObj = { @@ -185,7 +193,7 @@ exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, c }; */ var locURL = new urlMod.URL(locationLoginObj.location); var passDomain = locURL.scheme + "://" + locURL.host; - passwObj = getPassword(locationLoginObj.login, passDomain); + var passwObj = getPassword(locationLoginObj.login, passDomain); // In order to avoid sending whole password to the content script, // we are sending just these two Booleans. config.constantData.passwordState = { @@ -196,31 +204,60 @@ exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, c callback(new Message("CreateButtons", { instPkgs: installedPackages, constData: config.constantData, + config: config.configData, kNodes: config.gJSONData.configData.killNodes })); }; -exports.getClipboard = function getClipboard(command, cb) { - cb(new Message("RetClipboard", { - text: clipboard.get(), - cmd: command - })); +exports.getClipboard = function getClipboard(cb) { + cb(clipboard.get()); +}; + +exports.getURL = function getURL(url, callback) { + Request({ + url: url, + onComplete: function(response) { + if (response.status == 200) { + callback(response.text); + } + } + }).get(); +}; + +exports.openStringInNewPanel = function openStringInNewPanel(inHTMLStr) { + openURLInNewPanel("data:text/html;charset=utf-8," + + dataUtils.base64Encode(inHTMLStr)); }; exports.openURLInNewPanel = function openURLInNewPanel(url) { - panelMod.Panel({ + var panel = panelMod.Panel({ contentURL: url, width: 640, - height: 640, - allow: false // TODO needs to be reviewed + height: 640 }); -} + panel.show(); +}; + +exports.openURLInNewTab = function openURLInNewTab(url) { + tabs.open({ + url: url, + inBackground: true, + onReady: function(t) { + t.activate(); + } + }); +}; -exports.openURLinNewTab = function openURLinNewTab(urlStr) { +exports.createUpstreamBug = function createUpstreamBug(urlStr, subject, comment) { tabs.open({ url: urlStr, inBackground: true, onReady: function (t) { + var otherElems = t.contentDocument.forms.namedItem("Create").elements; + // Summary + otherElems.namedItem("short_desc").value = subject; + // Comment + otherElems.namedItem("comment").value = collectComments(); t.activate(); } }); @@ -257,7 +294,6 @@ exports.makeXMLRPCCall = function makeXMLRPCCall(url, login, method, params, cal exports.initialize = function initialize(config, callback) { var prefName = BTSPrefNS+"JSONURL"; var urlStr = ""; - var passwObj = {}; if (preferences.isSet(prefName)) { urlStr = preferences.get(prefName); @@ -295,14 +331,16 @@ exports.initialize = function initialize(config, callback) { }); } - // config.logger = new logger.Logger(JSON.parse(self.data.load("bugzillalabelAbbreviations.json"))); + // config.logger = new logger.Logger(JSON.parse( + // self.data.load("bugzillalabelAbbreviations.json"))); - config.matches = config.gJSONData.configData.matches; - config.skipMatches = config.matches.map(function(x) { + config.configData = {}; + config.configData.matches = config.gJSONData.configData.matches; + config.configData.skipMatches = config.configData.matches.map(function(x) { return x.replace("show_bug.cgi.*","((process|post)_bug|attachment)\.cgi$"); }); - config.objConstructor = {}; + // config.objConstructor = {}; // var bzType = config.gJSONData.configData.objectStyle; // if (bzType === "RH") { // config.objConstructor = require("rhbzpage").RHBugzillaPage; @@ -310,8 +348,6 @@ exports.initialize = function initialize(config, callback) { // } // config.objConstructor = require("mozillabzpage").MozillaBugzilla; - // callback(config); - config.constantData = {}; // TODO this is important and missing if ("constantData" in config.gJSONData) { @@ -320,18 +356,26 @@ exports.initialize = function initialize(config, callback) { selfMod.data.load("queryUpstreamBug.json")); config.constantData.XMLRPCData = JSON.parse( selfMod.data.load("XMLRPCdata.json")); + config.constantData.bugzillaLabelNames = + JSON.parse(selfMod.data.load("bugzillalabelNames.json")); + config.constantData.newUpstreamBug = + JSON.parse(selfMod.data.load("newUpstreamBug.json")); + config.constantData.ProfessionalProducts = + JSON.parse(selfMod.data.load("professionalProducts.json")); } if ("CCmaintainer" in config.constantData) { - config.defBugzillaMaintainerArr = config.constantData.CCmaintainer; + config.configData.defBugzillaMaintainerArr = config.constantData.CCmaintainer; } if ("suspiciousComponents" in config.gJSONData.configData) { - config.suspiciousComponents = config.gJSONData.configData.suspiciousComponents; + config.configData.suspiciousComponents = + config.gJSONData.configData.suspiciousComponents; } if ("XorgLogAnalysis" in config.gJSONData.configData) { - config.xorglogAnalysis = config.gJSONData.configData.XorgLogAnalysis; + config.configData.xorglogAnalysis = + config.gJSONData.configData.XorgLogAnalysis; } if ("submitsLogging" in config.gJSONData.configData && diff --git a/lib/main.js b/lib/main.js index 5ba237d..abdc758 100644 --- a/lib/main.js +++ b/lib/main.js @@ -12,14 +12,11 @@ "use strict"; var browser = require("tab-browser"); var self = require("self"); -var Request = require("request").Request; var pageMod = require("page-mod"); var libbz = require("libbugzilla"); var tabs = require("tabs"); var logger = require("logger"); -var config = {}; - function isOurPage(window, matchingURLs) { var url = window.location.href; @@ -67,13 +64,13 @@ var messageHandler = exports.messageHandler = function messageHandler(worker, ms break; case "GetInstalledPackages": // send message with packages back - libbz.getInstalledPackages(msg.data, config, function (pkgsMsg) { + libbz.getInstalledPackages(msg.data, function (pkgsMsg) { worker.postMessage(pkgsMsg); }); break; case "GetClipboard": - libbz.getClipboard(msg.data, function (clipboard) { - worker.postMessage(clipboard); + libbz.getClipboard(function (clipboard) { + worker.postMessage(new Message(msg.data, clipboard)); }); break; case "ChangeJSONURL": @@ -82,6 +79,12 @@ var messageHandler = exports.messageHandler = function messageHandler(worker, ms case "OpenURLinPanel": libbz.openURLinPanel(msg.data); break; + case "OpenURLinTab": + libbz.openURLInNewTab(msg.data); + break; + case "OpenStringInPanel": + libbz.openStringInNewPanel(msg.data); + break; case "MakeXMLRPCall": // url, login, method, params, callback libbz.makeXMLRPCCall(msg.data.url, msg.data.login, msg.data.method, @@ -92,6 +95,14 @@ var messageHandler = exports.messageHandler = function messageHandler(worker, ms }); }); break; + case "GetURL": + libbz.getURL(msg.data.url, function(stuff) { + worker.postMessage(new Message(msg.data.backMessage, stuff)); + }); + break; + case "OpenBugUpstream": + libbz.createUpstreamBug(msg.data.url, msg.data.subject, msg.data.comment); + break; case "testReady": // we ignore it here, interesting only in unit test break; @@ -109,7 +120,7 @@ var contentScriptLibraries = { ] }; -libbz.initialize(config, function () { +libbz.initialize(libbz.config, function () { pageMod.PageMod({ include: [ "https://bugzilla.redhat.com/show_bug.cgi?id=*" @@ -124,3 +135,5 @@ libbz.initialize(config, function () { } }); }); + +tabs.open("https://bugzilla.redhat.com/show_bug.cgi?id=595017"); |