Skip to content

Commit

Permalink
feat(run): allow passing Octokit and log (#1984)
Browse files Browse the repository at this point in the history
  • Loading branch information
hkdobrev committed Mar 12, 2024
1 parent c62652e commit d195264
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 15 additions & 1 deletion docs/development.md
Expand Up @@ -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
Expand All @@ -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";
Expand Down
9 changes: 6 additions & 3 deletions src/run.ts
@@ -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";
Expand All @@ -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;
};

/**
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit d195264

Please sign in to comment.