Hendrra
Hendrra

Reputation: 859

Getting all review requests from Review Board Python Web API

I would like to get the information about all reviews from my server. That's my code that I used to achieve my goal.

from rbtools.api.client import RBClient
client = RBClient('http://my-server.net/')
root = client.get_root()
reviews = root.get_review_requests()

The variable reviews contains just 25 review requests (I expected much, much more). What's even stranger I tried something a bit different

count = root.get_review_requests(counts_only=True)

Now count.count is equal to 17164. How can I extract the rest of my reviews? I tried to check the official documentation but I haven't found anything connected to my problem.

Upvotes: 2

Views: 586

Answers (2)

rzlvmp
rzlvmp

Reputation: 9364

You have to use pagination (unfortunately I can't provide exact code without ability to reproduce your question):

The maximum number of results to return in this list. By default, this is 25. There is a hard limit of 200; if you need more than 200 results, you will need to make more than one request, using the “next” pagination link.

Looks like pagination helper class also available.

If you want to get 200 results you may set max_results:

requests = root.get_review_requests(max_results=200)

Anyway HERE is a good example how to iterate over results.

Also I don't recommend to get all 17164 results by one request even if it possible. Because total data of response will be huge (let's say if size one a result is 10KB total size will be more than 171MB)

Upvotes: 0

mutantkeyboard
mutantkeyboard

Reputation: 1714

According to the documentation (https://www.reviewboard.org/docs/manual/dev/webapi/2.0/resources/review-request-list/#webapi2.0-review-request-list-resource), counts_only is only a Boolean flag that indicates following:

If specified, a single count field is returned with the number of results, instead of the results themselves.

But, what you could do, is to provide it with status, so:

count = root.get_review_requests(counts_only=True, status='all')

should return you all the requests.

Keep in mind that I didn't test this part of the code locally. I referred to their repo test example -> https://github.com/reviewboard/rbtools/blob/master/rbtools/utils/tests/test_review_request.py#L643 and the documentation link posted above.

Upvotes: 0

Related Questions