forked from renovatebot/renovate-approve-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (71 loc) · 2.07 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const APPROVE = "APPROVE";
const MANUAL_MERGE_MESSAGE = "merge this manually";
const RENOVATE_BOT = process.env.RENOVATE_BOT_USER || "renovate[bot]";
const RENOVATE_APPROVE_BOT = process.env.RENOVATE_APPROVE_BOT_USER || "renovate-approve[bot]";
module.exports = app => {
app.log("App is loaded");
function isRenovate(context) {
try {
return context.payload.sender.login === RENOVATE_BOT;
} catch (err) {
context.log(context.payload);
context.log(err);
return false;
}
}
function isAutomerging(context) {
try {
return !context.payload.pull_request.body.includes(MANUAL_MERGE_MESSAGE);
} catch (err) {
context.log(context.payload);
context.log(err);
return false;
}
}
function isRenovateApprover(context) {
try {
return context.payload.review.user.login === RENOVATE_APPROVE_BOT;
} catch (err) {
context.log(err);
return false;
}
}
function isRenovateUser(context) {
try {
return context.payload.pull_request.user.login === RENOVATE_BOT;
} catch (err) {
context.log(context.payload);
context.log(err);
return false;
}
}
function approvePr(context) {
try {
const params = context.issue({ event: APPROVE });
return context.github.pulls.createReview(params);
} catch (err) {
context.log(err);
context.log(context.payload);
}
}
app.on("pull_request.opened", async context => {
context.log("Received PR open event");
if (isRenovate(context) && isAutomerging(context)) {
context.log("Approving new PR");
return approvePr(context);
}
});
app.on("pull_request_review.dismissed", async context => {
context.log("Received PR review dismiss event");
context.log(context.payload);
if (
isRenovate(context) &&
isAutomerging(context) &&
isRenovateApprover(context) &&
isRenovateUser(context)
) {
context.log("Re-approving dismissed approval");
return approvePr(context);
}
});
};