(client *http.Client, repo ghrepo.Interface, pr *api.PullRequest, requiredChecks bool, includeEvent bool)
| 255 | } |
| 256 | |
| 257 | func populateStatusChecks(client *http.Client, repo ghrepo.Interface, pr *api.PullRequest, requiredChecks bool, includeEvent bool) ([]check, checkCounts, error) { |
| 258 | apiClient := api.NewClientFromHTTP(client) |
| 259 | |
| 260 | type response struct { |
| 261 | Node *api.PullRequest |
| 262 | } |
| 263 | |
| 264 | query := fmt.Sprintf(` |
| 265 | query PullRequestStatusChecks($id: ID!, $endCursor: String) { |
| 266 | node(id: $id) { |
| 267 | ...on PullRequest { |
| 268 | %s |
| 269 | } |
| 270 | } |
| 271 | }`, api.RequiredStatusCheckRollupGraphQL("$id", "$endCursor", includeEvent)) |
| 272 | |
| 273 | variables := map[string]interface{}{ |
| 274 | "id": pr.ID, |
| 275 | } |
| 276 | |
| 277 | statusCheckRollup := api.CheckContexts{} |
| 278 | |
| 279 | for { |
| 280 | var resp response |
| 281 | err := apiClient.GraphQL(repo.RepoHost(), query, variables, &resp) |
| 282 | if err != nil { |
| 283 | return nil, checkCounts{}, err |
| 284 | } |
| 285 | |
| 286 | if len(resp.Node.StatusCheckRollup.Nodes) == 0 { |
| 287 | return nil, checkCounts{}, errors.New("no commit found on the pull request") |
| 288 | } |
| 289 | |
| 290 | result := resp.Node.StatusCheckRollup.Nodes[0].Commit.StatusCheckRollup.Contexts |
| 291 | statusCheckRollup.Nodes = append( |
| 292 | statusCheckRollup.Nodes, |
| 293 | result.Nodes..., |
| 294 | ) |
| 295 | |
| 296 | if !result.PageInfo.HasNextPage { |
| 297 | break |
| 298 | } |
| 299 | variables["endCursor"] = result.PageInfo.EndCursor |
| 300 | } |
| 301 | |
| 302 | if len(statusCheckRollup.Nodes) == 0 { |
| 303 | return nil, checkCounts{}, fmt.Errorf("no checks reported on the '%s' branch", pr.HeadRefName) |
| 304 | } |
| 305 | |
| 306 | checks, counts := aggregateChecks(statusCheckRollup.Nodes, requiredChecks) |
| 307 | if len(checks) == 0 && requiredChecks { |
| 308 | return checks, counts, fmt.Errorf("no required checks reported on the '%s' branch", pr.HeadRefName) |
| 309 | } |
| 310 | return checks, counts, nil |
| 311 | } |
no test coverage detected