Fix repeated review Slack notifications

This commit is contained in:
Pedro Pombeiro 2018-02-13 19:22:29 +01:00
parent 837c7a27eb
commit da5667090c
No known key found for this signature in database
GPG Key ID: A65DEB11E4BBC647
1 changed files with 17 additions and 19 deletions

View File

@ -23,19 +23,18 @@ function registerForNewReviewRequests (robot, getSlackIdFromGitHubId) {
// Make sure we don't listen to our own messages
if (context.isBot) return null
await notifyReviewers(context, robot, getSlackIdFromGitHubId)
await notifyReviewer(context, robot, getSlackIdFromGitHubId)
})
}
async function notifyReviewers (context, robot, getSlackIdFromGitHubId) {
async function notifyReviewer (context, robot, getSlackIdFromGitHubId) {
const { payload } = context
for (let reviewer of payload.pull_request.requested_reviewers) {
const reviewer = payload.requested_reviewer
const userID = getSlackIdFromGitHubId(reviewer.login)
if (!userID) {
robot.log.warn('Could not find Slack ID for GitHub user', reviewer.login)
continue
return
}
slackWeb.im.open(userID).then(resp => {
@ -48,4 +47,3 @@ async function notifyReviewers (context, robot, getSlackIdFromGitHubId) {
slackWeb.chat.postMessage(dmChannelID, msg, {unfurl_links: true, as_user: slackHelper.BotUserName})
}).catch(error => robot.log.error('Could not open DM channel for review request notification', error))
}
}