generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: removed js-yaml and re-enabled octokit plugins
- Loading branch information
1 parent
320ed6e
commit 74136a1
Showing
3 changed files
with
18 additions
and
41 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,52 +1,30 @@ | ||
import { Octokit } from "@octokit/core"; | ||
import { requestLog } from "@octokit/plugin-request-log"; | ||
// import { RequestOptions } from "@octokit/types"; | ||
import { RequestOptions } from "@octokit/types"; | ||
import { paginateRest } from "@octokit/plugin-paginate-rest"; | ||
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods"; | ||
// import { retry } from "@octokit/plugin-retry"; | ||
// import { throttling } from "@octokit/plugin-throttling"; | ||
import { retry } from "@octokit/plugin-retry"; | ||
import { throttling } from "@octokit/plugin-throttling"; | ||
import { createAppAuth } from "@octokit/auth-app"; | ||
|
||
const defaultOptions = { | ||
authStrategy: createAppAuth, | ||
// throttle: { | ||
// onAbuseLimit: (retryAfter: number, options: RequestOptions, octokit: Octokit) => { | ||
// octokit.log.warn(`Abuse limit hit with "${options.method} ${options.url}", retrying in ${retryAfter} seconds.`); | ||
// return true; | ||
// }, | ||
// onRateLimit: (retryAfter: number, options: RequestOptions, octokit: Octokit) => { | ||
// octokit.log.warn(`Rate limit hit with "${options.method} ${options.url}", retrying in ${retryAfter} seconds.`); | ||
// return true; | ||
// }, | ||
// onSecondaryRateLimit: (retryAfter: number, options: RequestOptions, octokit: Octokit) => { | ||
// octokit.log.warn(`Secondary rate limit hit with "${options.method} ${options.url}", retrying in ${retryAfter} seconds.`); | ||
// return true; | ||
// }, | ||
// }, | ||
throttle: { | ||
onAbuseLimit: (retryAfter: number, options: RequestOptions, octokit: Octokit) => { | ||
octokit.log.warn(`Abuse limit hit with "${options.method} ${options.url}", retrying in ${retryAfter} seconds.`); | ||
return true; | ||
}, | ||
onRateLimit: (retryAfter: number, options: RequestOptions, octokit: Octokit) => { | ||
octokit.log.warn(`Rate limit hit with "${options.method} ${options.url}", retrying in ${retryAfter} seconds.`); | ||
return true; | ||
}, | ||
onSecondaryRateLimit: (retryAfter: number, options: RequestOptions, octokit: Octokit) => { | ||
octokit.log.warn(`Secondary rate limit hit with "${options.method} ${options.url}", retrying in ${retryAfter} seconds.`); | ||
return true; | ||
}, | ||
}, | ||
}; | ||
|
||
// function requestLogging(octokit: Octokit) { | ||
// octokit.hook.error("request", (error, options) => { | ||
// if ("status" in error) { | ||
// const { method, url, body } = octokit.request.endpoint.parse(options); | ||
// const msg = `GitHub request: ${method} ${url} - ${error.status}`; | ||
// | ||
// // @ts-expect-error log.debug is a pino log method and accepts a fields object | ||
// octokit.log.debug(body || {}, msg); | ||
// } | ||
// | ||
// throw error; | ||
// }); | ||
// | ||
// octokit.hook.after("request", (result, options) => { | ||
// const { method, url, body } = octokit.request.endpoint.parse(options); | ||
// const msg = `GitHub request: ${method} ${url} - ${result.status}`; | ||
// | ||
// // @ts-expect-error log.debug is a pino log method and accepts a fields object | ||
// octokit.log.debug(body || {}, msg); | ||
// }); | ||
// } | ||
|
||
export const customOctokit = Octokit.plugin(paginateRest, restEndpointMethods, requestLog).defaults((instanceOptions: object) => { | ||
export const customOctokit = Octokit.plugin(paginateRest, restEndpointMethods, requestLog, retry, throttling).defaults((instanceOptions: object) => { | ||
return Object.assign({}, defaultOptions, instanceOptions); | ||
}); |