MCPcopy Create free account
hub / github.com/cli/cli / GetWorkflows

Function GetWorkflows

pkg/cmd/workflow/shared/shared.go:57–99  ·  view source on GitHub ↗
(client *api.Client, repo ghrepo.Interface, limit int)

Source from the content-addressed store, hash-verified

55}
56
57func GetWorkflows(client *api.Client, repo ghrepo.Interface, limit int) ([]Workflow, error) {
58 perPage := limit
59 page := 1
60 if limit > 100 || limit == 0 {
61 perPage = 100
62 }
63
64 workflows := []Workflow{}
65
66 for {
67 if limit > 0 && len(workflows) == limit {
68 break
69 }
70 var result WorkflowsPayload
71
72 u, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "actions", "workflows")
73 if err != nil {
74 return nil, err
75 }
76 u.SetQuery("per_page", strconv.Itoa(perPage))
77 u.SetQuery("page", strconv.Itoa(page))
78
79 err = client.REST(repo.RepoHost(), "GET", u.String(), nil, &result)
80 if err != nil {
81 return nil, err
82 }
83
84 for _, workflow := range result.Workflows {
85 workflows = append(workflows, workflow)
86 if limit > 0 && len(workflows) == limit {
87 break
88 }
89 }
90
91 if len(result.Workflows) < perPage {
92 break
93 }
94
95 page++
96 }
97
98 return workflows, nil
99}
100
101type FilteredAllError struct {
102 error

Callers 4

listRunFunction · 0.92
TestGetWorkflowsFunction · 0.85
getWorkflowsByNameFunction · 0.85
ResolveWorkflowFunction · 0.85

Calls 7

JoinPathFunction · 0.92
SetQueryMethod · 0.80
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65

Tested by 1

TestGetWorkflowsFunction · 0.68