-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
38 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,12 @@ | ||
const endpoint = require('@octokit/endpoint') | ||
const fetch = require('node-fetch').default | ||
const getUserAgent = require('universal-user-agent') | ||
|
||
const request = require('./lib/request') | ||
const version = require('./package.json').version | ||
const userAgent = `octokit-request.js/${version} ${getUserAgent()}` | ||
|
||
function octokitRequest (endpoint, route, options) { | ||
return request(module.exports.fetch, endpoint(route, options)) | ||
} | ||
|
||
function withDefaults (oldEndpoint, newDefaults) { | ||
const endpoint = oldEndpoint.defaults(newDefaults) | ||
const request = octokitRequest.bind(null, endpoint) | ||
request.endpoint = endpoint | ||
request.defaults = withDefaults.bind(null, endpoint) | ||
return request | ||
} | ||
const withDefaults = require('./lib/with-defaults') | ||
|
||
module.exports = withDefaults(endpoint, { | ||
headers: { | ||
'user-agent': userAgent | ||
} | ||
}) | ||
|
||
// expose internally used `fetch` method for testing/mocking only | ||
module.exports.fetch = fetch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// expose internally used `fetch` method for testing/mocking only | ||
module.exports.fetch = require('node-fetch').default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = withDefaults | ||
|
||
const request = require('./request') | ||
|
||
function withDefaults (oldEndpoint, newDefaults) { | ||
const endpoint = oldEndpoint.defaults(newDefaults) | ||
const newApi = request.bind(null, endpoint) | ||
newApi.endpoint = endpoint | ||
newApi.defaults = withDefaults.bind(null, endpoint) | ||
return newApi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters