MCPcopy Create free account
hub / github.com/cli/cli / PullRequestFeatures

Method PullRequestFeatures

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

Source from the content-addressed store, hash-verified

231}
232
233func (d *detector) PullRequestFeatures() (PullRequestFeatures, error) {
234 // TODO: reinstate the short-circuit once the APIs are fully available on github.com
235 // https://github.com/cli/cli/issues/5778
236 //
237 // if !ghinstance.IsEnterprise(d.host) {
238 // return allPullRequestFeatures, nil
239 // }
240
241 var pullRequestFeatureDetection struct {
242 PullRequest struct {
243 Fields []struct {
244 Name string
245 } `graphql:"fields(includeDeprecated: true)"`
246 } `graphql:"PullRequest: __type(name: \"PullRequest\")"`
247 StatusCheckRollupContextConnection struct {
248 Fields []struct {
249 Name string
250 } `graphql:"fields(includeDeprecated: true)"`
251 } `graphql:"StatusCheckRollupContextConnection: __type(name: \"StatusCheckRollupContextConnection\")"`
252 }
253
254 // Break feature detection down into two separate queries because the platform
255 // only supports two `__type` expressions in one query.
256 var pullRequestFeatureDetection2 struct {
257 WorkflowRun struct {
258 Fields []struct {
259 Name string
260 } `graphql:"fields(includeDeprecated: true)"`
261 } `graphql:"WorkflowRun: __type(name: \"WorkflowRun\")"`
262 }
263
264 gql := api.NewClientFromHTTP(d.httpClient)
265
266 var wg errgroup.Group
267 wg.Go(func() error {
268 return gql.Query(d.host, "PullRequest_fields", &pullRequestFeatureDetection, nil)
269 })
270 wg.Go(func() error {
271 return gql.Query(d.host, "PullRequest_fields2", &pullRequestFeatureDetection2, nil)
272 })
273 if err := wg.Wait(); err != nil {
274 return PullRequestFeatures{}, err
275 }
276
277 features := PullRequestFeatures{}
278
279 for _, field := range pullRequestFeatureDetection.PullRequest.Fields {
280 if field.Name == "isInMergeQueue" {
281 features.MergeQueue = true
282 }
283 }
284
285 for _, field := range pullRequestFeatureDetection.StatusCheckRollupContextConnection.Fields {
286 // We only check for checkRunCount here but it, checkRunCountsByState, statusContextCount and statusContextCountsByState
287 // were all introduced in the same version of the API.
288 if field.Name == "checkRunCount" {
289 features.CheckRunAndStatusContextCounts = true
290 }

Callers 1

TestPullRequestFeaturesFunction · 0.95

Calls 2

NewClientFromHTTPFunction · 0.92
QueryMethod · 0.65

Tested by 1

TestPullRequestFeaturesFunction · 0.76