prepareSearchArgs resolves the search query string and REST search options from the tool args, applying the standard is: / repo: / munging shared by search_issues and search_pull_requests.
(args map[string]any, searchType string)
| 59 | // applying the standard is:<type> / repo:<owner>/<repo> munging shared by search_issues and |
| 60 | // search_pull_requests. |
| 61 | func prepareSearchArgs(args map[string]any, searchType string) (string, *github.SearchOptions, error) { |
| 62 | query, err := RequiredParam[string](args, "query") |
| 63 | if err != nil { |
| 64 | return "", nil, err |
| 65 | } |
| 66 | |
| 67 | if !hasSpecificFilter(query, "is", searchType) { |
| 68 | query = fmt.Sprintf("is:%s %s", searchType, query) |
| 69 | } |
| 70 | |
| 71 | owner, err := OptionalParam[string](args, "owner") |
| 72 | if err != nil { |
| 73 | return "", nil, err |
| 74 | } |
| 75 | |
| 76 | repo, err := OptionalParam[string](args, "repo") |
| 77 | if err != nil { |
| 78 | return "", nil, err |
| 79 | } |
| 80 | |
| 81 | if owner != "" && repo != "" && !hasRepoFilter(query) { |
| 82 | query = fmt.Sprintf("repo:%s/%s %s", owner, repo, query) |
| 83 | } |
| 84 | |
| 85 | sort, err := OptionalParam[string](args, "sort") |
| 86 | if err != nil { |
| 87 | return "", nil, err |
| 88 | } |
| 89 | order, err := OptionalParam[string](args, "order") |
| 90 | if err != nil { |
| 91 | return "", nil, err |
| 92 | } |
| 93 | pagination, err := OptionalPaginationParams(args) |
| 94 | if err != nil { |
| 95 | return "", nil, err |
| 96 | } |
| 97 | |
| 98 | opts := &github.SearchOptions{ |
| 99 | Sort: sort, |
| 100 | Order: order, |
| 101 | ListOptions: github.ListOptions{ |
| 102 | Page: pagination.Page, |
| 103 | PerPage: pagination.PerPage, |
| 104 | }, |
| 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 |
| 113 | } |
| 114 | |
| 115 | func searchHandler( |
| 116 | ctx context.Context, |
no test coverage detected