1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.run = void 0;
|
7 | const pkg_conf_1 = __importDefault(require("pkg-conf"));
|
8 | const index_1 = require("./index");
|
9 | const setup_1 = require("./apps/setup");
|
10 | const get_log_1 = require("./helpers/get-log");
|
11 | const read_cli_options_1 = require("./bin/read-cli-options");
|
12 | const read_env_options_1 = require("./bin/read-env-options");
|
13 | const server_1 = require("./server/server");
|
14 | const default_1 = require("./apps/default");
|
15 | const resolve_app_function_1 = require("./helpers/resolve-app-function");
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | async function run(appFnOrArgv, additionalOptions) {
|
21 | require("dotenv").config();
|
22 | const envOptions = read_env_options_1.readEnvOptions(additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.env);
|
23 | const cliOptions = Array.isArray(appFnOrArgv)
|
24 | ? read_cli_options_1.readCliOptions(appFnOrArgv)
|
25 | : {};
|
26 | const {
|
27 |
|
28 | logLevel: level, logFormat, logLevelInString, logMessageKey, sentryDsn,
|
29 |
|
30 | host, port, webhookPath, webhookProxy,
|
31 |
|
32 | appId, privateKey, redisConfig, secret, baseUrl,
|
33 |
|
34 | args, } = { ...envOptions, ...cliOptions };
|
35 | const logOptions = {
|
36 | level,
|
37 | logFormat,
|
38 | logLevelInString,
|
39 | logMessageKey,
|
40 | sentryDsn,
|
41 | };
|
42 | const log = get_log_1.getLog(logOptions);
|
43 | const probotOptions = {
|
44 | appId,
|
45 | privateKey,
|
46 | redisConfig,
|
47 | secret,
|
48 | baseUrl,
|
49 | log: log.child({ name: "probot" }),
|
50 | };
|
51 | const serverOptions = {
|
52 | host,
|
53 | port,
|
54 | webhookPath,
|
55 | webhookProxy,
|
56 | log: log.child({ name: "server" }),
|
57 | Probot: index_1.Probot.defaults(probotOptions),
|
58 | };
|
59 | let server;
|
60 | if (!appId || !privateKey) {
|
61 | if (process.env.NODE_ENV === "production") {
|
62 | if (!appId) {
|
63 | throw new Error("App ID is missing, and is required to run in production mode. " +
|
64 | "To resolve, ensure the APP_ID environment variable is set.");
|
65 | }
|
66 | else if (!privateKey) {
|
67 | throw new Error("Certificate is missing, and is required to run in production mode. " +
|
68 | "To resolve, ensure either the PRIVATE_KEY or PRIVATE_KEY_PATH environment variable is set and contains a valid certificate");
|
69 | }
|
70 | }
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | server = new server_1.Server({
|
78 | ...serverOptions,
|
79 | Probot: index_1.Probot.defaults({
|
80 | ...probotOptions,
|
81 | appId: 1,
|
82 | privateKey: "dummy value for setup, see #1512",
|
83 | }),
|
84 | });
|
85 | await server.load(setup_1.setupAppFactory(host, port));
|
86 | await server.start();
|
87 | return server;
|
88 | }
|
89 | if (Array.isArray(appFnOrArgv)) {
|
90 | const pkg = await pkg_conf_1.default("probot");
|
91 | const combinedApps = async (app) => {
|
92 | await server.load(default_1.defaultApp);
|
93 | if (Array.isArray(pkg.apps)) {
|
94 | for (const appPath of pkg.apps) {
|
95 | const appFn = await resolve_app_function_1.resolveAppFunction(appPath);
|
96 | await server.load(appFn);
|
97 | }
|
98 | }
|
99 | const [appPath] = args;
|
100 | const appFn = await resolve_app_function_1.resolveAppFunction(appPath);
|
101 | await server.load(appFn);
|
102 | };
|
103 | server = new server_1.Server(serverOptions);
|
104 | await server.load(combinedApps);
|
105 | await server.start();
|
106 | return server;
|
107 | }
|
108 | server = new server_1.Server(serverOptions);
|
109 | await server.load(appFnOrArgv);
|
110 | await server.start();
|
111 | return server;
|
112 | }
|
113 | exports.run = run;
|
114 |
|
\ | No newline at end of file |