fix: logging of first octokit instance is not set (#1676) - thanks @kammerjaeger @markjm

This commit is contained in:
David Brodski 2022-06-01 19:41:57 -04:00 committed by GitHub
parent 7fd06d6975
commit 646b6a9276
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import { ProbotOctokit } from "./probot-octokit";
import Redis from "ioredis";
import { getOctokitThrottleOptions } from "./get-octokit-throttle-options";
import { aliasLog } from "../helpers/alias-log";
import type { Logger } from "pino";
@ -45,6 +46,9 @@ export function getProbotOctokitWithDefaults(options: Options) {
let defaultOptions: any = {
auth: authOptions,
log: options.log.child
? aliasLog(options.log.child({ name: "octokit" }))
: options.log,
};
if (options.baseUrl) {

View File

@ -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: "octokit",
});
});
});