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
81 changed files
with
3,922 additions
and
3,947 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
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,16 +1,16 @@ | ||
const Octokit = require('./lib/core') | ||
const Octokit = require("./lib/core"); | ||
|
||
const CORE_PLUGINS = [ | ||
require('./plugins/log'), | ||
require('./plugins/authentication-deprecated'), // deprecated: remove in v17 | ||
require('./plugins/authentication'), | ||
require('./plugins/pagination'), | ||
require('./plugins/normalize-git-reference-responses'), | ||
require('./plugins/register-endpoints'), | ||
require('./plugins/rest-api-endpoints'), | ||
require('./plugins/validate'), | ||
require("./plugins/log"), | ||
require("./plugins/authentication-deprecated"), // deprecated: remove in v17 | ||
require("./plugins/authentication"), | ||
require("./plugins/pagination"), | ||
require("./plugins/normalize-git-reference-responses"), | ||
require("./plugins/register-endpoints"), | ||
require("./plugins/rest-api-endpoints"), | ||
require("./plugins/validate"), | ||
|
||
require('octokit-pagination-methods') // deprecated: remove in v17 | ||
] | ||
require("octokit-pagination-methods") // deprecated: remove in v17 | ||
]; | ||
|
||
module.exports = Octokit.plugin(CORE_PLUGINS) | ||
module.exports = Octokit.plugin(CORE_PLUGINS); |
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,26 +1,29 @@ | ||
module.exports = Octokit | ||
module.exports = Octokit; | ||
|
||
const { request } = require('@octokit/request') | ||
const Hook = require('before-after-hook') | ||
const { request } = require("@octokit/request"); | ||
const Hook = require("before-after-hook"); | ||
|
||
const parseClientOptions = require('./parse-client-options') | ||
const parseClientOptions = require("./parse-client-options"); | ||
|
||
function Octokit (plugins, options) { | ||
options = options || {} | ||
const hook = new Hook.Collection() | ||
const log = Object.assign({ | ||
debug: () => {}, | ||
info: () => {}, | ||
warn: console.warn, | ||
error: console.error | ||
}, options && options.log) | ||
function Octokit(plugins, options) { | ||
options = options || {}; | ||
const hook = new Hook.Collection(); | ||
const log = Object.assign( | ||
{ | ||
debug: () => {}, | ||
info: () => {}, | ||
warn: console.warn, | ||
error: console.error | ||
}, | ||
options && options.log | ||
); | ||
const api = { | ||
hook, | ||
log, | ||
request: request.defaults(parseClientOptions(options, log, hook)) | ||
} | ||
}; | ||
|
||
plugins.forEach(pluginFunction => pluginFunction(api, options)) | ||
plugins.forEach(pluginFunction => pluginFunction(api, options)); | ||
|
||
return api | ||
return api; | ||
} |
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,3 +1,3 @@ | ||
const factory = require('./factory') | ||
const factory = require("./factory"); | ||
|
||
module.exports = factory() | ||
module.exports = factory(); |
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,10 +1,10 @@ | ||
module.exports = factory | ||
module.exports = factory; | ||
|
||
const Octokit = require('./constructor') | ||
const registerPlugin = require('./register-plugin') | ||
const Octokit = require("./constructor"); | ||
const registerPlugin = require("./register-plugin"); | ||
|
||
function factory (plugins) { | ||
const Api = Octokit.bind(null, plugins || []) | ||
Api.plugin = registerPlugin.bind(null, plugins || []) | ||
return Api | ||
function factory(plugins) { | ||
const Api = Octokit.bind(null, plugins || []); | ||
Api.plugin = registerPlugin.bind(null, plugins || []); | ||
return Api; | ||
} |
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,64 +1,85 @@ | ||
module.exports = parseOptions | ||
module.exports = parseOptions; | ||
|
||
const { Deprecation } = require('deprecation') | ||
const { getUserAgent } = require('universal-user-agent') | ||
const once = require('once') | ||
const { Deprecation } = require("deprecation"); | ||
const { getUserAgent } = require("universal-user-agent"); | ||
const once = require("once"); | ||
|
||
const pkg = require('../package.json') | ||
const pkg = require("../package.json"); | ||
|
||
const deprecateOptionsTimeout = once((log, deprecation) => log.warn(deprecation)) | ||
const deprecateOptionsAgent = once((log, deprecation) => log.warn(deprecation)) | ||
const deprecateOptionsHeaders = once((log, deprecation) => log.warn(deprecation)) | ||
const deprecateOptionsTimeout = once((log, deprecation) => | ||
log.warn(deprecation) | ||
); | ||
const deprecateOptionsAgent = once((log, deprecation) => log.warn(deprecation)); | ||
const deprecateOptionsHeaders = once((log, deprecation) => | ||
log.warn(deprecation) | ||
); | ||
|
||
function parseOptions (options, log, hook) { | ||
function parseOptions(options, log, hook) { | ||
if (options.headers) { | ||
options.headers = Object.keys(options.headers).reduce((newObj, key) => { | ||
newObj[key.toLowerCase()] = options.headers[key] | ||
return newObj | ||
}, {}) | ||
newObj[key.toLowerCase()] = options.headers[key]; | ||
return newObj; | ||
}, {}); | ||
} | ||
|
||
const clientDefaults = { | ||
headers: options.headers || {}, | ||
request: options.request || {}, | ||
mediaType: { | ||
previews: [], | ||
format: '' | ||
format: "" | ||
} | ||
} | ||
}; | ||
|
||
if (options.baseUrl) { | ||
clientDefaults.baseUrl = options.baseUrl | ||
clientDefaults.baseUrl = options.baseUrl; | ||
} | ||
|
||
if (options.userAgent) { | ||
clientDefaults.headers['user-agent'] = options.userAgent | ||
clientDefaults.headers["user-agent"] = options.userAgent; | ||
} | ||
|
||
if (options.previews) { | ||
clientDefaults.mediaType.previews = options.previews | ||
clientDefaults.mediaType.previews = options.previews; | ||
} | ||
|
||
if (options.timeout) { | ||
deprecateOptionsTimeout(log, new Deprecation('[@octokit/rest] new Octokit({timeout}) is deprecated. Use {request: {timeout}} instead. See https://github.com/octokit/request.js#request')) | ||
clientDefaults.request.timeout = options.timeout | ||
deprecateOptionsTimeout( | ||
log, | ||
new Deprecation( | ||
"[@octokit/rest] new Octokit({timeout}) is deprecated. Use {request: {timeout}} instead. See https://github.com/octokit/request.js#request" | ||
) | ||
); | ||
clientDefaults.request.timeout = options.timeout; | ||
} | ||
|
||
if (options.agent) { | ||
deprecateOptionsAgent(log, new Deprecation('[@octokit/rest] new Octokit({agent}) is deprecated. Use {request: {agent}} instead. See https://github.com/octokit/request.js#request')) | ||
clientDefaults.request.agent = options.agent | ||
deprecateOptionsAgent( | ||
log, | ||
new Deprecation( | ||
"[@octokit/rest] new Octokit({agent}) is deprecated. Use {request: {agent}} instead. See https://github.com/octokit/request.js#request" | ||
) | ||
); | ||
clientDefaults.request.agent = options.agent; | ||
} | ||
|
||
if (options.headers) { | ||
deprecateOptionsHeaders(log, new Deprecation('[@octokit/rest] new Octokit({headers}) is deprecated. Use {userAgent, previews} instead. See https://github.com/octokit/request.js#request')) | ||
deprecateOptionsHeaders( | ||
log, | ||
new Deprecation( | ||
"[@octokit/rest] new Octokit({headers}) is deprecated. Use {userAgent, previews} instead. See https://github.com/octokit/request.js#request" | ||
) | ||
); | ||
} | ||
|
||
const userAgentOption = clientDefaults.headers['user-agent'] | ||
const defaultUserAgent = `octokit.js/${pkg.version} ${getUserAgent()}` | ||
const userAgentOption = clientDefaults.headers["user-agent"]; | ||
const defaultUserAgent = `octokit.js/${pkg.version} ${getUserAgent()}`; | ||
|
||
clientDefaults.headers['user-agent'] = [userAgentOption, defaultUserAgent].filter(Boolean).join(' ') | ||
clientDefaults.headers["user-agent"] = [userAgentOption, defaultUserAgent] | ||
.filter(Boolean) | ||
.join(" "); | ||
|
||
clientDefaults.request.hook = hook.bind(null, 'request') | ||
clientDefaults.request.hook = hook.bind(null, "request"); | ||
|
||
return clientDefaults | ||
return clientDefaults; | ||
} |
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,7 +1,9 @@ | ||
module.exports = registerPlugin | ||
module.exports = registerPlugin; | ||
|
||
const factory = require('./factory') | ||
const factory = require("./factory"); | ||
|
||
function registerPlugin (plugins, pluginFunction) { | ||
return factory(plugins.includes(pluginFunction) ? plugins : plugins.concat(pluginFunction)) | ||
function registerPlugin(plugins, pluginFunction) { | ||
return factory( | ||
plugins.includes(pluginFunction) ? plugins : plugins.concat(pluginFunction) | ||
); | ||
} |
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 |
---|---|---|
@@ -1,41 +1,52 @@ | ||
module.exports = authenticate | ||
module.exports = authenticate; | ||
|
||
const { Deprecation } = require('deprecation') | ||
const once = require('once') | ||
const { Deprecation } = require("deprecation"); | ||
const once = require("once"); | ||
|
||
const deprecateAuthenticate = once((log, deprecation) => log.warn(deprecation)) | ||
const deprecateAuthenticate = once((log, deprecation) => log.warn(deprecation)); | ||
|
||
function authenticate (state, options) { | ||
deprecateAuthenticate(state.octokit.log, new Deprecation('[@octokit/rest] octokit.authenticate() is deprecated. Use "auth" constructor option instead.')) | ||
function authenticate(state, options) { | ||
deprecateAuthenticate( | ||
state.octokit.log, | ||
new Deprecation( | ||
'[@octokit/rest] octokit.authenticate() is deprecated. Use "auth" constructor option instead.' | ||
) | ||
); | ||
|
||
if (!options) { | ||
state.auth = false | ||
return | ||
state.auth = false; | ||
return; | ||
} | ||
|
||
switch (options.type) { | ||
case 'basic': | ||
case "basic": | ||
if (!options.username || !options.password) { | ||
throw new Error('Basic authentication requires both a username and password to be set') | ||
throw new Error( | ||
"Basic authentication requires both a username and password to be set" | ||
); | ||
} | ||
break | ||
break; | ||
|
||
case 'oauth': | ||
case "oauth": | ||
if (!options.token && !(options.key && options.secret)) { | ||
throw new Error('OAuth2 authentication requires a token or key & secret to be set') | ||
throw new Error( | ||
"OAuth2 authentication requires a token or key & secret to be set" | ||
); | ||
} | ||
break | ||
break; | ||
|
||
case 'token': | ||
case 'app': | ||
case "token": | ||
case "app": | ||
if (!options.token) { | ||
throw new Error('Token authentication requires a token to be set') | ||
throw new Error("Token authentication requires a token to be set"); | ||
} | ||
break | ||
break; | ||
|
||
default: | ||
throw new Error("Invalid authentication type, must be 'basic', 'oauth', 'token' or 'app'") | ||
throw new Error( | ||
"Invalid authentication type, must be 'basic', 'oauth', 'token' or 'app'" | ||
); | ||
} | ||
|
||
state.auth = options | ||
state.auth = options; | ||
} |
Oops, something went wrong.