Created
December 20, 2017 00:37
-
-
Save henry40408/d116f0f38102e9ab2d22cf121de81ad6 to your computer and use it in GitHub Desktop.
jiminycricket/pr-review-submit-unassign
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
// https://github.com/jiminycricket/pr-review-submit-unassign/blob/5b3bf2e64c6417919d53c4966f50d5c8bb97e91e/index.js | |
const defaultConfig = require('./lib/defaultConfig') | |
module.exports = robot => { | |
robot.on('pull_request_review.submitted', assignAfterReviewSubmitted) | |
} | |
async function assignAfterReviewSubmitted (context) { | |
const { github } = context | |
const userConfig = await context.config('pr_review_submit_unassign.yml') | |
const config = Object.assign({}, defaultConfig, userConfig) | |
const { pull_request, review } = context.payload | |
const pullRequestOwner = pull_request.user.login | |
const reviwer = review.user.login | |
// NOTE not assign pull request owner if review is submitted by owner | |
if (pullRequestOwner === reviwer) { | |
return | |
} | |
let comment = '' | |
if (config.unassignReviewer) { | |
const params = context.issue({ body: { assignees: [reviwer] } }) | |
await github.issues.removeAssigneesFromIssue(params) | |
comment += config.unassignTemplate.replace('{reviwer}', reviwer) | |
} | |
if (config.assignPullRequestOwner) { | |
const params = context.issue({ assignees: [pullRequestOwner] }) | |
await github.issues.addAssigneesToIssue(params) | |
if (config.unassignReviewer) { | |
comment += ', ' | |
} | |
comment += config.assignTemplate.replace( | |
'{pullRequestOwner}', | |
pullRequestOwner | |
) | |
} | |
if (config.leaveComment) { | |
const commentParams = context.issue({ body: comment }) | |
await github.issues.createComment(commentParams) | |
} | |
} | |
module.exports.assignAfterReviewSubmitted = assignAfterReviewSubmitted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment