43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
import { Octokit as OctokitCore } from "@octokit/core";
|
|
import { paginateRest } from "@octokit/plugin-paginate-rest";
|
|
import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
|
|
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
|
|
import { retry } from "@octokit/plugin-retry";
|
|
import { throttling } from "@octokit/plugin-throttling";
|
|
import { VERSION } from "./version.js";
|
|
import { RequestError } from "@octokit/request-error";
|
|
const Octokit = OctokitCore.plugin(
|
|
restEndpointMethods,
|
|
paginateRest,
|
|
paginateGraphQL,
|
|
retry,
|
|
throttling
|
|
).defaults({
|
|
userAgent: `octokit.js/${VERSION}`,
|
|
throttle: {
|
|
onRateLimit,
|
|
onSecondaryRateLimit
|
|
}
|
|
});
|
|
function onRateLimit(retryAfter, options, octokit) {
|
|
octokit.log.warn(
|
|
`Request quota exhausted for request ${options.method} ${options.url}`
|
|
);
|
|
if (options.request.retryCount === 0) {
|
|
octokit.log.info(`Retrying after ${retryAfter} seconds!`);
|
|
return true;
|
|
}
|
|
}
|
|
function onSecondaryRateLimit(retryAfter, options, octokit) {
|
|
octokit.log.warn(
|
|
`SecondaryRateLimit detected for request ${options.method} ${options.url}`
|
|
);
|
|
if (options.request.retryCount === 0) {
|
|
octokit.log.info(`Retrying after ${retryAfter} seconds!`);
|
|
return true;
|
|
}
|
|
}
|
|
export {
|
|
Octokit,
|
|
RequestError
|
|
};
|