UNPKG

2.85 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getOptions = void 0;
4const deprecation_1 = require("deprecation");
5const get_private_key_1 = require("@probot/get-private-key");
6const get_log_1 = require("./helpers/get-log");
7const probot_1 = require("./probot");
8const DEFAULTS = {
9 APP_ID: "",
10 GHE_HOST: "",
11 GHE_PROTOCOL: "",
12 HOST: "",
13 LOG_FORMAT: "",
14 LOG_LEVEL: "warn",
15 LOG_LEVEL_IN_STRING: "",
16 PORT: "3000",
17 REDIS_URL: "",
18 SENTRY_DSN: "",
19 WEBHOOK_PATH: "",
20 WEBHOOK_PROXY_URL: "",
21 WEBHOOK_SECRET: "",
22};
23/**
24 * Merges configuration from defaults, environment variables, and overrides.
25 * Finds private key using [`@probot/get-private-key`](https://github.com/probot/get-private-key).
26 *
27 * @see https://probot.github.io/docs/configuration/
28 * @param defaults default Options, will be overwritten if according environment variable is set
29 * @param overrides overwrites defaults and according environment variables
30 * @param env defaults to process.env
31 */
32function getOptions({ overrides = {}, defaults = {}, env = process.env, } = {}) {
33 const privateKey = get_private_key_1.getPrivateKey({ env });
34 const envWithDefaults = { ...DEFAULTS, ...env };
35 const logOptions = {
36 level: envWithDefaults.LOG_LEVEL,
37 logFormat: envWithDefaults.LOG_FORMAT,
38 logLevelInString: envWithDefaults.LOG_LEVEL_IN_STRING === "true",
39 sentryDsn: envWithDefaults.SENTRY_DSN,
40 };
41 const probotOptions = {
42 appId: Number(envWithDefaults.APP_ID),
43 privateKey: (privateKey && privateKey.toString()) || undefined,
44 secret: envWithDefaults.WEBHOOK_SECRET,
45 redisConfig: envWithDefaults.REDIS_URL,
46 baseUrl: envWithDefaults.GHE_HOST
47 ? `${envWithDefaults.GHE_PROTOCOL || "https"}://${envWithDefaults.GHE_HOST}/api/v3`
48 : "https://api.github.com",
49 };
50 const log = get_log_1.getLog(logOptions).child({ name: "server" });
51 const ProbotWithDefaults = probot_1.Probot.defaults({
52 ...probotOptions,
53 log: log.child({ name: "probot" }),
54 });
55 const options = {
56 ...defaults,
57 host: envWithDefaults.HOST,
58 port: Number(envWithDefaults.PORT),
59 webhookPath: envWithDefaults.WEBHOOK_PATH,
60 webhookProxy: envWithDefaults.WEBHOOK_PROXY_URL,
61 log,
62 Probot: ProbotWithDefaults,
63 ...overrides,
64 };
65 options.log.warn(new deprecation_1.Deprecation(`[probot] "getOptions()" is deprecated, use "{ probot: createProbot() }" instead:
66
67 const { createNodeMiddleware, createProbot } = require("probot");
68 const myApp = require("./my-app.js");
69
70 module.exports = createNodeMiddleware(myApp, { probot: createProbot() });`));
71 return options;
72}
73exports.getOptions = getOptions;
74//# sourceMappingURL=get-options.js.map
\No newline at end of file