refactor(fun/clbot): drop changeShouldBeSkipped functionality

Change-Id: Id0b05b070dfdb8099c6c32761295dcb17db1aea4
Reviewed-on: https://cl.snix.dev/c/snix/+/30224
Tested-by: besadii
Autosubmit: Florian Klink <flokli@flokli.de>
Reviewed-by: Ilan Joselevich <personal@ilanjoselevich.com>
This commit is contained in:
Florian Klink 2025-03-21 00:43:47 +00:00 committed by clbot
parent 655682e23e
commit 66f45c2bf6
3 changed files with 3 additions and 44 deletions

View file

@ -41,7 +41,6 @@ var (
notifyBranches = stringSetFlag{}
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,21 +192,6 @@ 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.snix.dev/%d", c.Number)
}
@ -263,13 +247,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 || changeShouldBeSkipped(*onlyDisplay, e.Change.Subject) {
if e.Change.Project != *notifyRepo || !notifyBranches[e.Change.Branch] || e.PatchSet.Number != 1 {
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] || changeShouldBeSkipped(*onlyDisplay, e.Change.Subject) {
if e.Change.Project != *notifyRepo || !notifyBranches[e.Change.Branch] {
continue
}
owner := username(e.Change.Owner)

View file

@ -1,24 +0,0 @@
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")
}
}

View file

@ -10,7 +10,6 @@ pkgs.buildGoModule {
root = ./.;
fileset = lib.fileset.unions [
./clbot.go
./clbot_test.go
./go.mod
./go.sum
./backoffutil