forked from mozilla-bteam/bz.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bz-0.4.3.js
442 lines (377 loc) · 42.5 KB
/
bz-0.4.3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// this file is the entrypoint for building a browser file with browserify
"use strict";
var bz = window.bz = require("./index");
},{"./index":2}],2:[function(require,module,exports){
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
exports.createClient = createClient;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var XMLHttpRequest = require('./xhr').XMLHttpRequest;
/**
Constant for the login entrypoint.
*/
var LOGIN = '/login';
/**
Errors related to the socket timeout.
*/
var TIMEOUT_ERRORS = ['ETIMEDOUT', 'ESOCKETTIMEDOUT'];
function extractField(id, callback) {
if (typeof id === 'function') {
callback = id;
id = undefined;
}
return function (err, response) {
if (err) return callback(err);
if (response) {
// default behavior is to use the first id when the caller does not provide one.
if (id === undefined) {
id = Object.keys(response)[0];
}
callback(null, response[id]);
} else {
throw "Error:, no response in extractField";
}
};
}
/**
Function decorator which will attempt to login to bugzilla
with the current credentials prior to making the actual api call.
Bugzilla.prototype.method = login(function(param, param) {
});
@param {Function} method to decorate.
@return {Function} decorated method.
*/
function loginRequired(method) {
return function () {
// we assume this is a valid bugilla instance.
// remember |this| is a bugzilla instance
// args for the decorated method
var args = Array.prototype.slice.call(arguments),
// we need the callback so we can pass login related errors.
callback = args[args.length - 1];
this.login((function (err) {
if (err) return callback(err);
// we are now logged in so the method can run!
method.apply(this, args);
}).bind(this));
};
}
var BugzillaClient = (function () {
function BugzillaClient(options) {
_classCallCheck(this, BugzillaClient);
options = options || {};
this.username = options.username;
this.password = options.password;
this.timeout = options.timeout || 0;
this.api_key = options.api_key || null;
if (options.test) {
throw new Error('options.test is deprecated please specify the url directly');
}
this.apiUrl = options.url || 'https://bugzilla.mozilla.org/rest/';
this.apiUrl = this.apiUrl.replace(/\/$/, "");
this._auth = null;
}
/**
Authentication details for given user.
Example:
{ id: 1222, token: 'xxxx' }
@type {Object}
*/
/**
In the REST API we first login to acquire a token which is then used to make
requests. See: http://bzr.mozilla.org/bmo/4.2/view/head:/Bugzilla/WebService/Server/REST.pm#L556
This method can be used publicly but is designed for internal consumption for
ease of use.
@param {Function} callback [Error err, String token].
*/
_createClass(BugzillaClient, [{
key: 'login',
value: function login(callback) {
if (this._auth) {
callback(null, this._auth);
}
if (!this.username || !this.password) {
throw new Error('missing or invalid .username or .password');
}
var params = {
login: this.username,
password: this.password
};
var handleLogin = (function handleLogin(err, response) {
if (err) return callback(err);
if (response.result) {
this._auth = response.result;
} else {
this._auth = response;
}
callback(null, response);
}).bind(this);
this.APIRequest('/login', 'GET', handleLogin, null, null, params);
}
}, {
key: 'getBug',
value: function getBug(id, params, callback) {
if (!callback) {
callback = params;
params = {};
}
this.APIRequest('/bug/' + id, 'GET', extractField(callback), 'bugs', null, params);
}
}, {
key: 'searchBugs',
value: function searchBugs(params, callback) {
this.APIRequest('/bug', 'GET', callback, 'bugs', null, params);
}
}, {
key: 'updateBug',
value: function updateBug(id, bug, callback) {
this.APIRequest('/bug/' + id, 'PUT', callback, 'bugs', bug);
}
}, {
key: 'createBug',
value: function createBug(bug, callback) {
this.APIRequest('/bug', 'POST', callback, 'id', bug);
}
}, {
key: 'bugComments',
value: function bugComments(id, callback) {
var _callback = function _callback(e, r) {
if (e) throw e;
var _bug_comments = r[id];
if (typeof _bug_comments['comments'] !== 'undefined') {
// bugzilla 5 :(
_bug_comments = _bug_comments.comments;
}
callback(null, _bug_comments);
};
this.APIRequest('/bug/' + id + '/comment', 'GET', _callback, 'bugs');
}
}, {
key: 'addComment',
value: function addComment(id, comment, callback) {
this.APIRequest('/bug/' + id + '/comment', 'POST', callback, null, comment);
}
}, {
key: 'bugHistory',
value: function bugHistory(id, callback) {
this.APIRequest('/bug/' + id + '/history', 'GET', callback, 'bugs');
}
/**
* Finds all attachments for a given bug #
* http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html#attachments
*
* @param {Number} id of bug.
* @param {Function} [Error, Array<Attachment>].
*/
}, {
key: 'bugAttachments',
value: function bugAttachments(id, callback) {
this.APIRequest('/bug/' + id + '/attachment', 'GET', extractField(id, callback), 'bugs');
}
}, {
key: 'createAttachment',
value: function createAttachment(id, attachment, callback) {
this.APIRequest('/bug/' + id + '/attachment', 'POST', extractField(callback), 'ids', attachment);
}
}, {
key: 'getAttachment',
value: function getAttachment(id, callback) {
this.APIRequest('/bug/attachment/' + id, 'GET', extractField(callback), 'attachments');
}
}, {
key: 'updateAttachment',
value: function updateAttachment(id, attachment, callback) {
this.APIRequest('/bug/attachment/' + id, 'PUT', callback, 'ok', attachment);
}
}, {
key: 'searchUsers',
value: function searchUsers(match, callback) {
this.APIRequest('/user', 'GET', callback, 'users', null, { match: match });
}
}, {
key: 'getUser',
value: function getUser(id, callback) {
this.APIRequest('/user/' + id, 'GET', extractField(callback), 'users');
}
}, {
key: 'getSuggestedReviewers',
value: function getSuggestedReviewers(id, callback) {
// BMO- specific extension to get suggested reviewers for a given bug
// http://bzr.mozilla.org/bmo/4.2/view/head:/extensions/Review/lib/WebService.pm#L102
this.APIRequest('/review/suggestions/' + id, 'GET', callback);
}
/*
XXX this call is provided for convenience to people scripting against prod bugzillq
THERE IS NO EQUIVALENT REST CALL IN TIP, so this should not be tested against tip, hence
the hard-coded url.
*/
}, {
key: 'getConfiguration',
value: function getConfiguration(params, callback) {
if (!callback) {
callback = params;
params = {};
}
// this.APIRequest('/configuration', 'GET', callback, null, null, params);
// UGLAY temp fix until /configuration is implemented,
// see https://bugzilla.mozilla.org/show_bug.cgi?id=924405#c11:
var that = this;
var req = new XMLHttpRequest();
req.open('GET', 'https://api-dev.bugzilla.mozilla.org/latest/configuration', true);
req.setRequestHeader("Accept", "application/json");
req.onreadystatechange = function (event) {
if (req.readyState == 4 && req.status != 0) {
that.handleResponse(null, req, callback);
}
};
req.timeout = this.timeout;
req.ontimeout = function (event) {
that.handleResponse('timeout', req, callback);
};
req.onerror = function (event) {
that.handleResponse('error', req, callback);
};
req.send();
}
}, {
key: 'APIRequest',
value: function APIRequest(path, method, callback, field, body, params) {
if (
// if we are doing the login
path === LOGIN ||
// if we are already authed
this._auth ||
// or we are missing auth data
!this.password || !this.username) {
// skip automatic authentication
return this._APIRequest.apply(this, arguments);
}
var args = [].slice.call(arguments);
this.login((function (err) {
if (err) return callback(err);
this._APIRequest.apply(this, args);
}).bind(this));
}
}, {
key: '_APIRequest',
value: function _APIRequest(path, method, callback, field, body, params) {
var url = this.apiUrl + path;
params = params || {};
if (this.api_key) {
params.api_key = this.api_key;
}
if (this._auth) {
params.token = this._auth.token;
} else if (this.username && this.password) {
params.username = this.username;
params.password = this.password;
}
if (params && Object.keys(params).length > 0) {
url += "?" + this.urlEncode(params);
}
body = JSON.stringify(body);
var that = this;
var req = new XMLHttpRequest();
req.open(method, url, true);
req.setRequestHeader("Accept", "application/json");
if (method.toUpperCase() !== "GET") {
req.setRequestHeader("Content-Type", "application/json");
}
req.onreadystatechange = function (event) {
if (req.readyState == 4 && req.status != 0) {
that.handleResponse(null, req, callback, field);
}
};
req.timeout = this.timeout;
req.ontimeout = function (event) {
that.handleResponse('timeout', req, callback);
};
req.onerror = function (event) {
that.handleResponse(event, req, callback);
};
req.send(body);
}
}, {
key: 'handleResponse',
value: function handleResponse(err, response, callback, field) {
// detect timeout errors
if (err && err.code && TIMEOUT_ERRORS.indexOf(err.code) !== -1) {
return callback(new Error('timeout'));
}
// handle generic errors
if (err) return callback(err);
// anything in 200 status range is a success
var requestSuccessful = response.status > 199 && response.status < 300;
// even in the case of an unsuccessful request we may have json data.
var parsedBody;
try {
parsedBody = JSON.parse(response.responseText);
} catch (e) {
// XXX: might want to handle this better in the request success case?
if (requestSuccessful) {
return callback(new Error('response was not valid json: ' + response.responseText));
}
}
// detect if we're running Bugzilla 5.0
if (typeof parsedBody['result'] !== 'undefined') {
parsedBody = parsedBody['result'];
}
// successful http respnse but an error
// XXX: this seems like a bug in the api.
if (parsedBody && parsedBody.error) {
requestSuccessful = false;
}
if (!requestSuccessful) {
return callback(new Error('HTTP status ' + response.status + '\n' + (
// note intentional use of != instead of !==
parsedBody && parsedBody.message) ? parsedBody.message : ''));
}
callback(null, field ? parsedBody[field] : parsedBody);
}
}, {
key: 'urlEncode',
value: function urlEncode(params) {
var url = [];
for (var param in params) {
var values = params[param];
if (!values.forEach) values = [values];
// expand any arrays
values.forEach(function (value) {
url.push(encodeURIComponent(param) + "=" + encodeURIComponent(value));
});
}
return url.join("&");
}
}]);
return BugzillaClient;
})();
exports.BugzillaClient = BugzillaClient;
function createClient(options) {
return new BugzillaClient(options);
}
},{"./xhr":3}],3:[function(require,module,exports){
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var XMLHttpRequest = null;
exports.XMLHttpRequest = XMLHttpRequest;
if (typeof window === 'undefined') {
// we're not in a browser?
var _loader = require;
try {
exports.XMLHttpRequest = XMLHttpRequest = _loader('sdk/net/xhr').XMLHttpRequest;
} catch (e) {
exports.XMLHttpRequest = XMLHttpRequest = _loader("xmlhttprequest").XMLHttpRequest;
}
} else if (typeof window !== 'undefined' && typeof window.XMLHttpRequest !== 'undefined') {
exports.XMLHttpRequest = XMLHttpRequest = window.XMLHttpRequest;
} else {
throw "No window, WAT.";
}
},{}]},{},[1])
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozL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