-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
48 lines (41 loc) · 1.54 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
require('dotenv').config()
const createScheduler = require('probot-scheduler')
const Unassign = require('./lib/unassign')
module.exports = async robot => {
// Visit all repositories to mark and sweep no-response issues
const scheduler = createScheduler(robot, {
delay: !process.env.DISABLE_DELAY,
interval: 60 * (Number(process.env.CHECKING_INTERVAL) || 60) * 1000
});
// Unmark no response issues if a user comments
const events = [
'issue_comment',
'issues',
]
robot.on(events, unmark)
robot.on('schedule.repository', markAndSweep)
async function unmark (context) {
if (!context.isBot) {
const unassign = new Unassign(context.github, context.repo({logger: robot.log}))
let issue = context.payload.issue || context.payload.pull_request
const type = context.payload.issue ? 'issues' : 'pulls'
// Some payloads don't include labels
if (!issue.labels) {
try {
issue = (await context.github.issues.get(context.issue())).data
} catch (error) {
context.log('Issue not found')
}
}
const noResponseLabelAdded = context.payload.action === 'labeled' &&
context.payload.label.name === 'issue assignee: no-response'
if (unassign.hasNoResponseLabel(type, issue) && issue.state !== 'closed' && !noResponseLabelAdded) {
unassign.unmark(type, issue)
}
}
}
async function markAndSweep (context) {
const unassign = new Unassign(context.github, context.repo({logger: robot.log}))
await unassign.markAndSweep('issues')
}
}