forked from dcoapp/app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (30 loc) · 984 Bytes
/
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
const dco = require('./lib/dco');
const defaults = {
success: {
state: 'success',
description: 'All commits have a DCO sign-off from the author'
},
failure: {
state: 'failure',
description: 'All commits must have a DCO sign-off from the author',
target_url: 'https://developercertificate.org/'
}
};
module.exports = robot => {
robot.on('pull_request.opened', check);
robot.on('pull_request.synchronize', check);
async function check(event, context) {
const github = await robot.auth(event.payload.installation.id);
const pr = event.payload.pull_request;
const compare = await github.repos.compareCommits(context.repo({
base: pr.base.sha,
head: pr.head.sha
}));
const signedOff = compare.commits.every(dco);
const params = Object.assign({
sha: pr.head.sha,
context: 'DCO'
}, signedOff ? defaults.success : defaults.failure);
return github.repos.createStatus(context.repo(params));
}
};