-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (35 loc) · 1.17 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
const issueMatch = require('./lib/utils.js')
const defaultConfig = require('./lib/defaultConfig.js')
const issueEvents = ['issues.opened', 'issues.edited']
module.exports = app => {
app.on(issueEvents, async context => {
let config = {}
try {
const repoConfig = await context.config('issue_template.yml')
config = repoConfig ? repoConfig : defaultConfig;
} catch (e) {
config = defaultConfig;
}
const issueBody = context.payload.issue.body;
const params = {
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
number: context.payload.issue.number
};
const { match, closeComments } = issueMatch(issueBody, config.issueConfigs, config.comments);
if (!match) {
const issueComment = context.issue({ body: closeComments.join('\n') });
if (context.payload.action === 'created' || context.payload.action === 'opened') {
context.github.issues.createComment(issueComment);
}
return context.github.issues.edit({
...params,
state: 'closed'
});
}
return context.github.issues.edit({
...params,
state: 'open'
});
})
}