Skip to content

Commit

Permalink
Change pagination to classic offset pagination
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Bersani <marco.bersani@qonto.com>
  • Loading branch information
B3rs committed Jan 26, 2024
1 parent d745822 commit f4fd3fa
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions internal/providers/gitlab/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ func (c *Client) FetchProjects(ctx context.Context) ([]project.Project, error) {
func makeGitlabListProjectsOptions(config config.GitlabConfig) *gitlab.ListProjectsOptions {
options := &gitlab.ListProjectsOptions{
ListOptions: gitlab.ListOptions{
OrderBy: "id",
Pagination: "keyset",
PerPage: 25,
Sort: "asc",
PerPage: 25,
Sort: "asc",
},
}

Expand All @@ -84,23 +82,19 @@ func makeGitlabListProjectsOptions(config config.GitlabConfig) *gitlab.ListProje
func (c *Client) listAllProject(opts *gitlab.ListProjectsOptions) ([]*gitlab.Project, error) {
result := []*gitlab.Project{}

optionFuncs := []gitlab.RequestOptionFunc{}

for {
ps, resp, err := c.client.Projects.ListProjects(opts, optionFuncs...)
ps, resp, err := c.client.Projects.ListProjects(opts)
if err != nil {
return nil, err
}

result = append(result, ps...)

if resp.NextLink == "" {
if resp.NextPage == 0 {
break
}

optionFuncs = []gitlab.RequestOptionFunc{
gitlab.WithKeysetPaginationParameters(resp.NextLink),
}
opts.Page = resp.NextPage
}
return result, nil
}
Expand Down

0 comments on commit f4fd3fa

Please sign in to comment.