Skip to content

Commit

Permalink
internal/gaby: -requireapproval takes packages
Browse files Browse the repository at this point in the history
Change the -requireapproval flag from a bool to a string,
a list of packages that require approval.

Change-Id: I64191b7adb47a537d5cc6f6edf2ae7be7f4c7287
Reviewed-on: https://go-review.googlesource.com/c/oscar/+/637095
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
  • Loading branch information
jba committed Dec 17, 2024
1 parent 8c06601 commit 7375c1a
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions internal/gaby/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"net/http"
"net/url"
"os"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -55,7 +56,7 @@ type gabyFlags struct {
enablechanges bool
level string
overlay string
requireApproval bool
requireApproval string
}

var flags gabyFlags
Expand All @@ -68,7 +69,7 @@ func init() {
flag.BoolVar(&flags.enablechanges, "enablechanges", false, "allow changes to GitHub")
flag.StringVar(&flags.level, "level", "info", "initial log level")
flag.StringVar(&flags.overlay, "overlay", "", "spec for overlay to DB; see internal/dbspec for syntax")
flag.BoolVar(&flags.requireApproval, "requireapproval", false, "logged actions require approval")
flag.StringVar(&flags.requireApproval, "requireapproval", "", "comma-separated list of packages whose actions require approval")
}

// Gaby holds the state for gaby's execution.
Expand Down Expand Up @@ -123,6 +124,11 @@ func main() {
googleGroups: []string{"golang-nuts"},
}

requireApprovalPkgs, err := parseRequireApproval(flags.requireApproval)
if err != nil {
log.Fatal(err)
}

shutdown := g.initGCP() // sets up g.db, g.vector, g.secret, ...
defer shutdown()

Expand Down Expand Up @@ -182,7 +188,7 @@ func main() {
cf.AutoLink(`\bCL ([0-9]+)\b`, "https://go.dev/cl/$1")
cf.ReplaceURL(`\Qhttps://go-review.git.corp.google.com/\E`, "https://go-review.googlesource.com/")
cf.EnableEdits()
if flags.requireApproval {
if slices.Contains(requireApprovalPkgs, "commentfix") {
cf.RequireApproval()
}
g.commentFixer = cf
Expand All @@ -196,7 +202,7 @@ func main() {
rp.SkipTitlePrefix("x/tools/gopls: release version v")
rp.SkipTitleSuffix(" backport]")
rp.EnablePosts()
if flags.requireApproval {
if slices.Contains(validApprovalPkgs, "related") {
rp.RequireApproval()
}
g.relatedPoster = rp
Expand Down Expand Up @@ -228,6 +234,21 @@ func main() {
select {}
}

var validApprovalPkgs = []string{"commentfix", "related", "rules"}

// parseRequireApproval parses a comma-separated list of package names,
// checking that the packages are valid.
func parseRequireApproval(s string) ([]string, error) {
pkgs := strings.Split(s, ",")
for _, p := range pkgs {
if !slices.Contains(validApprovalPkgs, p) {
return nil, fmt.Errorf("invalid arg %q to -requireapproval: valid values are: %s",
p, strings.Join(validApprovalPkgs, ", "))
}
}
return pkgs, nil
}

// initLocal initializes a local Gaby instance.
// No longer used, but here for experimentation.
func (g *Gaby) initLocal() {
Expand Down

0 comments on commit 7375c1a

Please sign in to comment.