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

Usage of pagination #21

Open
webratz opened this issue May 13, 2019 · 3 comments
Open

Usage of pagination #21

webratz opened this issue May 13, 2019 · 3 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@webratz
Copy link

webratz commented May 13, 2019

I'm requesting sth, that returns more than 100 results. eg:
tc.vcs_root_api.get_roots()
This obviously returns a paginated result, as also the next_href etc is set.
From the docs it's unclear to me how to access the next pages of the result. Could you maybe give a hint what the right way would be todo this?

@allburov
Copy link
Member

Quick hack is get all entries with big count parameter.

vcss = tc.vcs_root.get_roots(locator='count:20000')

It seems now there is no way to get the next results, nextRef is only string for now.

@allburov allburov added help wanted Extra attention is needed good first issue Good for newcomers labels May 14, 2019
@webratz
Copy link
Author

webratz commented May 14, 2019

ah, thx. in the meanwhile i did for that specific call direct http calls and use the library for the rest. but i guess with this workaround i can remove the manual calls

@allburov
Copy link
Member

python-gitlab have a great solution. I have use below code and don't worry about pagination. We need realize something similar

    pr = gl.projects.get(209)
    piter = pr.pipelines.list(as_list=False)
    for pipeline in piter:
        pinfo = pr.pipelines.get(pipeline.id)
        print(pinfo.created_at)

From docs python-gitlab

list() methods can also return a generator object which will handle the next calls to the API when required. This is the recommended way to iterate through a large number of items:

items = gl.groups.list(as_list=False)
for item in items:
    print(item.attributes)

The generator exposes extra listing information as received from the server:

current_page: current page number (first page is 1)
prev_page: if None the current page is the first one
next_page: if None the current page is the last one
per_page: number of items per page
total_pages: total number of pages available
total: total number of items in the list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Development

No branches or pull requests

2 participants