This repository was archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (51 loc) · 1.46 KB
/
index.js
File metadata and controls
55 lines (51 loc) · 1.46 KB
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
"use strict";
var GitHub = require("github")
var _ = require("lodash")
var getSettings = require("./lib/settings")
var Manager = function (opts) {
this.settings = getSettings(opts)
Object.defineProperty(this, "github", {
get: function () {
var self = this
if (!this._github) {
this._github = new GitHub({version: "3.0.0", timeout: 5000})
this._github.authenticate({type: "oauth", token: self.settings.token})
}
return this._github
},
set: function (val) {
this._github = val
}
})
}
var extensions = [
{prefix: "gitdata", module: require("./lib/gitdata")},
{prefix: "issues", module: require("./lib/issues")},
{prefix: "pullRequests", module: require("./lib/pr")},
{prefix: "repos", module: require("./lib/repos")},
{prefix: "statuses", module: require("./lib/statuses")}
]
extensions.forEach(function (data) {
var prefix = data.prefix
var module = data.module
Object.defineProperty(Manager.prototype, prefix, {
get: function () {
var self = this
var propertyName = "_" + prefix
if (!self[propertyName]) {
self[propertyName] = {}
for (var name in module) {
var func = module[name]
if (_.isFunction(func))
self[propertyName][name] = func.bind(self)
else
self[propertyName][name] = func
}
}
return self[propertyName]
},
enumerable: false,
configurable: true
})
})
module.exports = Manager