-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
57 lines (46 loc) · 2.01 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 fs = require('fs');
const createScheduler = require('probot-scheduler');
const Freeze = require('./lib/freeze');
/* Configuration Variables */
module.exports = robot => {
robot.on('integration_installation.added', installationEvent);
robot.on('issue_comment', handleFreeze);
createScheduler(robot);
robot.on('schedule.repository', handleThaw);
async function installationEvent(context) {
const config = await context.config('probot-snooze.yml', JSON.parse(fs.readFileSync('./etc/defaults.json', 'utf8')));
context.github.issues.getLabel(context.repositories_added[0]({
name: config.labelName}).catch(() => {
return context.github.issues.createLabel(context.repositories_added[0]({
name: config.labelName,
color: config.labelColor
}));
}));
}
async function handleFreeze(context) {
const config = await context.config('probot-snooze.yml', JSON.parse(fs.readFileSync('./etc/defaults.json', 'utf8')));
const freeze = new Freeze(context.github, config);
const comment = context.payload.comment;
freeze.config.perform = true;
if (freeze.config.perform && !context.isBot && freeze.freezable(comment)) {
freeze.freeze(
context,
freeze.propsHelper(comment.user.login, comment.body)
);
}
}
async function handleThaw(context) {
const config = await context.config('probot-snooze.yml', JSON.parse(fs.readFileSync('./etc/defaults.json', 'utf8')));
const freeze = new Freeze(context.github, config);
const {owner, repo} = context.repo();
const q = `label:"${freeze.config.labelName}" repo:${owner}/${repo}`;
const resp = await context.github.search.issues({q});
await Promise.all(resp.data.items.map(issue => {
// Issue objects from the API don't include owner/repo params, so
// setting them here with `context.repo` so we don't have to worry
// about it later. :/
return freeze.checkUnfreeze(context, context.repo(issue));
}));
robot.log('scheduled thaw run complete');
}
};