aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-07-25 22:29:24 +0200
committerMatěj Cepl <mcepl@redhat.com>2010-07-25 22:32:04 +0200
commit9ab5c9dbd495d3bd0b9bec88f8a5db7213fc30c7 (patch)
tree0caaf8f57271d829e89d4db5cf03c51043bbe686 /lib
parent9f1bc2cfff3bfd7050c7dfd1c02954347923f643 (diff)
downloadbugzilla-triage-9ab5c9dbd495d3bd0b9bec88f8a5db7213fc30c7.tar.gz
Fix RHBugzillaPage.addClosingUpstream and BZPage.selectOptionByLabel method
Fixes #32
Diffstat (limited to 'lib')
-rw-r--r--lib/bzpage.js25
-rw-r--r--lib/rhbzpage.js31
2 files changed, 34 insertions, 22 deletions
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)) {