forked from dcalhoun/github-to-clubhouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.js
34 lines (32 loc) · 975 Bytes
/
github.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
const ignoredUser = sender =>
sender && !process.env.GITHUB_USERS.split(',').includes(sender.login);
const getIdFromString = name => {
const match = RegExp(/\/ch(\d+)\//, 'g').exec(name);
return match !== null ? match[1] : '';
};
exports.parseRequest = (event, body = {}) => {
switch (true) {
case ignoredUser(body.sender):
return {};
case event === 'create' && body.ref_type === 'branch':
return {
event: 'branch',
id: getIdFromString(body.ref),
};
case event === 'pull_request' && body.action === 'opened':
return {
event: 'pullRequestOpened',
id: getIdFromString(body.pull_request.head.ref),
};
case event === 'pull_request' &&
body.action === 'closed' &&
body.pull_request &&
body.pull_request.merged === true:
return {
event: 'pullRequestMerged',
id: getIdFromString(body.pull_request.head.ref),
};
default:
return {};
}
};