Skip to content

Commit 14561cc

Browse files
committed
Add PRR reviewer as a query option
1 parent 5836d60 commit 14561cc

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

cmd/kepctl/query.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func buildQueryCommand(k *kepctl.Client) *cobra.Command {
4141
f.StringSliceVar(&opts.SIG, "sig", nil, "SIG")
4242
f.StringSliceVar(&opts.Status, "status", nil, "Status")
4343
f.StringSliceVar(&opts.Stage, "stage", nil, "Stage")
44+
f.StringSliceVar(&opts.PRRApprover, "prr", nil, "Prod Readiness Approver")
4445
f.BoolVar(&opts.IncludePRs, "include-prs", false, "Include PRs in the results")
4546

4647
addRepoPathFlag(f, &opts.CommonArgs)

pkg/kepctl/query.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ import (
2828

2929
type QueryOpts struct {
3030
CommonArgs
31-
SIG []string
32-
Status []string
33-
Stage []string
34-
IncludePRs bool
31+
SIG []string
32+
Status []string
33+
Stage []string
34+
PRRApprover []string
35+
IncludePRs bool
3536
}
3637

3738
// Validate checks the args and cleans them up if needed
@@ -94,6 +95,7 @@ func (c *Client) Query(opts QueryOpts) error {
9495
// filter the KEPs by criteria
9596
allowedStatus := sliceToMap(opts.Status)
9697
allowedStage := sliceToMap(opts.Stage)
98+
allowedPRR := sliceToMap(opts.PRRApprover)
9799

98100
var keep []*keps.Proposal
99101
for _, k := range allKEPs {
@@ -103,6 +105,9 @@ func (c *Client) Query(opts QueryOpts) error {
103105
if len(opts.Stage) > 0 && !allowedStage[k.Stage] {
104106
continue
105107
}
108+
if len(opts.PRRApprover) > 0 && !atLeastOne(k.PRRApprovers, allowedPRR) {
109+
continue
110+
}
106111
keep = append(keep, k)
107112
}
108113

@@ -136,3 +141,14 @@ func selectByRegexp(vals []string, regexps []string) ([]string, error) {
136141
}
137142
return matches, nil
138143
}
144+
145+
// returns true if at least one of vals is in the allowed map
146+
func atLeastOne(vals []string, allowed map[string]bool) bool {
147+
for _, v := range vals {
148+
if allowed[v] {
149+
return true
150+
}
151+
}
152+
153+
return false
154+
}

0 commit comments

Comments
 (0)