From b508605084e8a50fa689f652e032d34c1e164c0b Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 27 Mar 2021 14:05:47 +0200 Subject: fix(clbot): Avoid pinging users for their own user folder CLs Instead of only "nopinging" the username in the templated message, replace all instances of the CL owner's name with one that does not (tries to not) highlight them. This way, CLs sent to another user's folder will still highlight them. Change-Id: I9a3d8563ab32befc1a1b1412851026343c170dd3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2688 Tested-by: BuildkiteCI Reviewed-by: sterni Reviewed-by: glittershark Reviewed-by: lukegb --- fun/clbot/clbot.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'fun') diff --git a/fun/clbot/clbot.go b/fun/clbot/clbot.go index a17d9a5da0..691f43afb9 100644 --- a/fun/clbot/clbot.go +++ b/fun/clbot/clbot.go @@ -165,6 +165,14 @@ func noping(user string) string { return string(un[0:1]) + zeroWidthSpace + string(un[1:]) } +// Apply noping to each instance of the username in the supplied +// message. With this users will not be pinged for their own CLs, but +// they will be notified if someone else writes a CL that includes +// their username. +func nopingAll(username, message string) string { + return strings.ReplaceAll(message, username, noping(username)) +} + func patchSetURL(c gerritevents.Change, p gerritevents.PatchSet) string { return fmt.Sprintf("https://cl.tvl.fyi/%d", c.Number) } @@ -223,12 +231,14 @@ func main() { if e.Change.Project != *notifyRepo || !notifyBranches[e.Change.Branch] || e.PatchSet.Number != 1 { continue } - parsedMsg = fmt.Sprintf("CL/%d: %q proposed by %s - %s", e.Change.Number, e.Change.Subject, noping(username(e.PatchSet)), patchSetURL(e.Change, e.PatchSet)) + user := username(e.PatchSet) + parsedMsg = nopingAll(user, fmt.Sprintf("CL/%d: %q proposed by %s - %s", e.Change.Number, e.Change.Subject, user, patchSetURL(e.Change, e.PatchSet))) case *gerritevents.ChangeMerged: if e.Change.Project != *notifyRepo || !notifyBranches[e.Change.Branch] { continue } - parsedMsg = fmt.Sprintf("CL/%d: %q applied by %s - %s", e.Change.Number, e.Change.Subject, noping(username(e.PatchSet)), patchSetURL(e.Change, e.PatchSet)) + user := username(e.PatchSet) + parsedMsg = nopingAll(user, fmt.Sprintf("CL/%d: %q applied by %s - %s", e.Change.Number, e.Change.Subject, user, patchSetURL(e.Change, e.PatchSet))) } if parsedMsg != "" { sendMsgChan <- parsedMsg -- cgit 1.4.1