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.Probot = void 0;
|
7 | const lru_cache_1 = __importDefault(require("lru-cache"));
|
8 | const alias_log_1 = require("./helpers/alias-log");
|
9 | const auth_1 = require("./auth");
|
10 | const get_log_1 = require("./helpers/get-log");
|
11 | const get_probot_octokit_with_defaults_1 = require("./octokit/get-probot-octokit-with-defaults");
|
12 | const get_webhooks_1 = require("./octokit/get-webhooks");
|
13 | const probot_octokit_1 = require("./octokit/probot-octokit");
|
14 | const version_1 = require("./version");
|
15 | class Probot {
|
16 | constructor(options = {}) {
|
17 | options.secret = options.secret || "development";
|
18 | let level = options.logLevel;
|
19 | const logMessageKey = options.logMessageKey;
|
20 | this.log = alias_log_1.aliasLog(options.log || get_log_1.getLog({ level, logMessageKey }));
|
21 |
|
22 | const cache = new lru_cache_1.default({
|
23 |
|
24 | max: 15000,
|
25 |
|
26 | maxAge: 1000 * 60 * 59,
|
27 | });
|
28 | const Octokit = get_probot_octokit_with_defaults_1.getProbotOctokitWithDefaults({
|
29 | githubToken: options.githubToken,
|
30 | Octokit: options.Octokit || probot_octokit_1.ProbotOctokit,
|
31 | appId: Number(options.appId),
|
32 | privateKey: options.privateKey,
|
33 | cache,
|
34 | log: this.log,
|
35 | redisConfig: options.redisConfig,
|
36 | baseUrl: options.baseUrl,
|
37 | });
|
38 | const octokit = new Octokit();
|
39 | this.state = {
|
40 | cache,
|
41 | githubToken: options.githubToken,
|
42 | log: this.log,
|
43 | Octokit,
|
44 | octokit,
|
45 | webhooks: {
|
46 | secret: options.secret,
|
47 | },
|
48 | appId: Number(options.appId),
|
49 | privateKey: options.privateKey,
|
50 | host: options.host,
|
51 | port: options.port,
|
52 | };
|
53 | this.auth = auth_1.auth.bind(null, this.state);
|
54 | this.webhooks = get_webhooks_1.getWebhooks(this.state);
|
55 | this.on = this.webhooks.on;
|
56 | this.onAny = this.webhooks.onAny;
|
57 | this.onError = this.webhooks.onError;
|
58 | this.version = version_1.VERSION;
|
59 | }
|
60 | static defaults(defaults) {
|
61 | const ProbotWithDefaults = class extends this {
|
62 | constructor(...args) {
|
63 | const options = args[0] || {};
|
64 | super(Object.assign({}, defaults, options));
|
65 | }
|
66 | };
|
67 | return ProbotWithDefaults;
|
68 | }
|
69 | receive(event) {
|
70 | this.log.debug({ event }, "Webhook received");
|
71 | return this.webhooks.receive(event);
|
72 | }
|
73 | async load(appFn) {
|
74 | if (Array.isArray(appFn)) {
|
75 | for (const fn of appFn) {
|
76 | await this.load(fn);
|
77 | }
|
78 | return;
|
79 | }
|
80 | return appFn(this, {});
|
81 | }
|
82 | }
|
83 | exports.Probot = Probot;
|
84 | Probot.version = version_1.VERSION;
|
85 |
|
\ | No newline at end of file |