Skip to content

Commit

Permalink
🧹 add pagination to gitlab projects fetching (#1957)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey authored Sep 27, 2023
1 parent cbbde6d commit 7de8f84
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions motor/providers/gitlab/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,20 @@ func (t *Provider) GroupProjects() ([]*gitlab.Project, error) {
if t.GroupId != 0 {
gid = t.GroupId
}
grp, _, err := t.Client().Groups.ListGroupProjects(gid, nil)
if err != nil {
return nil, err
perPage := 50
page := 1
total := 50
projects := []*gitlab.Project{}
for page*perPage <= total {
projs, resp, err := t.Client().Groups.ListGroupProjects(gid, &gitlab.ListGroupProjectsOptions{ListOptions: gitlab.ListOptions{Page: page, PerPage: perPage}})
if err != nil {
return nil, err
}
projects = append(projects, projs...)
total = resp.TotalItems
page += 1
}
return grp, err
return projects, nil
}

func (t *Provider) Project() (*gitlab.Project, error) {
Expand Down

0 comments on commit 7de8f84

Please sign in to comment.