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,29 +23,27 @@ 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
const reviewer = payload.requested_reviewer
const userID = getSlackIdFromGitHubId(reviewer.login)
for (let reviewer of payload.pull_request.requested_reviewers) {
const userID = getSlackIdFromGitHubId(reviewer.login)
if (!userID) {
robot.log.warn('Could not find Slack ID for GitHub user', reviewer.login)
continue
}
slackWeb.im.open(userID).then(resp => {
const dmChannelID = resp.channel.id
const msg = `New Pull Request awaiting your review: ${payload.pull_request.html_url}`
robot.log.info(`${botName} - Opened DM Channel ${dmChannelID}`)
robot.log.info(`Notifying ${userID} about review request in ${payload.pull_request.url}`)
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))
if (!userID) {
robot.log.warn('Could not find Slack ID for GitHub user', reviewer.login)
return
}
slackWeb.im.open(userID).then(resp => {
const dmChannelID = resp.channel.id
const msg = `New Pull Request awaiting your review: ${payload.pull_request.html_url}`
robot.log.info(`${botName} - Opened DM Channel ${dmChannelID}`)
robot.log.info(`Notifying ${userID} about review request in ${payload.pull_request.url}`)
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))
}