UNPKG

598 BJavaScriptView Raw
1module.exports = withDefaults
2
3const request = require('@octokit/request/lib/request')
4
5function withDefaults (hook, oldEndpoint, newDefaults) {
6 const endpoint = oldEndpoint.defaults(newDefaults)
7
8 const newApi = requestWithHook.bind(null, hook, endpoint)
9 newApi.endpoint = endpoint
10 newApi.defaults = withDefaults.bind(null, hook, endpoint)
11 return newApi
12}
13
14function requestWithHook (hook, endpoint, route, options) {
15 const endpointOptions = endpoint.merge(route, options)
16 return hook('request', endpointOptions, function (options) {
17 return request(endpoint.parse(options))
18 })
19}