fix(issue list): reject pull request-only search qualifiers
This commit is contained in:
parent
628dea6e52
commit
5194256928
2 changed files with 26 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package list
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/cli/cli/v2/api"
|
||||
fd "github.com/cli/cli/v2/internal/featuredetection"
|
||||
|
|
@ -9,6 +10,8 @@ import (
|
|||
prShared "github.com/cli/cli/v2/pkg/cmd/pr/shared"
|
||||
)
|
||||
|
||||
var pullRequestSearchQualifierRE = regexp.MustCompile(`(?i)\b(?:is|type):(?:pr|pull-?request)\b`)
|
||||
|
||||
func listIssues(client *api.Client, repo ghrepo.Interface, filters prShared.FilterOptions, limit int) (*api.IssuesAndTotalCount, error) {
|
||||
var states []string
|
||||
switch filters.State {
|
||||
|
|
@ -114,6 +117,10 @@ loop:
|
|||
}
|
||||
|
||||
func searchIssues(client *api.Client, detector fd.Detector, repo ghrepo.Interface, filters prShared.FilterOptions, limit int) (*api.IssuesAndTotalCount, error) {
|
||||
if pullRequestSearchQualifierRE.MatchString(filters.Search) {
|
||||
return nil, fmt.Errorf("cannot use pull request search qualifiers with `gh issue list`; use `gh pr list` instead")
|
||||
}
|
||||
|
||||
// TODO advancedIssueSearchCleanup
|
||||
// We won't need feature detection when GHES 3.17 support ends, since
|
||||
// the advanced issue search is the only available search backend for
|
||||
|
|
|
|||
|
|
@ -214,3 +214,22 @@ func TestSearchIssuesAndAdvancedSearch(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchIssues_rejectsPullRequestQualifiers(t *testing.T) {
|
||||
reg := &httpmock.Registry{}
|
||||
defer reg.Verify(t)
|
||||
|
||||
httpClient := &http.Client{Transport: reg}
|
||||
client := api.NewClientFromHTTP(httpClient)
|
||||
|
||||
_, err := searchIssues(
|
||||
client,
|
||||
fd.AdvancedIssueSearchSupportedAsOnlyBackend(),
|
||||
ghrepo.New("OWNER", "REPO"),
|
||||
prShared.FilterOptions{Search: "is:pr"},
|
||||
30,
|
||||
)
|
||||
|
||||
assert.EqualError(t, err, "cannot use pull request search qualifiers with `gh issue list`; use `gh pr list` instead")
|
||||
assert.Len(t, reg.Requests, 0)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue