/
run.ts
54 lines (47 loc) 路 1.82 KB
/
run.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require("dotenv").config();
import pkgConf from "pkg-conf";
import program from "commander";
import { ApplicationFunction } from "./types";
import { Probot } from "./index";
import { setupAppFactory } from "./apps/setup";
import { logWarningsForObsoleteEnvironmentVariables } from "./helpers/log-warnings-for-obsolete-environment-variables";
import { getLog } from "./helpers/get-log";
import { readCliOptions } from "./bin/read-cli-options";
import { readEnvOptions } from "./bin/read-env-options";
export async function run(appFnOrArgv: ApplicationFunction | string[]) {
const {
logLevel: level,
logFormat,
logLevelInString,
sentryDsn,
...options
} = Array.isArray(appFnOrArgv)
? readCliOptions(appFnOrArgv)
: readEnvOptions();
const log = getLog({ level, logFormat, logLevelInString, sentryDsn });
logWarningsForObsoleteEnvironmentVariables(log);
const probot = new Probot({ log, ...options });
if (!options.id || !options.privateKey) {
if (process.env.NODE_ENV === "production") {
if (!options.id) {
throw new Error(
"Application ID is missing, and is required to run in production mode. " +
"To resolve, ensure the APP_ID environment variable is set."
);
} else if (!options.privateKey) {
throw new Error(
"Certificate is missing, and is required to run in production mode. " +
"To resolve, ensure either the PRIVATE_KEY or PRIVATE_KEY_PATH environment variable is set and contains a valid certificate"
);
}
}
probot.load(setupAppFactory(options.host, options.port));
} else if (Array.isArray(appFnOrArgv)) {
const pkg = await pkgConf("probot");
probot.setup(program.args.concat((pkg.apps as string[]) || []));
} else {
probot.load(appFnOrArgv);
}
probot.start();
return probot;
}