feat(fun/clbot,ops/machines/whitby): filter tvix-dev clbot

In #tvix-dev, we want to display only CLs that relate to tvix and
related projects.

So use a pretty dumb allow-list for which CLs to display in that
channel.

Change-Id: I3ef50b64e3d7fbc27a6690be6a10f1b55c04cd6e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11658
Reviewed-by: flokli <flokli@flokli.de>
Reviewed-by: lukegb <lukegb@tvl.fyi>
Tested-by: BuildkiteCI
This commit is contained in:
Profpatsch 2024-05-13 17:54:34 +02:00
parent 1b39d5868a
commit 9559ef56e3
4 changed files with 55 additions and 9 deletions

View file

@ -41,7 +41,8 @@ var (
notifyRepo = flag.String("notify_repo", "depot", "Repo name to notify about")
notifyBranches = stringSetFlag{}
neverPing = flag.String("never_ping", "marcus", "Comma-separated terms that should never ping users")
neverPing = flag.String("never_ping", "marcus", "Comma-separated terms that should never ping users")
onlyDisplay = flag.String("only_display", "", "Comma-separated substrings of the gerrit CL Change Subject that should be shown (everything else is dropped)")
)
func init() {
@ -193,6 +194,21 @@ func nopingAll(username, message string) string {
return strings.ReplaceAll(message, username, noping(username))
}
// changeShouldBeSkipped applies the list of channels in `onlyDisplay`
// to whether we should skip displaying a CL.
func changeShouldBeSkipped(onlyDisplay string, changeSubject string) bool {
// case when we dont want to filter
if onlyDisplay == "" {
return false
}
for _, needle := range strings.Split(onlyDisplay, ",") {
if strings.Contains(changeSubject, needle) {
return false
}
}
return true
}
func patchSetURL(c gerritevents.Change, p gerritevents.PatchSet) string {
return fmt.Sprintf("https://cl.tvl.fyi/%d", c.Number)
}
@ -248,13 +264,13 @@ func main() {
var parsedMsg string
switch e := e.(type) {
case *gerritevents.PatchSetCreated:
if e.Change.Project != *notifyRepo || !notifyBranches[e.Change.Branch] || e.PatchSet.Number != 1 {
if e.Change.Project != *notifyRepo || !notifyBranches[e.Change.Branch] || e.PatchSet.Number != 1 || changeShouldBeSkipped(*onlyDisplay, e.Change.Subject) {
continue
}
user := username(e.PatchSet.Uploader)
parsedMsg = nopingAll(user, fmt.Sprintf("CL/%d proposed by %s - %s - %s", e.Change.Number, user, e.Change.Subject, patchSetURL(e.Change, e.PatchSet)))
case *gerritevents.ChangeMerged:
if e.Change.Project != *notifyRepo || !notifyBranches[e.Change.Branch] {
if e.Change.Project != *notifyRepo || !notifyBranches[e.Change.Branch] || changeShouldBeSkipped(*onlyDisplay, e.Change.Subject) {
continue
}
owner := username(e.Change.Owner)

24
fun/clbot/clbot_test.go Normal file
View file

@ -0,0 +1,24 @@
package main
import (
"testing"
)
func TestChangeShouldBeSkipped(t *testing.T) {
dontSkipAny := ""
if changeShouldBeSkipped(dontSkipAny, "mysubject") {
t.Fatal("dontSkipAny should not not be skip any")
}
showThese := "A,B"
if changeShouldBeSkipped(showThese, "A") {
t.Fatal("A should be shown")
}
if changeShouldBeSkipped(showThese, "B") {
t.Fatal("B should be shown")
}
if !changeShouldBeSkipped(showThese, "C") {
t.Fatal("C should not be shown")
}
}