| 262 | } |
| 263 | |
| 264 | func (d *detector) PullRequestFeatures() (PullRequestFeatures, error) { |
| 265 | // TODO: reinstate the short-circuit once the APIs are fully available on github.com |
| 266 | // https://github.com/cli/cli/issues/5778 |
| 267 | // |
| 268 | // if !ghinstance.IsEnterprise(d.host) { |
| 269 | // return allPullRequestFeatures, nil |
| 270 | // } |
| 271 | |
| 272 | var pullRequestFeatureDetection struct { |
| 273 | PullRequest struct { |
| 274 | Fields []struct { |
| 275 | Name string |
| 276 | } `graphql:"fields(includeDeprecated: true)"` |
| 277 | } `graphql:"PullRequest: __type(name: \"PullRequest\")"` |
| 278 | StatusCheckRollupContextConnection struct { |
| 279 | Fields []struct { |
| 280 | Name string |
| 281 | } `graphql:"fields(includeDeprecated: true)"` |
| 282 | } `graphql:"StatusCheckRollupContextConnection: __type(name: \"StatusCheckRollupContextConnection\")"` |
| 283 | } |
| 284 | |
| 285 | // Break feature detection down into two separate queries because the platform |
| 286 | // only supports two `__type` expressions in one query. |
| 287 | var pullRequestFeatureDetection2 struct { |
| 288 | WorkflowRun struct { |
| 289 | Fields []struct { |
| 290 | Name string |
| 291 | } `graphql:"fields(includeDeprecated: true)"` |
| 292 | } `graphql:"WorkflowRun: __type(name: \"WorkflowRun\")"` |
| 293 | } |
| 294 | |
| 295 | gql := api.NewClientFromHTTP(d.client()) |
| 296 | |
| 297 | var wg errgroup.Group |
| 298 | wg.Go(func() error { |
| 299 | return gql.Query(d.host, "PullRequest_fields", &pullRequestFeatureDetection, nil) |
| 300 | }) |
| 301 | wg.Go(func() error { |
| 302 | return gql.Query(d.host, "PullRequest_fields2", &pullRequestFeatureDetection2, nil) |
| 303 | }) |
| 304 | if err := wg.Wait(); err != nil { |
| 305 | return PullRequestFeatures{}, err |
| 306 | } |
| 307 | |
| 308 | features := PullRequestFeatures{} |
| 309 | |
| 310 | for _, field := range pullRequestFeatureDetection.PullRequest.Fields { |
| 311 | if field.Name == "isInMergeQueue" { |
| 312 | features.MergeQueue = true |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | for _, field := range pullRequestFeatureDetection.StatusCheckRollupContextConnection.Fields { |
| 317 | // We only check for checkRunCount here but it, checkRunCountsByState, statusContextCount and statusContextCountsByState |
| 318 | // were all introduced in the same version of the API. |
| 319 | if field.Name == "checkRunCount" { |
| 320 | features.CheckRunAndStatusContextCounts = true |
| 321 | } |