Skip to content

Commit

Permalink
feat: allow custom logger for Octokit instances (#2100)
Browse files Browse the repository at this point in the history
Allow custom logger for Octokit instances
  • Loading branch information
Eddman authored Nov 16, 2024
1 parent 89fdd54 commit 19954c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Logger } from "pino";
import { getAuthenticatedOctokit } from "./octokit/get-authenticated-octokit.js";
import { ProbotOctokit } from "./octokit/probot-octokit.js";
import type { State } from "./types.js";
Expand Down Expand Up @@ -31,6 +32,7 @@ import type { State } from "./types.js";
export async function auth(
state: State,
installationId?: number,
log?: Logger,
): Promise<InstanceType<typeof ProbotOctokit>> {
return getAuthenticatedOctokit(Object.assign({}, state), installationId);
return getAuthenticatedOctokit(Object.assign({}, state), installationId, log);
}
7 changes: 4 additions & 3 deletions src/octokit/get-authenticated-octokit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { State } from "../types.js";
import type { ProbotOctokit } from "./probot-octokit.js";
import type { OctokitOptions } from "../types.js";
import type { LogFn, Level } from "pino";
import type { LogFn, Level, Logger } from "pino";

type FactoryOptions = {
octokit: ProbotOctokit;
Expand All @@ -12,16 +12,17 @@ type FactoryOptions = {
export async function getAuthenticatedOctokit(
state: State,
installationId?: number,
log?: Logger,
) {
const { log, octokit } = state;
const { octokit } = state;

if (!installationId) return octokit;

return octokit.auth({
type: "installation",
installationId,
factory: ({ octokit, octokitOptions, ...otherOptions }: FactoryOptions) => {
const pinoLog = log.child({ name: "github" });
const pinoLog = log || state.log.child({ name: "github" });

const options: ConstructorParameters<typeof ProbotOctokit>[0] & {
log: Record<Level, LogFn>;
Expand Down

0 comments on commit 19954c8

Please sign in to comment.