fix listing of PRs when merged ones are searched (#3730)
Co-authored-by: Mislav Marohnić <mislav@github.com>
This commit is contained in:
parent
35e5c758b5
commit
e160dd3eae
4 changed files with 69 additions and 2 deletions
|
|
@ -112,9 +112,14 @@ func listRun(opts *ListOptions) error {
|
|||
return err
|
||||
}
|
||||
|
||||
issueState := strings.ToLower(opts.State)
|
||||
if issueState == "open" && shared.QueryHasStateClause(opts.Search) {
|
||||
issueState = ""
|
||||
}
|
||||
|
||||
filterOptions := prShared.FilterOptions{
|
||||
Entity: "issue",
|
||||
State: strings.ToLower(opts.State),
|
||||
State: issueState,
|
||||
Assignee: opts.Assignee,
|
||||
Labels: opts.Labels,
|
||||
Author: opts.Author,
|
||||
|
|
|
|||
|
|
@ -116,9 +116,14 @@ func listRun(opts *ListOptions) error {
|
|||
return err
|
||||
}
|
||||
|
||||
prState := strings.ToLower(opts.State)
|
||||
if prState == "open" && shared.QueryHasStateClause(opts.Search) {
|
||||
prState = ""
|
||||
}
|
||||
|
||||
filters := shared.FilterOptions{
|
||||
Entity: "pr",
|
||||
State: strings.ToLower(opts.State),
|
||||
State: prState,
|
||||
Author: opts.Author,
|
||||
Assignee: opts.Assignee,
|
||||
Labels: opts.Labels,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package shared
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/google/shlex"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
|
|
@ -243,6 +244,21 @@ func SearchQueryBuild(options FilterOptions) string {
|
|||
return q.String()
|
||||
}
|
||||
|
||||
func QueryHasStateClause(searchQuery string) bool {
|
||||
argv, err := shlex.Split(searchQuery)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, arg := range argv {
|
||||
if arg == "is:closed" || arg == "is:merged" || arg == "state:closed" || arg == "state:merged" || strings.HasPrefix(arg, "merged:") || strings.HasPrefix(arg, "closed:") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// MeReplacer resolves usages of `@me` to the handle of the currently logged in user.
|
||||
type MeReplacer struct {
|
||||
apiClient *api.Client
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package shared
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
|
@ -151,3 +152,43 @@ func TestMeReplacer_Replace(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_QueryHasStateClause(t *testing.T) {
|
||||
tests := []struct {
|
||||
searchQuery string
|
||||
hasState bool
|
||||
}{
|
||||
{
|
||||
searchQuery: "is:closed is:merged",
|
||||
hasState: true,
|
||||
},
|
||||
{
|
||||
searchQuery: "author:mislav",
|
||||
hasState: false,
|
||||
},
|
||||
{
|
||||
searchQuery: "assignee:g14a mentions:vilmibm",
|
||||
hasState: false,
|
||||
},
|
||||
{
|
||||
searchQuery: "merged:>2021-05-20",
|
||||
hasState: true,
|
||||
},
|
||||
{
|
||||
searchQuery: "state:merged state:open",
|
||||
hasState: true,
|
||||
},
|
||||
{
|
||||
searchQuery: "assignee:g14a is:closed",
|
||||
hasState: true,
|
||||
},
|
||||
{
|
||||
searchQuery: "state:closed label:bug",
|
||||
hasState: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
gotState := QueryHasStateClause(tt.searchQuery)
|
||||
assert.Equal(t, tt.hasState, gotState)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue