feat(run): allow passing `Octokit` and `log` (#1984)

This commit is contained in:
Harry Dobrev 2024-03-12 19:00:08 +02:00 committed by GitHub
parent c62652e368
commit d1952641f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 4 deletions

View File

@ -166,6 +166,20 @@ import app from "./index.js";
run(app);
```
You can also set your own [`Octokit` constructor](https://github.com/octokit/core.js) with custom plugins and a custom logger while still reading default options from `.env`:
```js
// main.js
import { run } from "probot";
import app from "./index.js";
// pass a probot app function by overriding Probot options
run(app, {
Octokit: ProbotOctokit.plugin(myPlugin),
log: pino(),
});
```
Now you can run `main.js` however you want.
### Use server
@ -175,7 +189,7 @@ The [`run`](https://github.com/probot/probot/blob/master/src/run.ts) function th
1. Read configuration from environment variables and local files
2. Start a [`Server`](https://probot.github.io/api/latest/classes/server_server.Server.html) instance
Among other things, using the Server instance permits you to set your own [`Octokit` constructor](https://github.com/octokit/core.js) with custom plugins and a custom logger.
If you need more control over the Server instance, you can use the `Server` class directly:
```js
import { Server, Probot } from "probot";

View File

@ -1,7 +1,7 @@
import pkgConf from "pkg-conf";
import type { ApplicationFunction, Options, ServerOptions } from "./types.js";
import { Probot } from "./index.js";
import { Logger, Probot, ProbotOctokit } from "./index.js";
import { setupAppFactory } from "./apps/setup.js";
import { getLog } from "./helpers/get-log.js";
import { readCliOptions } from "./bin/read-cli-options.js";
@ -13,7 +13,9 @@ import { isProduction } from "./helpers/is-production.js";
import { config as dotenvConfig } from "dotenv";
type AdditionalOptions = {
env: NodeJS.ProcessEnv;
env?: NodeJS.ProcessEnv;
Octokit?: typeof ProbotOctokit;
log?: Logger;
};
/**
@ -70,7 +72,8 @@ export async function run(
redisConfig,
secret,
baseUrl,
log: log.child({ name: "probot" }),
log: additionalOptions?.log || log.child({ name: "probot" }),
Octokit: additionalOptions?.Octokit || undefined,
};
const serverOptions: ServerOptions = {