devopshq / teamcity

dohq-teamcity is a Python package providing access to the JetBrains TeamCity server API.
https://devopshq.github.io/teamcity/
MIT License
33 stars 12 forks source link

Usage of pagination #21

Open webratz opened 5 years ago

webratz commented 5 years ago

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 commented 5 years ago

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.

webratz commented 5 years ago

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 commented 5 years ago

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