Skip to content

Instantly share code, notes, and snippets.

@henry40408
Created December 20, 2017 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henry40408/d116f0f38102e9ab2d22cf121de81ad6 to your computer and use it in GitHub Desktop.
Save henry40408/d116f0f38102e9ab2d22cf121de81ad6 to your computer and use it in GitHub Desktop.
jiminycricket/pr-review-submit-unassign
// 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