Skip to content

Commit

Permalink
fix: logging of first octokit instance is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
kammerjaeger committed Apr 12, 2022
1 parent 420f886 commit 280ceb3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/octokit/get-probot-octokit-with-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ export function getProbotOctokitWithDefaults(options: Options) {
defaultOptions.throttle = octokitThrottleOptions;
}

if (options.log) {
const pinoLog = options.log.child({ name: "github" });
defaultOptions.log = {
fatal: pinoLog.fatal.bind(pinoLog),
error: pinoLog.error.bind(pinoLog),
warn: pinoLog.warn.bind(pinoLog),
info: pinoLog.info.bind(pinoLog),
debug: pinoLog.debug.bind(pinoLog),
trace: pinoLog.trace.bind(pinoLog),
};
}

return options.Octokit.defaults((instanceOptions: any) => {
const options = Object.assign({}, defaultOptions, instanceOptions, {
auth: instanceOptions.auth
Expand Down
20 changes: 20 additions & 0 deletions test/create-probot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,24 @@ describe("createProbot", () => {
});
expect(JSON.parse(outputData).myMessage).toEqual("Ciao");
});

test("env, octokit logger set", async () => {
const outputData = await captureLogOutput(async () => {
const probot = createProbot({
env: {
...env,
LOG_LEVEL: "info",
LOG_FORMAT: "json",
LOG_MESSAGE_KEY: "myMessage",
},
});

const octokit = await probot.auth();
octokit.log.info("Ciao");
});
expect(JSON.parse(outputData)).toMatchObject({
myMessage: "Ciao",
name: "github",
});
});
});

0 comments on commit 280ceb3

Please sign in to comment.