MCPcopy
hub / github.com/cli/cli / PullRequestFeatures

Method PullRequestFeatures

internal/featuredetection/feature_detection.go:201–268  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

199}
200
201func (d *detector) PullRequestFeatures() (PullRequestFeatures, error) {
202 // TODO: reinstate the short-circuit once the APIs are fully available on github.com
203 // https://github.com/cli/cli/issues/5778
204 //
205 // if !ghinstance.IsEnterprise(d.host) {
206 // return allPullRequestFeatures, nil
207 // }
208
209 var pullRequestFeatureDetection struct {
210 PullRequest struct {
211 Fields []struct {
212 Name string
213 } `graphql:"fields(includeDeprecated: true)"`
214 } `graphql:"PullRequest: __type(name: \"PullRequest\")"`
215 StatusCheckRollupContextConnection struct {
216 Fields []struct {
217 Name string
218 } `graphql:"fields(includeDeprecated: true)"`
219 } `graphql:"StatusCheckRollupContextConnection: __type(name: \"StatusCheckRollupContextConnection\")"`
220 }
221
222 // Break feature detection down into two separate queries because the platform
223 // only supports two `__type` expressions in one query.
224 var pullRequestFeatureDetection2 struct {
225 WorkflowRun struct {
226 Fields []struct {
227 Name string
228 } `graphql:"fields(includeDeprecated: true)"`
229 } `graphql:"WorkflowRun: __type(name: \"WorkflowRun\")"`
230 }
231
232 gql := api.NewClientFromHTTP(d.httpClient)
233
234 var wg errgroup.Group
235 wg.Go(func() error {
236 return gql.Query(d.host, "PullRequest_fields", &pullRequestFeatureDetection, nil)
237 })
238 wg.Go(func() error {
239 return gql.Query(d.host, "PullRequest_fields2", &pullRequestFeatureDetection2, nil)
240 })
241 if err := wg.Wait(); err != nil {
242 return PullRequestFeatures{}, err
243 }
244
245 features := PullRequestFeatures{}
246
247 for _, field := range pullRequestFeatureDetection.PullRequest.Fields {
248 if field.Name == "isInMergeQueue" {
249 features.MergeQueue = true
250 }
251 }
252
253 for _, field := range pullRequestFeatureDetection.StatusCheckRollupContextConnection.Fields {
254 // We only check for checkRunCount here but it, checkRunCountsByState, statusContextCount and statusContextCountsByState
255 // were all introduced in the same version of the API.
256 if field.Name == "checkRunCount" {
257 features.CheckRunAndStatusContextCounts = true
258 }

Callers 1

TestPullRequestFeaturesFunction · 0.95

Calls 3

NewClientFromHTTPFunction · 0.92
QueryMethod · 0.65
WaitMethod · 0.65

Tested by 1

TestPullRequestFeaturesFunction · 0.76