-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathgitlab.js
71 lines (59 loc) · 1.75 KB
/
gitlab.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
/**!
* gitlab - lib/gitlab.js
*
* Copyright(c) fengmk2 and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
*/
'use strict';
/**
* Module dependencies.
*/
var debug = require('debug')('gitlab');
var RESTFulClient = require('restful-client').RESTFulClient;
var util = require('util');
var resources = require('./resources');
module.exports = Gitlab;
/**
* Create a gitlab API client.
*
* @param {Object} options
* - {String} api, api root url, e.g.: 'http://gitlab.com/api/v3'
* - {String} privateToken, You can find or reset your private token in your profile.
* - {String} accessToken, Obtained via OAuth
*/
function Gitlab(options) {
options = options || {};
options.api = options.api || 'https://gitlab.com/api/v3';
RESTFulClient.call(this, options);
this.privateToken = options.privateToken;
this.accessToken = options.accessToken;
this.addResources(resources);
// mergeRequests => merge_requests
this.merge_requests = this.mergeRequests;
// members => projectMembers
this.members = this.projectMembers;
}
util.inherits(Gitlab, RESTFulClient);
Gitlab.prototype.setAuthentication = function (req) {
var accessToken = req.params.data.access_token || this.accessToken;
if (accessToken) {
req.params.data.access_token = accessToken;
} else {
req.params.data.private_token = req.params.data.private_token || this.privateToken;
}
return req;
};
Gitlab.create = function (options) {
return new Gitlab(options);
};
Gitlab.createPromise = function (options) {
var client = Gitlab.create(options);
return require('./promisify')(client);
};
Gitlab.createThunk = function (options) {
var client = Gitlab.create(options);
return require('./thunkify')(client);
};