diff options
-rw-r--r-- | data/bugzillalabelNames.json | 2 | ||||
-rw-r--r-- | lib/bzpage.js | 25 | ||||
-rw-r--r-- | lib/rhbzpage.js | 31 |
3 files changed, 35 insertions, 23 deletions
diff --git a/data/bugzillalabelNames.json b/data/bugzillalabelNames.json index c079443..8512e58 100644 --- a/data/bugzillalabelNames.json +++ b/data/bugzillalabelNames.json @@ -4,4 +4,4 @@ "bugs.eclipse.org": "Eclipse Project", "bugzilla.gnome.org": "GNOME Desktop", "bugzilla.redhat.com": "Red Hat" -}
\ No newline at end of file +} diff --git a/lib/bzpage.js b/lib/bzpage.js index e315922..e8f11aa 100644 --- a/lib/bzpage.js +++ b/lib/bzpage.js @@ -9,7 +9,9 @@ var selfMod = require("self"); var fileMod = require("file"); var simpleStorage = require("simple-storage"); var preferences = require("preferences-service"); +var selection = require("selection"); var prompts = require("prompts"); +var tabs = require("tabs"); var Color = require("color").Color; var bugURL = "https://bugzilla.redhat.com/show_bug.cgi?id="; @@ -557,7 +559,7 @@ BZPage.prototype.collectComments = function collectComments () { /** - * Select option with given label on the <SELECT> element with given id. + * Select option with given value on the <SELECT> element with given id. * * Also execute change HTMLEvent, so that the form behaves accordingly. * @@ -579,6 +581,27 @@ BZPage.prototype.selectOption = function selectOption (id, label, fireEvent) { } }; +BZPage.prototype.selectOptionByLabel = function selectOptionByLabel(id, label, fireEvent) { + if (!fireEvent) { + fireEvent = true; + } + var sel = this.doc.getElementById(id); + var labelRE = new RegExp(label.trim()); + var ourOption = Array.filter(sel.options, function (op) { + return op.textContent.trim() == label; + }, this); + + if (ourOption[0]) { + sel.value = ourOption[0].value; + } + + if (fireEvent) { + var intEvent = this.doc.createEvent("HTMLEvents"); + intEvent.initEvent("change", true, true); + sel.dispatchEvent(intEvent); + } +}; + /** * Send mouse click to the specified element * diff --git a/lib/rhbzpage.js b/lib/rhbzpage.js index 92c6e28..81c63fe 100644 --- a/lib/rhbzpage.js +++ b/lib/rhbzpage.js @@ -688,7 +688,7 @@ RHBugzillaPage.prototype.analyzeXorgLog = function analyzeXorgLog(attachID) { * @param URLhostname String hostname of the external bugzilla * @return String with the string for the external_id SELECT */ -RHBugzillaPage.prototype.getBugzillaName = function(URLhostname) { +RHBugzillaPage.prototype.getBugzillaName = function getBugzillaName(URLhostname) { var bugzillaID = ""; var bzLabelNames = JSON.parse(self.data.load("bugzillalabelNames.json")); if (bzLabelNames[URLhostname]) { @@ -708,7 +708,7 @@ RHBugzillaPage.prototype.getBugzillaName = function(URLhostname) { * + responseHeaders * + responseText */ -RHBugzillaPage.prototype.fixingMIMECallBack = function() { +RHBugzillaPage.prototype.fixingMIMECallBack = function fixingMIMECallBack() { var that = this; if (--this.reqCounter <= 0) { timer.setTimeout(function () { @@ -817,33 +817,25 @@ RHBugzillaPage.prototype.addTextLink = function(row) { RHBugzillaPage.prototype.addClosingUpstream = function() { var refs = this.doc.getElementById("external_bugs_table") .getElementsByTagName("tr"); + // that's a bad id, if there is a one. :) var inputBox = this.doc.getElementById("inputbox"); var externalBugID = 0; var wholeURL = ""; - // TODO Hopefully unfinished and even less tested // Fix missing ID on the external_id SELECT - this.doc.getElementsByName("external_id")[0].setAttribute("id", + this.doc.getElementsByName("external_id")[0].setAttribute("id", "external_id"); if (inputBox.value.match(/^http.*/)) { - wholeURL = inputBox.value; - var helpURL = new url.URL(wholeURL); - var paramsArr = helpURL.path.replace(/^\?/, '').split('&'); - // get convert URL parameters to an Object - var params = {}, s = []; - paramsArr.forEach(function(par, idx, arr) { - s = par.split('='); - params[s[0]] = s[1]; - }); - if (params.id) { - externalBugID = parseInt(params.id, 10); + var wholeURL= new url.URL(inputBox.value); + var externalBugID = util.getBugNo(wholeURL); + if (externalBugID) { inputBox.value = externalBugID; } - // get host and bugzillaName - var bugzillaName = this.getBugzillaName(helpURL.hostname); - this.selectOption("external_id", bugzillaName); + // get bugzillaName and set the label + var bugzillaName = this.getBugzillaName(wholeURL.host); + this.selectOptionByLabel("external_id", bugzillaName); } else if (!isNaN(inputBox.value)) { externalBugID = parseInt(inputBox.value, 10); var bugzillaHostname = this.doc.getElementById("external_id").value; @@ -853,9 +845,6 @@ RHBugzillaPage.prototype.addClosingUpstream = function() { // the previous commit? } - // TODO THis is not good, we don't have a feedback for other commands, - // not to be run, if this fails. - // It is not good to close bug as UPSTREAM, if there is no reference // to the upstream bug. if ((externalBugID > 0) || (refs.length > 2)) { |