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:
parent
b3a0a96953
commit
f2980dfc16
1 changed files with 26 additions and 2 deletions
|
@ -35,8 +35,32 @@ var (
|
||||||
ircPassword = flag.String("irc_pass", "", "Password to use for IRC")
|
ircPassword = flag.String("irc_pass", "", "Password to use for IRC")
|
||||||
ircSendLimit = flag.Duration("irc_send_limit", 100*time.Millisecond, "Delay between messages")
|
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")
|
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(¬ifyBranches, "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 {
|
func mustFixedHostKey(f string) ssh.HostKeyCallback {
|
||||||
pk, _, _, _, err := ssh.ParseAuthorizedKey([]byte(f))
|
pk, _, _, _, err := ssh.ParseAuthorizedKey([]byte(f))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -196,12 +220,12 @@ 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 != "depot" || e.Change.Branch != "master" || e.PatchSet.Number != 1 {
|
if e.Change.Project != *notifyRepo || !notifyBranches[e.Change.Branch] || e.PatchSet.Number != 1 {
|
||||||
continue
|
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))
|
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:
|
case *gerritevents.ChangeMerged:
|
||||||
if e.Change.Project != "depot" || e.Change.Branch != "master" {
|
if e.Change.Project != *notifyRepo || !notifyBranches[e.Change.Branch] {
|
||||||
continue
|
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))
|
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))
|
||||||
|
|
Loading…
Reference in a new issue