forked from octokit/octokit.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (24 loc) · 929 Bytes
/
index.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
module.exports = GitHubApi
const defaultsDeep = require('lodash/defaultsDeep')
const Hook = require('before-after-hook')
const parseClientOptions = require('./lib/parse-client-options')
const request = require('./lib/request')
const ENDPOINT_DEFAULTS = require('./lib/endpoint').DEFAULTS
const PLUGINS = [
require('./lib/plugins/authentication'),
require('./lib/plugins/endpoint-methods'),
require('./lib/plugins/pagination')
]
function GitHubApi (options) {
const defaults = defaultsDeep(parseClientOptions(options), ENDPOINT_DEFAULTS)
const hook = new Hook()
const api = {
// NOTE: github.hook, github.plugin and github.request are experimental APIs
// at this point and can change at any time
hook,
plugin: (pluginFunction) => pluginFunction(api),
request: (options) => api.hook('request', defaultsDeep(options, defaults), request)
}
PLUGINS.forEach(api.plugin)
return api
}