forked from behaviorbot/request-info
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
57 lines (48 loc) · 1.46 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
const getConfig = require('probot-config');
const defaultConfig = {
requestInfoReplyComment:
'The maintainers of this repository require that you fill out the issue template correctly.',
requiredHeaders: [
'Prerequisites',
'Expected Behavior',
'Current Behavior',
'Possible Solution',
'Your Environment'
],
requireBugLabel: true
};
module.exports = app => {
async function receive(context) {
const { data: labels } = await context.github.issues.listLabelsOnIssue(
context.issue()
);
if (!labels.find(label => label.name === 'bug')) return;
try {
const config = await getConfig(context, 'config.yml', defaultConfig);
let invalid = false;
const { title, body } = context.payload.issue;
const lowerCaseBody = body.toLowerCase();
if (!title || !body) {
invalid = true;
}
const { requiredHeaders } = config;
for (const header of requiredHeaders) {
if (!lowerCaseBody.includes(header.toLowerCase())) {
invalid = true;
}
}
if (invalid) {
const { requestInfoReplyComment: closeComment } = config;
await context.github.issues.createComment(
context.issue({ body: closeComment })
);
await context.github.issues.edit(context.issue({ state: 'closed' }));
}
} catch (err) {
if (err.code !== 404) {
throw err;
}
}
}
app.on(['issues.opened', 'issues.edited'], receive);
};