Skip to content

Commit 6aa1efc

Browse files
committed
Support --base and --label in combination with pr list --assignee
1 parent 51d570e commit 6aa1efc

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

api/queries_pr.go

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,8 @@ func PullRequestList(client *Client, vars map[string]interface{}, limit int) ([]
474474
prs := []PullRequest{}
475475
pageLimit := min(limit, 100)
476476
variables := map[string]interface{}{}
477-
for name, val := range vars {
478-
variables[name] = val
479-
}
480477

481-
if _, ok := vars["assignee"]; ok {
478+
if assignee, ok := vars["assignee"].(string); ok {
482479
query = fragment + `
483480
query(
484481
$q: String!,
@@ -499,21 +496,36 @@ func PullRequestList(client *Client, vars map[string]interface{}, limit int) ([]
499496
}`
500497
owner := vars["owner"].(string)
501498
repo := vars["repo"].(string)
502-
assignee := vars["assignee"].(string)
503-
state := ""
504-
states := vars["state"].([]string)
505-
if len(states) == 1 {
499+
search := []string{
500+
fmt.Sprintf("repo:%s/%s", owner, repo),
501+
fmt.Sprintf("assignee:%s", assignee),
502+
"is:pr",
503+
"sort:created-desc",
504+
}
505+
if states, ok := vars["state"].([]string); ok && len(states) == 1 {
506506
switch states[0] {
507507
case "OPEN":
508-
state = " state:open"
508+
search = append(search, "state:open")
509509
case "CLOSED":
510-
state = " state:closed"
510+
search = append(search, "state:closed")
511511
case "MERGED":
512-
state = " is:merged"
512+
search = append(search, "is:merged")
513+
}
514+
}
515+
if labels, ok := vars["labels"].([]string); ok && len(labels) > 0 {
516+
if len(labels) > 1 {
517+
return nil, fmt.Errorf("multiple labels with --assignee are not supported: %#v", vars)
513518
}
519+
search = append(search, fmt.Sprintf(`label:"%s"`, labels[0]))
520+
}
521+
if baseBranch, ok := vars["baseBranch"].(string); ok {
522+
search = append(search, fmt.Sprintf(`base:"%s"`, baseBranch))
523+
}
524+
variables["q"] = strings.Join(search, " ")
525+
} else {
526+
for name, val := range vars {
527+
variables[name] = val
514528
}
515-
// TODO: support base, label filtering
516-
variables["q"] = fmt.Sprintf("repo:%s/%s assignee:%s is:pr%s sort:created-desc", owner, repo, assignee, state)
517529
}
518530

519531
for {

command/pr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func init() {
2727
prListCmd.Flags().IntP("limit", "L", 30, "Maximum number of items to fetch")
2828
prListCmd.Flags().StringP("state", "s", "open", "Filter by state")
2929
prListCmd.Flags().StringP("base", "B", "", "Filter by base branch")
30-
prListCmd.Flags().StringArrayP("label", "l", nil, "Filter by label")
30+
prListCmd.Flags().StringSliceP("label", "l", nil, "Filter by label")
3131
prListCmd.Flags().StringP("assignee", "a", "", "Filter by assignee")
3232
}
3333

@@ -137,7 +137,7 @@ func prList(cmd *cobra.Command, args []string) error {
137137
if err != nil {
138138
return err
139139
}
140-
labels, err := cmd.Flags().GetStringArray("label")
140+
labels, err := cmd.Flags().GetStringSlice("label")
141141
if err != nil {
142142
return err
143143
}

0 commit comments

Comments
 (0)