-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathfilter.js
40 lines (36 loc) · 1.35 KB
/
filter.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
"use strict";
// Filter functions for GitHub API responses. Returns true if the entity passes
// the filter, like a `Array.prototype.filter` callback. The `log` callback is
// called with any console messages that should be logged.
function filterEvent(body, log) {
if (!body) {
log("Ignoring event: no body");
return false;
}
if (!body.pull_request) {
log("Ignoring event: not a pull request");
return false;
}
if (body.sender && body.sender.login == "wpt-pr-bot") {
log("Ignoring event: sender is wpt-pr-bot");
return false;
}
return true;
}
function filterPullRequest(pull_request, log) {
if (pull_request.state == "closed") {
log(`Ignoring #${pull_request.number}: pull request is closed`);
return false;
}
// Note: the `draft` boolean is a preview API which we don't enable:
// https://developer.github.com/changes/2019-02-14-draft-pull-requests/
// The `mergeable_state` is undocumented but has been observed:
// https://github.com/web-platform-tests/wpt-pr-bot/issues/69#issuecomment-546273083
if (pull_request.draft || pull_request.mergeable_state === "draft") {
log(`Ignoring #${pull_request.number}: pull request is a draft`);
return false;
}
return true;
}
exports.event = filterEvent;
exports.pullRequest = filterPullRequest;