MCPcopy
hub / github.com/cli/cli / searchPullRequests

Function searchPullRequests

pkg/cmd/pr/list/http.go:32–130  ·  view source on GitHub ↗
(httpClient *http.Client, detector fd.Detector, repo ghrepo.Interface, filters prShared.FilterOptions, limit int)

Source from the content-addressed store, hash-verified

30}
31
32func searchPullRequests(httpClient *http.Client, detector fd.Detector, repo ghrepo.Interface, filters prShared.FilterOptions, limit int) (*api.PullRequestAndTotalCount, error) {
33 // TODO advancedIssueSearchCleanup
34 // We won't need feature detection when GHES 3.17 support ends, since
35 // the advanced issue search is the only available search backend for
36 // issues.
37 features, err := detector.SearchFeatures()
38 if err != nil {
39 return nil, err
40 }
41
42 type response struct {
43 Search struct {
44 Nodes []api.PullRequest
45 PageInfo struct {
46 HasNextPage bool
47 EndCursor string
48 }
49 IssueCount int
50 }
51 }
52
53 fragment := fmt.Sprintf("fragment pr on PullRequest{%s}", api.PullRequestGraphQL(filters.Fields))
54 query := fragment + `
55 query PullRequestSearch(
56 $q: String!,
57 $type: SearchType!,
58 $limit: Int!,
59 $endCursor: String,
60 ) {
61 search(query: $q, type: $type, first: $limit, after: $endCursor) {
62 issueCount
63 nodes {
64 ...pr
65 }
66 pageInfo {
67 hasNextPage
68 endCursor
69 }
70 }
71 }`
72
73 variables := map[string]interface{}{}
74
75 filters.Repo = ghrepo.FullName(repo)
76 filters.Entity = "pr"
77
78 // TODO advancedIssueSearchCleanup
79 if features.AdvancedIssueSearchAPI {
80 variables["q"] = prShared.SearchQueryBuild(filters, true)
81 // TODO advancedIssueSearchCleanup
82 if features.AdvancedIssueSearchAPIOptIn {
83 variables["type"] = "ISSUE_ADVANCED"
84 } else {
85 variables["type"] = "ISSUE"
86 }
87 } else {
88 variables["q"] = prShared.SearchQueryBuild(filters, false)
89 variables["type"] = "ISSUE"

Callers 2

listPullRequestsFunction · 0.85

Calls 7

PullRequestGraphQLFunction · 0.92
FullNameFunction · 0.92
NewClientFromHTTPFunction · 0.92
GraphQLMethod · 0.80
minFunction · 0.70
SearchFeaturesMethod · 0.65
RepoHostMethod · 0.65

Tested by 1