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, 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 | sentryDsn,
|
40 | };
|
41 | const log = get_log_1.getLog(logOptions);
|
42 | const probotOptions = {
|
43 | appId,
|
44 | privateKey,
|
45 | redisConfig,
|
46 | secret,
|
47 | baseUrl,
|
48 | log: log.child({ name: "probot" }),
|
49 | };
|
50 | const serverOptions = {
|
51 | host,
|
52 | port,
|
53 | webhookPath,
|
54 | webhookProxy,
|
55 | log: log.child({ name: "server" }),
|
56 | Probot: index_1.Probot.defaults(probotOptions),
|
57 | };
|
58 | let server;
|
59 | if (!appId || !privateKey) {
|
60 | if (process.env.NODE_ENV === "production") {
|
61 | if (!appId) {
|
62 | throw new Error("App ID is missing, and is required to run in production mode. " +
|
63 | "To resolve, ensure the APP_ID environment variable is set.");
|
64 | }
|
65 | else if (!privateKey) {
|
66 | throw new Error("Certificate is missing, and is required to run in production mode. " +
|
67 | "To resolve, ensure either the PRIVATE_KEY or PRIVATE_KEY_PATH environment variable is set and contains a valid certificate");
|
68 | }
|
69 | }
|
70 | server = new server_1.Server(serverOptions);
|
71 | await server.load(setup_1.setupAppFactory(host, port));
|
72 | await server.start();
|
73 | return server;
|
74 | }
|
75 | if (Array.isArray(appFnOrArgv)) {
|
76 | const pkg = await pkg_conf_1.default("probot");
|
77 | const combinedApps = async (app) => {
|
78 | await server.load(default_1.defaultApp);
|
79 | if (Array.isArray(pkg.apps)) {
|
80 | for (const appPath of pkg.apps) {
|
81 | const appFn = await resolve_app_function_1.resolveAppFunction(appPath);
|
82 | server.load(appFn);
|
83 | }
|
84 | }
|
85 | const [appPath] = args;
|
86 | const appFn = await resolve_app_function_1.resolveAppFunction(appPath);
|
87 | server.load(appFn);
|
88 | };
|
89 | server = new server_1.Server(serverOptions);
|
90 | await server.load(combinedApps);
|
91 | await server.start();
|
92 | return server;
|
93 | }
|
94 | server = new server_1.Server(serverOptions);
|
95 | await server.load(appFnOrArgv);
|
96 | await server.start();
|
97 | return server;
|
98 | }
|
99 | exports.run = run;
|
100 |
|
\ | No newline at end of file |