MCPcopy
hub / github.com/cli/cli / GetRuns

Function GetRuns

pkg/cmd/run/shared/shared.go:363–434  ·  view source on GitHub ↗
(client *api.Client, repo ghrepo.Interface, opts *FilterOptions, limit int)

Source from the content-addressed store, hash-verified

361}
362
363func GetRuns(client *api.Client, repo ghrepo.Interface, opts *FilterOptions, limit int) (*RunsPayload, error) {
364 path := fmt.Sprintf("repos/%s/actions/runs", ghrepo.FullName(repo))
365 if opts != nil && opts.WorkflowID > 0 {
366 path = fmt.Sprintf("repos/%s/actions/workflows/%d/runs", ghrepo.FullName(repo), opts.WorkflowID)
367 }
368
369 perPage := limit
370 if limit > 100 {
371 perPage = 100
372 }
373 path += fmt.Sprintf("?per_page=%d", perPage)
374 path += "&exclude_pull_requests=true" // significantly reduces payload size
375
376 if opts != nil {
377 if opts.Branch != "" {
378 path += fmt.Sprintf("&branch=%s", url.QueryEscape(opts.Branch))
379 }
380 if opts.Actor != "" {
381 path += fmt.Sprintf("&actor=%s", url.QueryEscape(opts.Actor))
382 }
383 if opts.Status != "" {
384 path += fmt.Sprintf("&status=%s", url.QueryEscape(opts.Status))
385 }
386 if opts.Event != "" {
387 path += fmt.Sprintf("&event=%s", url.QueryEscape(opts.Event))
388 }
389 if opts.Created != "" {
390 path += fmt.Sprintf("&created=%s", url.QueryEscape(opts.Created))
391 }
392 if opts.Commit != "" {
393 path += fmt.Sprintf("&head_sha=%s", url.QueryEscape(opts.Commit))
394 }
395 }
396
397 var result *RunsPayload
398
399pagination:
400 for path != "" {
401 var response RunsPayload
402 var err error
403 path, err = client.RESTWithNext(repo.RepoHost(), "GET", path, nil, &response)
404 if err != nil {
405 return nil, err
406 }
407
408 if result == nil {
409 result = &response
410 if len(result.WorkflowRuns) == limit {
411 break pagination
412 }
413 } else {
414 for _, run := range response.WorkflowRuns {
415 result.WorkflowRuns = append(result.WorkflowRuns, run)
416 if len(result.WorkflowRuns) == limit {
417 break pagination
418 }
419 }
420 }

Callers 3

runDeleteFunction · 0.92
runViewFunction · 0.92
GetRunsWithFilterFunction · 0.85

Calls 4

FullNameFunction · 0.92
preloadWorkflowNamesFunction · 0.85
RESTWithNextMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected