From ad424a6c3f99bc3b7458a92fd250952c73f878ae Mon Sep 17 00:00:00 2001 From: zbarahal-do <59702904+zbarahal-do@users.noreply.github.com> Date: Fri, 19 Jan 2024 03:49:57 -0500 Subject: [PATCH] Check email before checking name (#13) * Check email before checking name --------- Co-authored-by: Timo Reimann --- slack.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/slack.go b/slack.go index 2121a28..39873b3 100644 --- a/slack.go +++ b/slack.go @@ -19,9 +19,16 @@ import ( type slackUsers []slackUser func (users slackUsers) findByPDUser(pdUser pagerduty.User) *slackUser { + // check email match first since it's a distinctive identifier for _, slackUser := range users { - if slackUser.email == pdUser.Email || - slackUser.realName == strings.ToLower(pdUser.Name) || + if slackUser.email == pdUser.Email { + return &slackUser + } + } + + // if we couldn't find an email match, use name. this is the second choice as name is not unique in an organization + for _, slackUser := range users { + if slackUser.realName == strings.ToLower(pdUser.Name) || slackUser.name == strings.ToLower(pdUser.Name) { return &slackUser }