Skip to content

Commit

Permalink
feat: use -approve flag to included approved PRs in output
Browse files Browse the repository at this point in the history
  • Loading branch information
cuotos committed Jun 6, 2023
1 parent 3ef7ed5 commit 7d1caba
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
12 changes: 12 additions & 0 deletions filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func WithIsClosed() FilterOpt {
}
}

// WithReviewRequired will add the "review:required" flag to the search string. It logically does the opposite of WithIncludeApproved
func WithReviewRequired(required bool) FilterOpt {
return func() (string, error) {
if required {
Expand All @@ -70,6 +71,17 @@ func WithReviewRequired(required bool) FilterOpt {
}
}

// WithIncludeApproved will NOT add the "review:required" flag to the search string. It logically does the opposite of WithReviewRequired
func WithIncludeApproved(approved bool) FilterOpt {
return func() (string, error) {
if approved {
return "", nil
} else {
return "review:required", nil
}
}
}

func WithIsDraft() FilterOpt {
return func() (string, error) {
return "draft:true", nil
Expand Down
1 change: 1 addition & 0 deletions filter/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestOptions(t *testing.T) {
{WithIsNotDraft(), "draft:false", ""},
{WithIsDraft(), "draft:true", ""},
{WithReviewRequired(true), "review:required", ""},
{WithIncludeApproved(false), "review:required", ""},
}

for _, tc := range tcs {
Expand Down
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func main() {
func run() error {
v := flag.Bool("v", false, "prints version")
jsonOutput := flag.Bool("json", false, "print output in JSON format")
all := flag.Bool("all", false, "include PRs ready to merge")
all := flag.Bool("all", false, "include PRs ready to merge. DEPRECATED: use -approved")
approved := flag.Bool("approved", false, "include PRs ready to merge")
searchWholeTeam := flag.Bool("team", false, "should look up all members of the team. defaults to just calling user")

flag.Parse()
Expand Down Expand Up @@ -93,7 +94,9 @@ func run() error {
members = append(members, user)
}

queryString, err := generateQueryString(conf.GithubOrg, members, filter.WithReviewRequired(!*all)) //"view all" is "NOT requiring review", therefore have to negate the "all" flag
incApproved := *all || *approved

queryString, err := generateQueryString(conf.GithubOrg, members, filter.WithIncludeApproved(incApproved))
if err != nil {
return err
}
Expand Down
18 changes: 14 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,34 @@ import (

func TestGenerateQueryString(t *testing.T) {
tcs := []struct {
Org string
Users []string
Expected []string
Org string
Users []string
Expected []string
incApproved bool
}{
{
"TestOrg",
[]string{},
[]string{"org:TestOrg", "is:open", "review:required", "draft:false", "type:pr"},
false,
},
{
"SecondOrg",
[]string{"cuotos"},
[]string{"org:SecondOrg", "is:open", "review:required", "draft:false", "author:cuotos", "type:pr"},
false,
},
{
"AnotherOrg",
[]string{"cuotos", "danyo"},
[]string{"org:AnotherOrg", "is:open", "review:required", "draft:false", "type:pr", "author:cuotos", "author:danyo"},
false,
},
{
"TestOrg",
[]string{},
[]string{"org:TestOrg", "is:open", "draft:false", "type:pr"},
true,
},
}

Expand All @@ -44,7 +54,7 @@ func TestGenerateQueryString(t *testing.T) {
members = append(members, &github.User{Login: &userName})
}

actual, _ := generateQueryString(tc.Org, members, filter.WithReviewRequired(true))
actual, _ := generateQueryString(tc.Org, members, filter.WithReviewRequired(!tc.incApproved)) //"inc approved" is "NOT requiring review", therefore have to negate the "approved" flag
actualFields := strings.Fields(actual)
assert.ElementsMatch(t, tc.Expected, actualFields)
}
Expand Down

0 comments on commit 7d1caba

Please sign in to comment.