X Tutup
Skip to content

Commit a2dfeeb

Browse files
author
vilmibm
committed
support fetching all workflows
1 parent 16fe05c commit a2dfeeb

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

pkg/cmd/workflow/shared/shared.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,18 @@ func (w *Workflow) Base() string {
4040
}
4141

4242
func GetWorkflows(client *api.Client, repo ghrepo.Interface, limit int) ([]Workflow, error) {
43-
// TODO support getting all for 0 limit
4443
perPage := limit
4544
page := 1
46-
if limit > 100 {
45+
if limit > 100 || limit == 0 {
4746
perPage = 100
4847
}
4948

5049
workflows := []Workflow{}
5150

52-
for len(workflows) < limit {
51+
for {
52+
if limit > 0 && len(workflows) == limit {
53+
break
54+
}
5355
var result WorkflowsPayload
5456

5557
path := fmt.Sprintf("repos/%s/actions/workflows?per_page=%d&page=%d", ghrepo.FullName(repo), perPage, page)
@@ -61,7 +63,7 @@ func GetWorkflows(client *api.Client, repo ghrepo.Interface, limit int) ([]Workf
6163

6264
for _, workflow := range result.Workflows {
6365
workflows = append(workflows, workflow)
64-
if len(workflows) == limit {
66+
if limit > 0 && len(workflows) == limit {
6567
break
6668
}
6769
}
@@ -136,8 +138,7 @@ func getWorkflowByID(client *api.Client, repo ghrepo.Interface, ID string) (*Wor
136138
}
137139

138140
func getWorkflowsByName(client *api.Client, repo ghrepo.Interface, name string) ([]Workflow, error) {
139-
// TODO fix limit
140-
workflows, err := GetWorkflows(client, repo, 100)
141+
workflows, err := GetWorkflows(client, repo, 0)
141142
if err != nil {
142143
return nil, fmt.Errorf("couldn't fetch workflows for %s: %w", ghrepo.FullName(repo), err)
143144
}

pkg/cmd/workflow/view/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func runView(opts *ViewOptions) error {
176176
}
177177

178178
func promptWorkflows(client *api.Client, repo ghrepo.Interface) (*shared.Workflow, error) {
179-
workflows, err := shared.GetWorkflows(client, repo, 10)
179+
workflows, err := shared.GetWorkflows(client, repo, 0)
180180
if len(workflows) == 0 {
181181
err = errors.New("no workflows are enabled")
182182
}

0 commit comments

Comments
 (0)
X Tutup