Skip to content

Commit 2d6181b

Browse files
Raul6469gr2m
authored andcommitted
feat: detect WIP commit messages (#32)
thanks @Raul6469 & @HeeL
1 parent 843366e commit 2d6181b

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

‎lib/handle-pull-request-change.js‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
module.exports = handlePullRequestChange
22

33
async function handlePullRequestChange (robot, context) {
4-
const title = context.payload.pull_request.title
5-
const isWip = /\b(wip|do not merge)\b/i.test(title)
4+
const {title, html_url, head} = context.payload.pull_request
5+
const isWip = containsWIP(title) || await commitsContainWIP(context)
66
const status = isWip ? 'pending' : 'success'
77

8-
console.log(`Updating PR "${title}" (${context.payload.pull_request.html_url}): ${status}`)
8+
console.log('Updating PR "%s" (%s): %s', title, html_url, status)
99

1010
context.github.repos.createStatus(context.repo({
11-
sha: context.payload.pull_request.head.sha,
11+
sha: head.sha,
1212
state: status,
1313
target_url: 'https://github.com/apps/wip',
1414
description: isWip ? 'work in progress – do not merge!' : 'ready for review',
1515
context: 'WIP'
1616
}))
1717
}
18+
19+
async function commitsContainWIP (context) {
20+
const commits = await context.github.pullRequests.getCommits(context.repo({
21+
number: context.payload.pull_request.number
22+
}))
23+
24+
return commits.data.map(element => element.commit.message).some(containsWIP)
25+
}
26+
27+
function containsWIP (string) {
28+
return /\b(wip|do not merge)\b/i.test(string)
29+
}

0 commit comments

Comments
 (0)