forked from behaviorbot/first-pr-merge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
24 lines (22 loc) · 845 Bytes
/
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
module.exports = app => {
app.on('pull_request.closed', async context => {
if (context.payload.pull_request.merged) {
const creator = context.payload.pull_request.user.login
const { owner, repo } = context.repo()
const res = await context.github.search.issues({ q: `is:pr is:merged author:${creator} repo:${owner}/${repo}` })
const mergedPRs = res.data.items.filter(pr => pr.number !== context.payload.pull_request.number)
if (mergedPRs.length === 0) {
try {
const config = await context.config('config.yml')
if (config.firstPRMergeComment) {
context.github.issues.createComment(context.issue({ body: config.firstPRMergeComment }))
}
} catch (err) {
if (err.code !== 404) {
throw err
}
}
}
}
})
}