UNPKG

probot

Version:

A framework for building GitHub Apps to automate and improve your workflow

59 lines (58 loc) 2.14 kB
import { getPrivateKey } from "@probot/get-private-key"; import { Probot } from "./probot.js"; import { defaultWebhookPath } from "./server/server.js"; const DEFAULTS = { APP_ID: "", WEBHOOK_SECRET: "", WEBHOOK_PATH: defaultWebhookPath, GHE_HOST: "", GHE_PROTOCOL: "https", LOG_FORMAT: undefined, LOG_LEVEL: "warn", LOG_LEVEL_IN_STRING: "false", LOG_MESSAGE_KEY: "msg", REDIS_URL: "", SENTRY_DSN: "", }; /** * Merges configuration from defaults/environment variables/overrides and returns * a Probot instance. Finds private key using [`@probot/get-private-key`](https://github.com/probot/get-private-key). * * @see https://probot.github.io/docs/configuration/ * @param defaults default Options, will be overwritten if according environment variable is set * @param overrides overwrites defaults and according environment variables * @param env defaults to process.env */ export function createProbot({ overrides = {}, defaults = {}, env = process.env, } = {}) { let privateKey; try { privateKey = getPrivateKey({ env }); } catch { } const envWithDefaults = { ...DEFAULTS, ...env }; const envOptions = { logLevel: envWithDefaults.LOG_LEVEL, appId: Number(envWithDefaults.APP_ID), privateKey: (privateKey && privateKey.toString()) || undefined, secret: envWithDefaults.WEBHOOK_SECRET, redisConfig: envWithDefaults.REDIS_URL, webhookPath: envWithDefaults.WEBHOOK_PATH, baseUrl: envWithDefaults.GHE_HOST ? `${envWithDefaults.GHE_PROTOCOL || "https"}://${envWithDefaults.GHE_HOST}/api/v3` : "https://api.github.com", }; const probotOptions = { ...defaults, ...envOptions, ...overrides, }; return new Probot({ log: probotOptions.log, logLevel: probotOptions.logLevel, logFormat: envWithDefaults.LOG_FORMAT, logLevelInString: envWithDefaults.LOG_LEVEL_IN_STRING === "true", logMessageKey: envWithDefaults.LOG_MESSAGE_KEY, sentryDsn: envWithDefaults.SENTRY_DSN, ...probotOptions, }); }