Skip to content

Commit

Permalink
chore: added logs for Octokit
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Jan 10, 2025
1 parent 32996e5 commit 3559bd7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Binary file modified bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@octokit/auth-app": "7.1.0",
"@octokit/core": "6.1.2",
"@octokit/plugin-paginate-rest": "11.3.3",
"@octokit/plugin-request-log": "^5.3.1",
"@octokit/plugin-rest-endpoint-methods": "13.2.4",
"@octokit/plugin-retry": "7.1.1",
"@octokit/plugin-throttling": "9.3.1",
Expand All @@ -63,6 +64,7 @@
"@octokit/webhooks-types": "7.5.1",
"@sinclair/typebox": "0.34.3",
"@ubiquity-os/plugin-sdk": "^1.1.1",
"console-log-level": "^1.4.1",
"dotenv": "16.4.5",
"hono": "^4.6.12",
"openai": "^4.70.2",
Expand All @@ -83,6 +85,7 @@
"@mswjs/http-middleware": "0.10.1",
"@swc/core": "1.6.5",
"@swc/jest": "0.2.36",
"@types/console-log-level": "^1.4.5",
"@types/jest": "29.5.12",
"@types/node": "20.14.10",
"@types/node-rsa": "^1.1.4",
Expand Down
9 changes: 6 additions & 3 deletions src/github/github-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Octokit } from "@octokit/core";
import { requestLog } from "@octokit/plugin-request-log";
import { RequestOptions } from "@octokit/types";
import { paginateRest } from "@octokit/plugin-paginate-rest";
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
Expand Down Expand Up @@ -46,6 +47,8 @@ function requestLogging(octokit: Octokit) {
});
}

export const customOctokit = Octokit.plugin(throttling, retry, paginateRest, restEndpointMethods, requestLogging).defaults((instanceOptions: object) => {
return Object.assign({}, defaultOptions, instanceOptions);
});
export const customOctokit = Octokit.plugin(throttling, retry, paginateRest, restEndpointMethods, requestLogging, requestLog).defaults(
(instanceOptions: object) => {
return Object.assign({}, defaultOptions, instanceOptions);
}
);
13 changes: 11 additions & 2 deletions src/github/github-event-handler.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { EmitterWebhookEvent, Webhooks } from "@octokit/webhooks";
import { createAppAuth } from "@octokit/auth-app";
import { EmitterWebhookEvent, Webhooks } from "@octokit/webhooks";
import { signPayload } from "@ubiquity-os/plugin-sdk/signature";
import logger from "console-log-level";
import OpenAI from "openai";

import { customOctokit } from "./github-client";
import { GitHubContext, SimplifiedContext } from "./github-context";
import { KvStore } from "./utils/kv-store";
import { PluginChainState } from "./types/plugin";
import { KvStore } from "./utils/kv-store";

export type Options = {
environment: "production" | "development";
Expand Down Expand Up @@ -71,6 +72,10 @@ export class GitHubEventHandler {

getAuthenticatedOctokit(installationId: number) {
return new customOctokit({
request: {
fetch: fetch.bind(globalThis),
},
log: logger({ level: "debug" }),
auth: {
appId: this._appId,
privateKey: this._privateKey,
Expand All @@ -81,6 +86,10 @@ export class GitHubEventHandler {

getUnauthenticatedOctokit() {
return new customOctokit({
request: {
fetch: fetch.bind(globalThis),
},
log: logger({ level: "debug" }),
auth: {
appId: this._appId,
privateKey: this._privateKey,
Expand Down

0 comments on commit 3559bd7

Please sign in to comment.