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

View File

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