This repository has been archived by the owner on May 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
72 lines (62 loc) 路 2.27 KB
/
index.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import "reflect-metadata";
import { Context, Probot, ProbotOctokit } from "probot";
import Container from "typedi";
import { createConnection, useContainer } from "typeorm";
import { IPullServiceToken } from "./services/PullService";
import { ILoggerToken } from "./common/token";
import {
handleAppInstallOnAccountEvent,
handleAppInstallOnRepoEvent,
handleAppStartUpEvent,
} from "./events/app";
export = async (app: Probot) => {
// Init container.
useContainer(Container);
Container.set(ILoggerToken, app.log);
// TODO: use the github client authed by installation id.
// Init Github client.
// Notice: This github client uses a TOKEN as the bot github account for access, in this case, we do not need to
// authorize for each installation through the Github APP, but this will also bring some restrictions.
const github = new ProbotOctokit({
auth: {
token: process.env.GITHUB_ACCESS_TOKEN,
},
log: app.log,
});
// Connect database.
createConnection()
.then(() => {
// Handle application start up event.
// Notice: Full sync at startup will not block the subsequent execution of
// WebHook-based incremental sync, and the two are executed concurrently.
handleAppStartUpEvent(app, github, Container.get(IPullServiceToken)).then(
null
);
// Establish WebHook listen.
// You can learn more about webhook through the following documents:
// https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events
app.on("ping", async (context: Context) => {
context.log.info("pong");
});
app.on("installation.created", async (context: Context) => {
await handleAppInstallOnAccountEvent(
context,
Container.get(IPullServiceToken)
);
});
app.on("installation_repositories.added", async (context: Context) => {
await handleAppInstallOnRepoEvent(
context,
Container.get(IPullServiceToken)
);
});
})
.catch((err) => {
console.log(err);
app.log.error("Failed to connect database", err);
});
// For more information on building apps:
// https://probot.github.io/docs/
// To get your app running against GitHub, see:
// https://probot.github.io/docs/development/
};