Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for pagination #14

Open
zcei opened this issue Nov 11, 2015 · 2 comments
Open

Support for pagination #14

zcei opened this issue Nov 11, 2015 · 2 comments

Comments

@zcei
Copy link

zcei commented Nov 11, 2015

Hej folks,

I'm using this awesome wrapper for the GitLab API and was wondering the other day, why there are projects missing when using gitlab.projects.list.

After some research I've seen, that GitLab uses a pagination via Link headers and was wondering how to set them.

Are you up for a PR, which allows the user to set a default per_page? (GitLabs default is 20)

Also how would you like the pagination? I see no way without breaking backward compatibility here, as you're passing the actual content array and not a "wrapper with meta-information" e.g.:

yield gitlab.projects.list();

{
  page: 1,
  perPage: 30,
  content: [...]
}

EDIT: I've found out so far, that I can use gitlab.projects.list({per_page: 30}), though it doesn't look that nice, especially when privateToken is in camel-case.
Also we don't get the feedback from headers whether there are more pages to request or not.

@fengmk2
Copy link
Member

fengmk2 commented Nov 12, 2015

Can you help us to improve this?

@tex0l
Copy link

tex0l commented Oct 30, 2018

I've built myself a little decorator:

const depaginate = func => async (args) => {
  const result = []
  let page = 0
  while (true) {
    page++
    const r = await func({
      ...args,
      page,
      per_page: 50
    })
    if (r.length) result.push(...r)
    else break
  }
  return result
}

It can be used this way:

await depaginate(client.issues.list)({
  id: project.id,
})

Ugly, but it works 😇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants