Skip to content

Commit db11c5b

Browse files
authored
Fix advanced search not enabled for fields
1 parent f94057c commit db11c5b

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

pkg/github/issues_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,47 @@ func Test_SearchIssues(t *testing.T) {
744744
expectError: false,
745745
expectedResult: mockSearchResult,
746746
},
747+
{
748+
name: "query with field. qualifier enables advanced_search",
749+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
750+
GetSearchIssues: expectQueryParams(
751+
t,
752+
map[string]string{
753+
"q": "is:issue field.priority:P1",
754+
"page": "1",
755+
"per_page": "30",
756+
"advanced_search": "true",
757+
},
758+
).andThen(
759+
mockResponse(t, http.StatusOK, mockSearchResult),
760+
),
761+
}),
762+
requestArgs: map[string]any{
763+
"query": "field.priority:P1",
764+
},
765+
expectError: false,
766+
expectedResult: mockSearchResult,
767+
},
768+
{
769+
name: "query without field. qualifier does not set advanced_search",
770+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
771+
GetSearchIssues: expectQueryParams(
772+
t,
773+
map[string]string{
774+
"q": "is:issue is:open",
775+
"page": "1",
776+
"per_page": "30",
777+
},
778+
).andThen(
779+
mockResponse(t, http.StatusOK, mockSearchResult),
780+
),
781+
}),
782+
requestArgs: map[string]any{
783+
"query": "is:open",
784+
},
785+
expectError: false,
786+
expectedResult: mockSearchResult,
787+
},
747788
{
748789
name: "search issues fails",
749790
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{

pkg/github/search_utils.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"net/http"
99
"regexp"
10+
"strings"
1011

1112
ghErrors "github.com/github/github-mcp-server/pkg/errors"
1213
"github.com/github/github-mcp-server/pkg/utils"
@@ -94,14 +95,21 @@ func prepareSearchArgs(args map[string]any, searchType string) (string, *github.
9495
return "", nil, err
9596
}
9697

97-
return query, &github.SearchOptions{
98+
opts := &github.SearchOptions{
9899
Sort: sort,
99100
Order: order,
100101
ListOptions: github.ListOptions{
101102
Page: pagination.Page,
102103
PerPage: pagination.PerPage,
103104
},
104-
}, nil
105+
}
106+
107+
// field.<name>:<value> qualifiers require the advanced search API.
108+
if strings.Contains(query, "field.") {
109+
opts.AdvancedSearch = github.Ptr(true)
110+
}
111+
112+
return query, opts, nil
105113
}
106114

107115
func searchHandler(

0 commit comments

Comments
 (0)