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:
parent
655682e23e
commit
66f45c2bf6
3 changed files with 3 additions and 44 deletions
|
|
@ -40,8 +40,7 @@ var (
|
||||||
notifyRepo = flag.String("notify_repo", "depot", "Repo name to notify about")
|
notifyRepo = flag.String("notify_repo", "depot", "Repo name to notify about")
|
||||||
notifyBranches = stringSetFlag{}
|
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() {
|
func init() {
|
||||||
|
|
@ -193,21 +192,6 @@ func nopingAll(username, message string) string {
|
||||||
return strings.ReplaceAll(message, username, noping(username))
|
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 don’t 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 {
|
func patchSetURL(c gerritevents.Change, p gerritevents.PatchSet) string {
|
||||||
return fmt.Sprintf("https://cl.snix.dev/%d", c.Number)
|
return fmt.Sprintf("https://cl.snix.dev/%d", c.Number)
|
||||||
}
|
}
|
||||||
|
|
@ -263,13 +247,13 @@ func main() {
|
||||||
var parsedMsg string
|
var parsedMsg string
|
||||||
switch e := e.(type) {
|
switch e := e.(type) {
|
||||||
case *gerritevents.PatchSetCreated:
|
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
|
continue
|
||||||
}
|
}
|
||||||
user := username(e.PatchSet.Uploader)
|
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)))
|
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:
|
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
|
continue
|
||||||
}
|
}
|
||||||
owner := username(e.Change.Owner)
|
owner := username(e.Change.Owner)
|
||||||
|
|
|
||||||
|
|
@ -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")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -10,7 +10,6 @@ pkgs.buildGoModule {
|
||||||
root = ./.;
|
root = ./.;
|
||||||
fileset = lib.fileset.unions [
|
fileset = lib.fileset.unions [
|
||||||
./clbot.go
|
./clbot.go
|
||||||
./clbot_test.go
|
|
||||||
./go.mod
|
./go.mod
|
||||||
./go.sum
|
./go.sum
|
||||||
./backoffutil
|
./backoffutil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue