aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bzpage.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-09-10 20:50:05 +0200
committerMatěj Cepl <mcepl@redhat.com>2010-09-10 20:50:05 +0200
commit07a9f4248c978771e55dc9054238ff03a4d6865c (patch)
treef98f4a1e98d06bd1d59c188a9f31032a1bd74907 /lib/bzpage.js
parent2a7171fb5cd16ae361916dd0dd97d566f970a6df (diff)
downloadbugzilla-triage-07a9f4248c978771e55dc9054238ff03a4d6865c.tar.gz
Getting Bug.get via XML-RPC
Diffstat (limited to 'lib/bzpage.js')
-rw-r--r--lib/bzpage.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js
index 2f4436f..998e64d 100644
--- a/lib/bzpage.js
+++ b/lib/bzpage.js
@@ -12,6 +12,8 @@ var simpleStorage = require("simple-storage");
var preferences = require("preferences-service");
var selection = require("selection");
var prompts = require("prompts");
+var xrpc = require("xmlrpc");
+var Request = require("request").Request;
var tabs = require("tabs");
var Color = require("color").Color;
@@ -44,6 +46,7 @@ var BZPage = function BZPage(win, config) {
// 85
this.ReporterColor = new Color(255, 255, 166); // RGB 255, 255, 166; HSL 60, 2,
// 83
+
// initialize dynamic properties
var that = this;
this.win = win;
@@ -72,6 +75,8 @@ var BZPage = function BZPage(win, config) {
this.constantData = config.gJSONData.constantData;
this.constantData.queryUpstreamBug = JSON.parse(
selfMod.data.load("queryUpstreamBug.json"));
+ this.constantData.XMLRPCData = JSON.parse(
+ selfMod.data.load("XMLRPCdata.json"));
}
if ("CCmaintainer" in this.constantData) {
@@ -100,7 +105,19 @@ var BZPage = function BZPage(win, config) {
this.setConfigurationButton();
this.submitHandlerInstalled = false;
+
+ this.login = this.getLogin();
+ // XML-RPC password
+ if (this.hostname in this.constantData.XMLRPCData) {
+ this.password = this.getPassword(this.login);
+ }
+
this.bugNo = util.getBugNo(this.doc.location.toString());
+
+ // deal with aliases
+ if (isNaN(parseInt(this.bugNo, 10)) && this.password) {
+ this.bugNo = this.getRealBugNo();
+ }
this.title = this.doc.getElementById("short_desc_nonedit_display").textContent;
this.CCList = this.getCCList();
@@ -134,6 +151,45 @@ BZPage.prototype.getBugId = function getBugId () {
return util.getBugNo(this.doc.location.href);
};
+BZPage.prototype.getRealBugNo = function () {
+ console.log("we have to deal with bug aliased as " + this.bugNo);
+ var that = this;
+
+ // https://bugzilla.redhat.com/show_bug.cgi?ctype=xml&id=serialWacom
+
+ var xmlrpcMsg = new xrpc.XMLRPCMessage("User.login");
+ xmlrpcMsg.addParameter({
+ login: this.login,
+ password: this.password,
+ remember: 1
+ });
+ Request({
+ url: this.constantData.XMLRPCData[this.hostname].url,
+ onComplete: function() {
+ if (this.response.status == 200) {
+ xmlrpcMsg = new xrpc.XMLRPCMessage("Bug.get");
+ xmlrpcMsg.addParameter({
+ ids: util.getParamsFromURL(that.win.location.href)['id']
+ });
+ console.log("XML-RPC message:\n" + xmlrpcMsg.xml());
+ Request({
+ url: that.constantData.XMLRPCData[that.hostname].url,
+ onComplete: function() {
+ if (this.response.status === 200) {
+ console.log("response = " + this.response.text);
+ //if
+ }
+ },
+ content: xmlrpcMsg.xml(),
+ contentType: "text/xml"
+ }).post();
+ }
+ },
+ content: xmlrpcMsg.xml(),
+ contentType: "text/xml"
+ }).post();
+};
+
/**
*
*/
@@ -761,6 +817,18 @@ BZPage.prototype.getAttachments = function getAttachments () {
};
/**
+ * Get login of the currently logged-in user.
+ *
+ * @return String with the login name of the currently logged-in user
+ */
+BZPage.prototype.getLogin = function getLogin () {
+ var lastLIElement = this.doc.querySelector("#header ul.links li:last-of-type");
+ var loginArr = lastLIElement.textContent.split("\n");
+ var loginStr = loginArr[loginArr.length - 1].trim();
+ return loginStr;
+};
+
+/**
* returns password from the current storage, or if there isn't
* one, then it will ask user for it.
*