1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getOptions = void 0;
|
4 | const deprecation_1 = require("deprecation");
|
5 | const get_private_key_1 = require("@probot/get-private-key");
|
6 | const get_log_1 = require("./helpers/get-log");
|
7 | const probot_1 = require("./probot");
|
8 | const 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 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | function 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 | }
|
73 | exports.getOptions = getOptions;
|
74 |
|
\ | No newline at end of file |