-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
58 lines (52 loc) · 1.58 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
import { Application, Context } from "probot";
import { ConfigManager } from "probot-config-manager";
import { handle } from "./handler";
import { IConfig, schema } from "./models";
module.exports = async (app: Application) => {
const events = [
"issues.opened",
"issues.reopened",
"issues.labeled",
"issues.unlabeled",
"pull_request.opened",
"pull_request.reopened",
"pull_request.labeled",
"pull_request.unlabeled",
];
const configManager = new ConfigManager<IConfig>("relabel.yml", {}, schema);
app.log.info("probot-require-label loaded");
app.on(events, async (context: Context) => {
const inumber = context.issue().number;
const repo = context.issue().repo;
const owner = context.issue().owner;
const logger = context.log.child({
owner: owner,
repo: repo,
issue: inumber,
app: "probot-require-label",
});
logger.debug("Getting Config");
const config = await configManager.getConfig(context).catch((err) => {
logger.error(err);
return {} as IConfig;
});
let eventType = config.issues;
if ("pull_request" === context.event) {
eventType = config.pulls;
}
if (!eventType) {
eventType = config.requiredLabels;
}
if (eventType) {
logger.debug("Config exists");
logger.debug(config);
await handle(context, eventType!, 30000).catch((err) => {
logger.warn(err);
});
logger.debug("Handled");
}
});
app.on("*", async (context) => {
context.log.debug({ event: context.event, action: context.payload.action });
});
};