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

Method PullRequestFeatures

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

Source from the content-addressed store, hash-verified

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

Callers 1

TestPullRequestFeaturesFunction · 0.95

Calls 3

NewClientFromHTTPFunction · 0.92
QueryMethod · 0.65
WaitMethod · 0.65

Tested by 1

TestPullRequestFeaturesFunction · 0.76