-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: detect WIP commit messages (#32)
- Loading branch information
Showing
1 changed file
with
16 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |