about summary refs log tree commit diff
path: root/fun/clbot
diff options
context:
space:
mode:
authorLuke Granger-Brown <git@lukegb.com>2020-06-24T01·39+0000
committerlukegb <lukegb@tvl.fyi>2020-06-24T01·46+0000
commitf2980dfc16360f8b56d200cbf0368f2a374061b8 (patch)
tree3291e8097a8bd5ea4fe4e621b1f9cf6fc846e80a /fun/clbot
parentb3a0a96953591f0435d6c97dd4da6d88d20b0606 (diff)
feat(clbot): allow specifying branch and repo to look at on command line r/1075
Change-Id: Ib2e37275d770a1e98a526481018514a564a4f73b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/569
Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'fun/clbot')
-rw-r--r--fun/clbot/clbot.go28
1 files changed, 26 insertions, 2 deletions
diff --git a/fun/clbot/clbot.go b/fun/clbot/clbot.go
index 37d9a222e7a1..7ab40569743a 100644
--- a/fun/clbot/clbot.go
+++ b/fun/clbot/clbot.go
@@ -35,8 +35,32 @@ var (
 	ircPassword  = flag.String("irc_pass", "", "Password to use for IRC")
 	ircSendLimit = flag.Duration("irc_send_limit", 100*time.Millisecond, "Delay between messages")
 	ircSendBurst = flag.Int("irc_send_burst", 10, "Number of messages which can be sent in a burst")
+
+	notifyRepo     = flag.String("notify_repo", "depot", "Repo name to notify about")
+	notifyBranches = stringSetFlag{}
 )
 
+func init() {
+	flag.Var(&notifyBranches, "notify_branches", "Branch names (comma-separated, or repeated flags, or both) to notify users about")
+}
+
+type stringSetFlag map[string]bool
+
+func (f stringSetFlag) String() string {
+	return fmt.Sprintf("%q", map[string]bool(f))
+}
+func (f stringSetFlag) Set(s string) error {
+	if s == "" {
+		return nil
+	}
+	for _, k := range strings.Split(s, ",") {
+		if k != "" {
+			f[k] = true
+		}
+	}
+	return nil
+}
+
 func mustFixedHostKey(f string) ssh.HostKeyCallback {
 	pk, _, _, _, err := ssh.ParseAuthorizedKey([]byte(f))
 	if err != nil {
@@ -196,12 +220,12 @@ func main() {
 			var parsedMsg string
 			switch e := e.(type) {
 			case *gerritevents.PatchSetCreated:
-				if e.Change.Project != "depot" || e.Change.Branch != "master" || e.PatchSet.Number != 1 {
+				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))
 			case *gerritevents.ChangeMerged:
-				if e.Change.Project != "depot" || e.Change.Branch != "master" {
+				if e.Change.Project != *notifyRepo || !notifyBranches[e.Change.Branch] {
 					continue
 				}
 				parsedMsg = fmt.Sprintf("CL/%d: %q submitted by %s - %s", e.Change.Number, e.Change.Subject, noping(username(e.PatchSet)), patchSetURL(e.Change, e.PatchSet))