Skip to content

Commit

Permalink
feat: detect WIP commit messages (#32)
Browse files Browse the repository at this point in the history
thanks @Raul6469 & @HeeL
  • Loading branch information
Raul6469 authored and gr2m committed Feb 12, 2018
1 parent 843366e commit 2d6181b
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/handle-pull-request-change.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
module.exports = handlePullRequestChange

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

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

context.github.repos.createStatus(context.repo({
sha: context.payload.pull_request.head.sha,
sha: head.sha,
state: status,
target_url: 'https://github.com/apps/wip',
description: isWip ? 'work in progress – do not merge!' : 'ready for review',
context: 'WIP'
}))
}

async function commitsContainWIP (context) {
const commits = await context.github.pullRequests.getCommits(context.repo({
number: context.payload.pull_request.number
}))

return commits.data.map(element => element.commit.message).some(containsWIP)
}

function containsWIP (string) {
return /\b(wip|do not merge)\b/i.test(string)
}

0 comments on commit 2d6181b

Please sign in to comment.