UNPKG

probot

Version:

A framework for building GitHub Apps to automate and improve your workflow

64 lines 2.34 kB
import { request } from "@octokit/request"; import { ProbotOctokit } from "./probot-octokit.js"; import { getOctokitThrottleOptions } from "./get-octokit-throttle-options.js"; /** * Returns an Octokit instance with default settings for authentication. If * a `githubToken` is passed explicitly, the Octokit instance will be * pre-authenticated with that token when instantiated. Otherwise Octokit's * app authentication strategy is used, and `options.auth` options are merged * deeply when instantiated. * * Besides the authentication, the Octokit's baseUrl is set as well when run * against a GitHub Enterprise Server with a custom domain. */ export async function getProbotOctokitWithDefaults(options) { const authOptions = options.githubToken ? { token: options.githubToken, request: request.defaults({ request: { fetch: options.request?.fetch, }, }), } : { cache: options.cache, appId: options.appId, privateKey: options.privateKey, request: request.defaults({ request: { fetch: options.request?.fetch, }, }), }; const log = options.log.child({ name: "octokit" }); const octokitThrottleOptions = await getOctokitThrottleOptions({ log, redisConfig: options.redisConfig, }); const defaultOptions = { log, auth: authOptions, }; if (options.request) { defaultOptions.request = options.request; } if (options.baseUrl) { defaultOptions.baseUrl = options.baseUrl; } if (octokitThrottleOptions) { defaultOptions.throttle = octokitThrottleOptions; } return options.Octokit.defaults((instanceOptions) => { const options = Object.assign({}, defaultOptions, instanceOptions, { auth: instanceOptions.auth ? Object.assign({}, defaultOptions.auth, instanceOptions.auth) : defaultOptions.auth, }); if (instanceOptions.throttle) { options.throttle = Object.assign({}, defaultOptions.throttle, instanceOptions.throttle); } return options; }); } //# sourceMappingURL=get-probot-octokit-with-defaults.js.map