UNPKG

2.22 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.createProbot = void 0;
4const get_private_key_1 = require("@probot/get-private-key");
5const get_log_1 = require("./helpers/get-log");
6const probot_1 = require("./probot");
7const DEFAULTS = {
8 APP_ID: "",
9 WEBHOOK_SECRET: "",
10 GHE_HOST: "",
11 GHE_PROTOCOL: "",
12 LOG_FORMAT: "",
13 LOG_LEVEL: "warn",
14 LOG_LEVEL_IN_STRING: "",
15 REDIS_URL: "",
16 SENTRY_DSN: "",
17};
18/**
19 * Merges configuration from defaults/environment variables/overrides and returns
20 * a Probot instance. Finds private key using [`@probot/get-private-key`](https://github.com/probot/get-private-key).
21 *
22 * @see https://probot.github.io/docs/configuration/
23 * @param defaults default Options, will be overwritten if according environment variable is set
24 * @param overrides overwrites defaults and according environment variables
25 * @param env defaults to process.env
26 */
27function createProbot({ overrides = {}, defaults = {}, env = process.env, } = {}) {
28 const privateKey = get_private_key_1.getPrivateKey({ env });
29 const envWithDefaults = { ...DEFAULTS, ...env };
30 const envOptions = {
31 logLevel: envWithDefaults.LOG_LEVEL,
32 appId: Number(envWithDefaults.APP_ID),
33 privateKey: (privateKey && privateKey.toString()) || undefined,
34 secret: envWithDefaults.WEBHOOK_SECRET,
35 redisConfig: envWithDefaults.REDIS_URL,
36 baseUrl: envWithDefaults.GHE_HOST
37 ? `${envWithDefaults.GHE_PROTOCOL || "https"}://${envWithDefaults.GHE_HOST}/api/v3`
38 : "https://api.github.com",
39 };
40 const probotOptions = {
41 ...defaults,
42 ...envOptions,
43 ...overrides,
44 };
45 const logOptions = {
46 level: probotOptions.logLevel,
47 logFormat: envWithDefaults.LOG_FORMAT,
48 logLevelInString: envWithDefaults.LOG_LEVEL_IN_STRING === "true",
49 sentryDsn: envWithDefaults.SENTRY_DSN,
50 };
51 const log = get_log_1.getLog(logOptions).child({ name: "server" });
52 return new probot_1.Probot({
53 log: log.child({ name: "probot" }),
54 ...probotOptions,
55 });
56}
57exports.createProbot = createProbot;
58//# sourceMappingURL=create-probot.js.map
\No newline at end of file