Skip to content

Commit

Permalink
chore: removed js-yaml and re-enabled octokit plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Jan 18, 2025
1 parent 320ed6e commit 74136a1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"@swc/jest": "0.2.36",
"@types/console-log-level": "^1.4.5",
"@types/jest": "29.5.12",
"@types/js-yaml": "^4.0.9",
"@types/node": "20.14.10",
"@types/node-rsa": "^1.1.4",
"azure-functions-core-tools": "^4.0.6610",
Expand Down
58 changes: 18 additions & 40 deletions src/github/github-client.ts
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);
});

0 comments on commit 74136a1

Please sign in to comment.