This repository has been archived by the owner on May 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 212
/
index.js
66 lines (53 loc) · 1.85 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
58
59
60
61
62
63
64
65
66
require('newrelic')
const getConfig = require('probot-config')
const createScheduler = require('probot-scheduler')
const Stale = require('./lib/stale')
module.exports = async app => {
// Visit all repositories to mark and sweep stale issues
const scheduler = createScheduler(app)
// Unmark stale issues if a user comments
const events = [
'issue_comment',
'issues',
'pull_request',
'pull_request_review',
'pull_request_review_comment'
]
app.on(events, unmark)
app.on('schedule.repository', markAndSweep)
async function unmark (context) {
if (!context.isBot) {
const stale = await forRepository(context)
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 staleLabelAdded = context.payload.action === 'labeled' &&
context.payload.label.name === stale.config.staleLabel
if (stale.hasStaleLabel(type, issue) && issue.state !== 'closed' && !staleLabelAdded) {
await stale.unmarkIssue(type, issue)
}
}
}
async function markAndSweep (context) {
const stale = await forRepository(context)
await stale.markAndSweep('pulls')
await stale.markAndSweep('issues')
}
async function forRepository (context) {
let config = await getConfig(context, 'stale.yml')
if (!config) {
scheduler.stop(context.payload.repository)
// Don't actually perform for repository without a config
config = { perform: false }
}
config = Object.assign(config, context.repo({ logger: app.log }))
return new Stale(context.github, config)
}
}