(env: ApiEnv)
| 7 | type ApiEnv = typeof apiEnv; |
| 8 | |
| 9 | export function buildGitHubApp(env: ApiEnv): GitHubApp { |
| 10 | if (env.LOCAL_DEV) { |
| 11 | logger.info("LOCAL_DEV=true - using LocalDevGitHubApp (fake GitHub integration)"); |
| 12 | return new LocalDevGitHubApp(); |
| 13 | } |
| 14 | |
| 15 | const missing = getMissingGitHubCredentials(env); |
| 16 | if (missing.length > 0) { |
| 17 | throw new Error( |
| 18 | `Missing GitHub app credentials: ${missing.join(", ")}. Set them, or set LOCAL_DEV=true to use the fake app.`, |
| 19 | ); |
| 20 | } |
| 21 | |
| 22 | // Postgres-backed ETag store enables conditional requests (free 304s) on every GitHub call. |
| 23 | const etagStore = new PrismaEtagStore(db); |
| 24 | |
| 25 | return new OctokitGitHubApp( |
| 26 | { |
| 27 | appId: env.GITHUB_APP_ID!, |
| 28 | privateKey: env.GITHUB_APP_PRIVATE_KEY!, |
| 29 | webhookSecret: env.GITHUB_APP_WEBHOOK_SECRET!, |
| 30 | appSlug: env.GITHUB_APP_SLUG!, |
| 31 | }, |
| 32 | etagStore, |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | function getMissingGitHubCredentials(env: ApiEnv): string[] { |
| 37 | const missing: string[] = []; |
no test coverage detected