Skip to content

Commit 0aa7f7d

Browse files
feat(bot): use Probot programmatic API with t3-env validation (#2015)
* feat(bot): add custom env var mapping for Fly.io deployment - Create server.ts entry point that maps GITHUB_BOT_* env vars to Probot's expected names - Update package.json start script to use new server entry point - Update Dockerfile CMD to use new server entry point This allows the bot to use custom environment variable names (GITHUB_BOT_APP_ID, GITHUB_BOT_PRIVATE_KEY, GITHUB_BOT_WEBHOOK_SECRET, etc.) while maintaining compatibility with Probot's default env var names. Co-Authored-By: yujonglee <[email protected]> * refactor(bot): use Probot programmatic API with t3-env validation - Create env.ts with t3-env validation for GITHUB_BOT_* env vars - Refactor server.ts to use Server class with Probot.defaults() - Add @t3-oss/env-core and zod dependencies This uses the programmatic API to pass appId, privateKey, and secret directly to Probot instead of mapping environment variables. Co-Authored-By: yujonglee <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent b94ee38 commit 0aa7f7d

File tree

5 files changed

+60
-107
lines changed

5 files changed

+60
-107
lines changed

apps/bot/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ FROM node:22-slim AS runtime
2222
WORKDIR /app
2323
ENV NODE_ENV="production"
2424
COPY --from=build /runtime ./
25-
CMD ["node", "node_modules/probot/bin/probot.js", "run", "./lib/index.js"]
25+
CMD ["node", "./lib/server.js"]

apps/bot/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
"scripts": {
66
"build": "tsc",
77
"typecheck": "tsc --noEmit",
8-
"start": "probot run ./lib/index.js",
8+
"start": "node ./lib/server.js",
99
"test": "vitest run"
1010
},
1111
"dependencies": {
12-
"probot": "^13.4.5"
12+
"@t3-oss/env-core": "^0.13.8",
13+
"probot": "^13.4.5",
14+
"zod": "^4.1.13"
1315
},
1416
"devDependencies": {
1517
"@types/node": "^20.0.0",
1618
"nock": "^14.0.5",
1719
"smee-client": "^2.0.0",
18-
"vitest": "^2.0.0",
19-
"typescript": "^5.8.3"
20+
"typescript": "^5.8.3",
21+
"vitest": "^2.0.0"
2022
},
2123
"overrides": {
2224
"@types/pg": "8.15.1"

apps/bot/src/env.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createEnv } from "@t3-oss/env-core";
2+
import { z } from "zod";
3+
4+
export const env = createEnv({
5+
server: {
6+
GITHUB_BOT_APP_ID: z.coerce.number().int().positive(),
7+
GITHUB_BOT_PRIVATE_KEY: z.string().min(1),
8+
GITHUB_BOT_WEBHOOK_SECRET: z.string().min(1),
9+
GITHUB_BOT_CLIENT_ID: z.string().min(1).optional(),
10+
GITHUB_BOT_CLIENT_SECRET: z.string().min(1).optional(),
11+
},
12+
runtimeEnv: process.env,
13+
emptyStringAsUndefined: true,
14+
});

apps/bot/src/server.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Probot, Server } from "probot";
2+
3+
import { env } from "./env.js";
4+
import app from "./index.js";
5+
6+
async function start() {
7+
const server = new Server({
8+
Probot: Probot.defaults({
9+
appId: env.GITHUB_BOT_APP_ID,
10+
privateKey: env.GITHUB_BOT_PRIVATE_KEY,
11+
secret: env.GITHUB_BOT_WEBHOOK_SECRET,
12+
}),
13+
});
14+
15+
await server.load(app);
16+
await server.start();
17+
}
18+
19+
start();

pnpm-lock.yaml

Lines changed: 20 additions & 102 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)