-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
59 lines (49 loc) · 1.82 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
const { listCompleted, listsFromMarkdown } = require('./lib/markdown-checks')
module.exports = (app) => {
// watch for pull requests & their changes
app.on(['pull_request.opened', 'pull_request.edited', 'pull_request.synchronize'], async context => {
const startTime = (new Date()).toISOString()
// lookup the pr body/description
const pr = context.payload.pull_request
const lists = listsFromMarkdown(pr.body)
// needs at least 1 checklist
const hasLists = lists.length > 0
const hasListCheck = {
name: 'pr-review-guide-created',
head_sha: pr.head.sha,
started_at: startTime,
status: 'completed',
conclusion: hasLists ? 'success' : 'failure',
output: {
title: 'PR Review Guide',
summary: 'PRs should have a guide for reviewers',
text: 'Please make a thoughtful review guide for your reviewer'
}
}
context.github.checks.create(context.repo(hasListCheck))
if (!hasLists) { return }
// check if all checklists are completed
const guideComplete = lists.every(listCompleted)
const guideCheck = {
name: 'pr-review-guide-completed',
head_sha: pr.head.sha,
started_at: startTime,
status: 'in_progress',
output: {
title: 'PR Review in progress',
summary: 'The PR Guide still needs to be completed',
text: 'Please check off the relevant items in the PR Guide'
}
}
// all finished?
if (guideComplete) {
guideCheck.status = 'completed'
guideCheck.conclusion = 'success'
guideCheck.completed_at = (new Date()).toISOString()
guideCheck.output.title = 'PR Review complete'
guideCheck.output.summary = 'The PR Guide has been completed'
};
// send check back to GitHub
return context.github.checks.create(context.repo(guideCheck))
})
}