feat(clbot): allow specifying branch and repo to look at on command line

Change-Id: Ib2e37275d770a1e98a526481018514a564a4f73b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/569
Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
Luke Granger-Brown 2020-06-24 01:39:05 +00:00 committed by lukegb
parent b3a0a96953
commit f2980dfc16

View file

@ -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))