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 }