From 52593c185b34417686a280f7f59c1f88782851e6 Mon Sep 17 00:00:00 2001 From: Zach Barahal Date: Tue, 9 Jan 2024 15:07:14 -0800 Subject: [PATCH 1/2] Check email before checking name --- slack.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/slack.go b/slack.go index 2121a28..31349c9 100644 --- a/slack.go +++ b/slack.go @@ -19,9 +19,17 @@ 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 } From 932c9e52a05f1832738d23fcbf7bbddf55d2a291 Mon Sep 17 00:00:00 2001 From: Timo Reimann Date: Fri, 12 Jan 2024 08:13:32 +0100 Subject: [PATCH 2/2] Apply gofmt and format comments --- slack.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/slack.go b/slack.go index 31349c9..39873b3 100644 --- a/slack.go +++ b/slack.go @@ -21,15 +21,14 @@ 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 { + 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) || + if slackUser.realName == strings.ToLower(pdUser.Name) || slackUser.name == strings.ToLower(pdUser.Name) { return &slackUser }