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