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.Application = void 0;
|
7 | const express_1 = require("express");
|
8 | const lru_cache_1 = __importDefault(require("lru-cache"));
|
9 | const deprecation_1 = require("deprecation");
|
10 | const probot_octokit_1 = require("./octokit/probot-octokit");
|
11 | const get_log_1 = require("./helpers/get-log");
|
12 | const get_probot_octokit_with_defaults_1 = require("./octokit/get-probot-octokit-with-defaults");
|
13 | const webhook_event_check_1 = require("./helpers/webhook-event-check");
|
14 | const alias_log_1 = require("./helpers/alias-log");
|
15 | const get_webhooks_1 = require("./octokit/get-webhooks");
|
16 | const load_1 = require("./load");
|
17 | const get_router_1 = require("./get-router");
|
18 | const auth_1 = require("./auth");
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | class Application {
|
25 | constructor(options) {
|
26 | this.log = alias_log_1.aliasLog(options.log || get_log_1.getLog({ level: process.env.LOG_LEVEL }));
|
27 | this.log.warn(`[probot] "import { Application } from 'probot'" is deprecated. Use "import { Probot } from 'probot'" instead, the APIs are the same.`);
|
28 | const cache = options.cache ||
|
29 | new lru_cache_1.default({
|
30 |
|
31 | max: 15000,
|
32 |
|
33 | maxAge: 1000 * 60 * 59,
|
34 | });
|
35 | const Octokit = get_probot_octokit_with_defaults_1.getProbotOctokitWithDefaults({
|
36 | githubToken: options.githubToken,
|
37 | Octokit: options.Octokit || probot_octokit_1.ProbotOctokit,
|
38 | appId: options.id,
|
39 | privateKey: options.privateKey,
|
40 | cache,
|
41 | log: this.log,
|
42 | redisConfig: options.redisConfig,
|
43 | throttleOptions: options.throttleOptions,
|
44 | });
|
45 | if (options.throttleOptions) {
|
46 | this.log.warn(`[probot] "new Application({ throttleOptions })" is deprecated. Use "new Application({Octokit: ProbotOctokit.defaults({ throttle }) })" instead`);
|
47 | }
|
48 | this.state = {
|
49 | cache,
|
50 | githubToken: options.githubToken,
|
51 | log: this.log,
|
52 | Octokit,
|
53 | octokit: options.octokit || new Octokit(),
|
54 | webhooks: {
|
55 | path: options.webhookPath,
|
56 | secret: options.secret,
|
57 | },
|
58 | };
|
59 | this.webhooks = options.webhooks || get_webhooks_1.getWebhooks(this.state);
|
60 | this.on = (eventNameOrNames, callback) => {
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | webhook_event_check_1.webhookEventCheck(this.state, eventNameOrNames);
|
66 | if (eventNameOrNames === "*") {
|
67 |
|
68 | return this.webhooks.onAny(callback);
|
69 | }
|
70 | return this.webhooks.on(eventNameOrNames, callback);
|
71 | };
|
72 | this.receive = this.webhooks.receive;
|
73 | const router = options.router || express_1.Router();
|
74 |
|
75 | this.load = load_1.load.bind(null, this, router);
|
76 | this.auth = auth_1.auth.bind(null, this.state);
|
77 | this.internalRouter = router;
|
78 | }
|
79 | |
80 |
|
81 |
|
82 | get router() {
|
83 | this.log.warn(new deprecation_1.Deprecation(`[probot] "app.router" is deprecated, use "getRouter()" from the app function instead: "({ app, getRouter }) => { ... }"`));
|
84 | return this.internalRouter;
|
85 | }
|
86 | |
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | route(path) {
|
110 | this.log.warn(new deprecation_1.Deprecation(`[probot] "app.route()" is deprecated, use the "getRouter()" argument from the app function instead: "({ app, getRouter }) => { ... }"`));
|
111 | return get_router_1.getRouter(this.internalRouter, path);
|
112 | }
|
113 | }
|
114 | exports.Application = Application;
|
115 |
|
\ | No newline at end of file |