UNPKG

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