Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (43 loc) · 1.63 KB
/
Copy pathindex.js
File metadata and controls
50 lines (43 loc) · 1.63 KB
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
/**
* This is the main entrypoint to the Probot app
* @param {import('probot').Probot} app
*/
export default (app) => {
app.on([
'pull_request.opened',
'pull_request.edited',
'pull_request.labeled',
'pull_request.unlabeled',
'pull_request.synchronize'
], handlePullRequestChange)
async function handlePullRequestChange (context) {
const { pull_request: pr } = context.payload
const hasKreditsLabel = !!pr.labels.find(l => l.name.match(/^kredits-\d$/))
try { await setStatus(hasKreditsLabel, context) }
catch (e) { console.log(e) }
}
function setStatus (hasKreditsLabel, context) {
const pullRequest = context.payload.pull_request
const checkOptions = {
name: 'Kredits',
head_sha: pullRequest.head.sha,
status: 'in_progress',
started_at: (new Date()).toISOString(),
output: {
title: 'Kredits label missing',
summary: 'No kredits label assigned. Please add one for this check to pass.',
text: 'This project rewards contributions with Kosmos Kredits. In order to determine the amount, the bot looks for a label of `kredits-1` (small contribution), `kredits-2` (medium-size contribution), or `kredits-3` (large contribution).'
}
}
if (hasKreditsLabel) {
checkOptions.status = 'completed'
checkOptions.conclusion = 'success'
checkOptions.completed_at = new Date()
checkOptions.output.title = 'Kredits label assigned'
checkOptions.output.summary = ''
}
return context.octokit.rest.checks.create(context.repo(checkOptions))
}
// For more information on building apps:
// https://probot.github.io/docs/
}