diff options
author | Vincent Ambo <mail@tazj.in> | 2021-03-27T12·05+0200 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2021-03-28T01·21+0000 |
commit | b508605084e8a50fa689f652e032d34c1e164c0b (patch) | |
tree | 5cc5d8818abec03841bee974fa15335a2dc9193e /fun | |
parent | 4a17fe59227f67d299737bf50c27137b5c7459b3 (diff) |
fix(clbot): Avoid pinging users for their own user folder CLs r/2352
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 <sternenseemann@systemli.org> Reviewed-by: glittershark <grfn@gws.fyi> Reviewed-by: lukegb <lukegb@tvl.fyi>
Diffstat (limited to 'fun')
-rw-r--r-- | fun/clbot/clbot.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/fun/clbot/clbot.go b/fun/clbot/clbot.go index a17d9a5da0bb..691f43afb9c9 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 |