From 80bc5b6aa6e6a093cd2c2a70a7cf0829afa13b27 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Mon, 26 Apr 2010 12:18:08 +0200 Subject: fix issue 30 ... new format of Xorg.0.log --- bugzillaBugTriage.js | 108 ++++++++-------- bugzillaComments.js | 344 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 397 insertions(+), 55 deletions(-) create mode 100644 bugzillaComments.js diff --git a/bugzillaBugTriage.js b/bugzillaBugTriage.js index cfc3025..8c39590 100644 --- a/bugzillaBugTriage.js +++ b/bugzillaBugTriage.js @@ -63,9 +63,8 @@ var msgStrs = {}; var CommentRe = new RegExp("^\\s*#"); var BlankLineRe = new RegExp("^\\s*$"); // nová řádka -// [ 65.631] (--) intel(0): Chipset: "845G" -var ChipsetRE = new RegExp( - "^\\s*\\[?[ 0-9.]*\\]?\\s*\\(--\\) ([A-Za-z]+)\\([0-9]?\\): Chipset: (.*)$"); +// [ 65.631] (--) intel(0): Chipset: "845G" +var ChipsetRE = new RegExp("^\\s*\\[?[ 0-9.]*\\]?\\s*\\(--\\) ([A-Za-z]+)\\([0-9]?\\): Chipset: (.*)$"); var ATIgetIDRE = new RegExp("^.*\\(ChipID = 0x([0-9a-fA-F]+)\\).*$"); var AbrtRE = new RegExp("^\\s*\\[abrt\\]"); var signalHandlerRE = new RegExp("^\\s*#[0-9]*\\s*"); @@ -1265,58 +1264,57 @@ BzPage.prototype.addNewButton = function(originalLocation, newId, newLabel, * * @return None */ -BzPage.prototype.fillInChipMagic = function() { - var XorgLogURL = ""; - var XorgLogAttID = ""; - var XorgLogFound = false; - var attURL = "", interestingLine = ""; - var interestingArray = []; - - // Find out Xorg.0.log attachment URL - this.XorgLogAttList = this.attachments - .filter(function(value, index, array) { - // Xorg.0.log must be text, otherwise we cannot parse it - return (/[xX].*log/.test(value[0]) && /text/.test(value[2])); - }); - if (this.XorgLogAttList.length === 0) { - return; - } - - XorgLogAttID = this.XorgLogAttList[this.XorgLogAttListIndex][1]; - attURL = "https://bugzilla.redhat.com/attachment.cgi?id=" + XorgLogAttID; - that = this; - - var req = new XMLHttpRequest(); - req.open("GET", attURL, true); - req.onreadystatechange = function(aEvt) { - if (req.readyState == 4) { - if (req.status == 200) { - var ret = req.responseText; - var interestingLineArr = ret.split("\n").filter( - function(v, i, a) { - return ChipsetRE.test(v); - }); - console.log("interestingLineArr = " - + interestingLineArr.toSource()); - if (interestingLineArr.length > 0) { - interestingArray = ChipsetRE.exec(interestingLineArr[0]); - interestingLine = interestingArray[2].replace(/[\s"]+/g, - " ").trim(); - var whiteboardInput = that.dok - .getElementById("status_whiteboard"); - that.addNewButton(whiteboardInput, "chipmagic", "Fill In", - "", "CHIPMAGIC", interestingLine + "\t" - + interestingArray[1].toUpperCase(), false, - true); - } - } else { - throw "Getting attachment " + attURL + "failed!"; - } - } - }; - req.send(""); - - this.XorgLogAttListIndex++; +BzPage.prototype.fillInChipMagic = function () { + var XorgLogURL = ""; + var XorgLogAttID = ""; + var XorgLogFound = false; + var attURL = "", interestingLine = ""; + var interestingArray = []; + + + // Find out Xorg.0.log attachment URL + this.XorgLogAttList = this.attachments.filter(function (value, index, array) { + // Xorg.0.log must be text, otherwise we cannot parse it + return (/[xX].*log/.test(value[0]) && /text/.test(value[2])); + }); + if (this.XorgLogAttList.length === 0) { + return; + } + + XorgLogAttID = this.XorgLogAttList[this.XorgLogAttListIndex][1]; + attURL = "https://bugzilla.redhat.com/attachment.cgi?id="+XorgLogAttID; + that = this; + + var req = new XMLHttpRequest(); + req.open("GET",attURL,true); + req.onreadystatechange = function (aEvt) { + if (req.readyState == 4) { + if (req.status == 200) { + var ret = req.responseText; + var interestingLineArr = ret.split("\n"). + filter(function (v,i,a) { + return ChipsetRE.test(v); + }); + console.log("interestingLineArr = " + interestingLineArr.toSource()); + if (interestingLineArr.length >0) { + interestingArray = ChipsetRE.exec(interestingLineArr[0]); + interestingLine = interestingArray[2]. + replace(/[\s"]+/g," ").trim(); + var whiteboardInput = that.dok. + getElementById("status_whiteboard"); + that.addNewButton(whiteboardInput,"chipmagic","Fill In", + "","CHIPMAGIC", + interestingLine+"\t"+interestingArray[1].toUpperCase(), + false,true); + } + } else { + throw "Getting attachment " + attURL + "failed!"; + } + } + }; + req.send(""); + + this.XorgLogAttListIndex++; }; /** diff --git a/bugzillaComments.js b/bugzillaComments.js new file mode 100644 index 0000000..83b382d --- /dev/null +++ b/bugzillaComments.js @@ -0,0 +1,344 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Bugzilla Comments Jetpack code. + * + * The Initial Developer of the Original Code is + * Philipp Kewisch + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Matěj Cepl + * Mark Banner + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +var manifest = { + settings: [ + { + name: "jsonURL", + type: "text", + label: "URL for Comments Pack" + }, + { + name: "enabledPacks", + type: "text", + label: "Enabled Comment Packages" + } + ] +}; +jetpack.future.import("jetpack.storage.settings"); +jetpack.future.import("jetpack.pageMods"); + +// Container for loaded package json data. +var gJSONData = null; + +//////////////////////////////////////////////////////////////// +// Helper functions +//////////////////////////////////////////////////////////////// +var hlpr = { + valToArray: function valToArray(val) { + let arr = []; + if (typeof val == "string") { + arr = [val]; + } else if ($.isArray(val)) { + arr = val; + } + return arr; + }, + + addCSVValue: function addCSVValue(str, value) { + let parts = (str.trim().length > 0 ? str.split(",") : []); + if (parts.indexOf(value) < 0) { + parts.concat(hlpr.valToArray(value)); + } + return parts.join(","); + }, + + removeCSVValue: function removeCSVValue(str, value) { + let parts = (str.trim().length > 0 ? str.split(",") : []); + for each (let val in hlpr.valToArray(value)) { + let pos = parts.indexOf(val); + if (pos > -1) { + parts.splice(pos, 1); + } + } + return parts.join(","); + }, + + selectOption: function selectOption(select, value) { + let doc = select[0].ownerDocument; + select.val(value); + + let e = doc.createEvent("HTMLEvents"); + e.initEvent("change", true, true); + select[0].dispatchEvent(e); + }, + + clickElement: function clickElement(element) { + let doc = element[0].ownerDocument; + let e = doc.createEvent("MouseEvents"); + e.initMouseEvent("click", true, true, doc.defaultView, + 0, 0, 0, 0, 0, false, false, false, false, 0, null); + element[0].dispatchEvent(e); + } +}; + +//////////////////////////////////////////////////////////////// +// Basic Bugzilla modifications +//////////////////////////////////////////////////////////////// + +function BaseBugzilla(doc) { + this.doc = doc; + this.init(); +} + +BaseBugzilla.prototype = { + doc: null, + + get installedPackages() { + // TODO does this really need to by dynamic? + let installedPackages = {}; + if (gJSONData && ("commentPackages" in gJSONData)) { + let enabledPackages = jetpack.storage.settings.enabledPacks.split(/[, ]/); + for each (let pkg in enabledPackages) { + if (pkg in gJSONData.commentPackages) { + installedPackages[pkg] = gJSONData.commentPackages[pkg]; + } + } + } + return installedPackages; + }, + + init: function base_init() { + this.initCommentsDropdown(); + }, + + initCommentsDropdown: function base_initCommentsDropdown() { + let ca = $("
" + + " " + + "