-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
29 lines (21 loc) · 818 Bytes
/
index.ts
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
import { Application, Context } from 'probot' // eslint-disable-line no-unused-vars
import { serverless } from '@probot/serverless-gcf'
const matcher = /^{{whendone}}([\s\S]*?){{\/whendone}}$/m
const probot = serverless(whenDone)
export { probot, whenDone }
function whenDone (app: Application) {
app.on(['issues.closed', 'pull_request.closed'], async (context: Context) => {
const { issue, pull_request: pr } = context.payload
if (pr && !pr.merged) {
return
}
const matches = (issue || pr).body.match(matcher)
if (matches && matches[1]) {
const newComment = context.issue({ body: clean(matches[1]) })
await context.github.issues.createComment(newComment)
}
})
}
function clean (rawData: string): string {
return rawData.trim().replace(/`([/@][^`]+)`/g, '$1')
}