-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.js
48 lines (39 loc) · 1.26 KB
/
index.js
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
const debug = require("debug")("probot:trafico");
const Raven = require("raven");
const Trafico = require("./lib/trafico");
Raven.config(
process.env.NODE_ENV === "production" &&
"https://[email protected]/1222067"
).install();
function probotPlugin(robot) {
const events = [
"pull_request.opened",
"pull_request.closed",
"pull_request.edited",
"pull_request.synchronize",
"pull_request.reopened",
"pull_request.review_requested",
"pull_request.review_request_removed",
"pull_request_review.edited",
"pull_request_review.submitted",
"pull_request_review.dismissed"
];
robot.on(events, runTrafico);
}
async function runTrafico(context) {
const trafico = forRepository(context);
const pullRequest = getPullRequest(context);
const config = await getConfig(context);
trafico.runTrafico(context, pullRequest, config);
}
function forRepository(context) {
const config = Object.assign({}, context.repo({ logger: debug }));
return new Trafico(context.github, config);
}
function getPullRequest(context) {
return context.payload.pull_request || context.payload.review.pull_request;
}
async function getConfig(context) {
return await context.config("trafico.yml");
}
module.exports = probotPlugin;