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.webhookPath = options.webhookPath || "/";
|
18 | options.secret = options.secret || "development";
|
19 | let level = options.logLevel;
|
20 | this.log = alias_log_1.aliasLog(options.log || get_log_1.getLog({ level }));
|
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 | path: options.webhookPath,
|
47 | secret: options.secret,
|
48 | },
|
49 | appId: Number(options.appId),
|
50 | privateKey: options.privateKey,
|
51 | host: options.host,
|
52 | port: options.port,
|
53 | };
|
54 | this.auth = auth_1.auth.bind(null, this.state);
|
55 | this.webhooks = get_webhooks_1.getWebhooks(this.state);
|
56 | this.on = (eventNameOrNames, callback) => {
|
57 | if (eventNameOrNames === "*") {
|
58 |
|
59 | return this.webhooks.onAny(callback);
|
60 | }
|
61 | return this.webhooks.on(eventNameOrNames, callback);
|
62 | };
|
63 | this.onAny = this.webhooks.onAny;
|
64 | this.onError = this.webhooks.onError;
|
65 | this.version = version_1.VERSION;
|
66 | }
|
67 | static defaults(defaults) {
|
68 | const ProbotWithDefaults = class extends this {
|
69 | constructor(...args) {
|
70 | const options = args[0] || {};
|
71 | super(Object.assign({}, defaults, options));
|
72 | }
|
73 | };
|
74 | return ProbotWithDefaults;
|
75 | }
|
76 | receive(event) {
|
77 | this.log.debug({ event }, "Webhook received");
|
78 | return this.webhooks.receive(event);
|
79 | }
|
80 | async load(appFn) {
|
81 | if (Array.isArray(appFn)) {
|
82 | for (const fn of appFn) {
|
83 | await this.load(fn);
|
84 | }
|
85 | return;
|
86 | }
|
87 | return appFn(this, {});
|
88 | }
|
89 | }
|
90 | exports.Probot = Probot;
|
91 | Probot.version = version_1.VERSION;
|
92 |
|
\ | No newline at end of file |