(client *api.Client, repo ghrepo.Interface, opts *FilterOptions, limit int)
| 366 | } |
| 367 | |
| 368 | func GetRuns(client *api.Client, repo ghrepo.Interface, opts *FilterOptions, limit int) (*RunsPayload, error) { |
| 369 | u, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "actions", "runs") |
| 370 | if err != nil { |
| 371 | return nil, err |
| 372 | } |
| 373 | if opts != nil && opts.WorkflowID > 0 { |
| 374 | u, err = safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "actions", "workflows", strconv.FormatInt(opts.WorkflowID, 10), "runs") |
| 375 | if err != nil { |
| 376 | return nil, err |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | perPage := limit |
| 381 | if limit > 100 { |
| 382 | perPage = 100 |
| 383 | } |
| 384 | u.SetQuery("per_page", strconv.Itoa(perPage)) |
| 385 | u.SetQuery("exclude_pull_requests", "true") // significantly reduces payload size |
| 386 | |
| 387 | if opts != nil { |
| 388 | if opts.Branch != "" { |
| 389 | u.SetQuery("branch", opts.Branch) |
| 390 | } |
| 391 | if opts.Actor != "" { |
| 392 | u.SetQuery("actor", opts.Actor) |
| 393 | } |
| 394 | if opts.Status != "" { |
| 395 | u.SetQuery("status", opts.Status) |
| 396 | } |
| 397 | if opts.Event != "" { |
| 398 | u.SetQuery("event", opts.Event) |
| 399 | } |
| 400 | if opts.Created != "" { |
| 401 | u.SetQuery("created", opts.Created) |
| 402 | } |
| 403 | if opts.Commit != "" { |
| 404 | u.SetQuery("head_sha", opts.Commit) |
| 405 | } |
| 406 | } |
| 407 | var pageURL safeurl.SafeURL = u |
| 408 | |
| 409 | var result *RunsPayload |
| 410 | |
| 411 | pagination: |
| 412 | for pageURL.String() != "" { |
| 413 | var response RunsPayload |
| 414 | next, err := client.RESTWithNext(repo.RepoHost(), "GET", pageURL.String(), nil, &response) |
| 415 | if err != nil { |
| 416 | return nil, err |
| 417 | } |
| 418 | pageURL = safeurl.NewImmutableSafeURL(next) |
| 419 | |
| 420 | if result == nil { |
| 421 | result = &response |
| 422 | if len(result.WorkflowRuns) == limit { |
| 423 | break pagination |
| 424 | } |
| 425 | } else { |
no test coverage detected