Is there a way to query the reviews given by a user in a certain time period?

194 views
Skip to first unread message

Adam Gross

unread,
May 10, 2022, 8:55:22 AM5/10/22
to Review Board Community
I am working on a Python script which uses the rbtools package and collects the contributions made by a person. I started with the basic things like enumerating all code reviews posted by a user and sorting by lines of code changed.

I want to add functionality to query for all reviews given by a user as part of reviewing someone else's code during a specific time period. However, I can't find any relevant web API under https://www.reviewboard.org/docs/manual/3.0/webapi/ that would fit. All of the ones that seem relevant (e.g. get_diff_comments and get_reviews) all require a review request ID instead of allowing me to do a search based on username and time period. Is there an API that would help me here?

Thanks,
Adam

David Trowbridge

unread,
May 10, 2022, 1:10:40 PM5/10/22
to reviewboard
Adam,

This is a long-standing limitation of the current API. We're planning on adding a new resource soon to query reviews across all review requests.

There is an extension that we've used internally that adds a new API endpoint to do this. It's not well documented but perhaps it could serve as a starting point: https://github.com/beanbaginc/student-sonar/tree/master/misc/rb-reviews-api

David

--
Supercharge your Review Board with Power Pack: https://www.reviewboard.org/powerpack/
Want us to host Review Board for you? Check out RBCommons: https://rbcommons.com/
Happy user? Let us know! https://www.reviewboard.org/users/
---
You received this message because you are subscribed to the Google Groups "Review Board Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reviewboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/reviewboard/d95123a1-2a6c-4174-9886-2287077dadc9n%40googlegroups.com.

Adam Gross

unread,
Nov 2, 2022, 9:10:57 AM11/2/22
to Review Board Community
Hi David, you had mentioned "We're planning on adding a new resource soon to query reviews across all review requests." Is this present in the new 5.0? If so, what is the resource name? Thanks!

David Trowbridge

unread,
Nov 2, 2022, 1:32:38 PM11/2/22
to revie...@googlegroups.com
Hi Adam,


There are also root-level resources for individual comments that can be queried similarly.

David

Adam Gross

unread,
Nov 28, 2022, 4:18:07 PM11/28/22
to revie...@googlegroups.com
Sorry to bug you again about this. I was able to get IT to deploy this extension on top of 3.0.18 but I can't figure out the API entrypoint. I read through the GitHub merge request description, the extension repo code, and the documentation, but I still can't figure it out. I tried https://<hostname>/api/rb_reviews_api?from-user=grossag among other things. Do you know what the resource entry point is for this extension?

You received this message because you are subscribed to a topic in the Google Groups "Review Board Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/reviewboard/OBsJ7sFDsCc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to reviewboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/reviewboard/CAFS3VNUqkkQN7q6yzNAeW36HnkHufG%2B7pBzz9pjiZprCEin9uQ%40mail.gmail.com.

David Trowbridge

unread,
Nov 28, 2022, 4:22:08 PM11/28/22
to revie...@googlegroups.com
Adam,

Because it comes from an extension, the endpoint is nested within the extensions namespace at /api/extensions/rb_reviews_api.extension.ReviewsAPI/reviews/

It supports a ?from-user=<username> argument, as well as time-added-from= and time-added-to= arguments (that work similar to the ones on other endpoints).

David

Adam Gross

unread,
Nov 28, 2022, 6:21:33 PM11/28/22
to revie...@googlegroups.com

Adam Gross

unread,
Dec 9, 2022, 2:31:02 PM12/9/22
to revie...@googlegroups.com
Here is a snippet of the Python code I'm using to access the extension. I didn't want to include the whole script, as it would be too much detail. But I can if others would prefer. Error handling is nonexistent at this point in my script, so ignore obvious failure cases.

(Variables received by the time this code runs: years is an int, username is a string and is just the base username, server_url is the server address including https)

I am finding that I don't get any results for users who I query. I know these users provided reviews 4 months ago on this test reviewboard instance. But the script prints "0 reviews given."

I'm not asking for any debugging, but overall does this look like a sane way to use the API to query the reviews given? The reviewboard Python API code is so dynamic that it's hard to inspect at runtime.

utcnow = datetime.datetime.utcnow()
time_added_to = utcnow.isoformat()
utcbegin = utcnow - datetime.timedelta(weeks=years*52)
time_added_from = utcbegin.isoformat()

client = RBClient(server_url)

try:
    root = client.get_root()
except AuthorizationError:
    print('You are not logged in to the reviewboard API. '
          'Enter your credentials:')
    username = input('Username: ')
    password = getpass('Password: ')
    client.login(username, password)

    root = client.get_root()

reviews_extension = None
for extension in root.get_extensions():
    if extension.name == 'rb_reviews_api':
        reviews_extension = extension
        break
else:
    print('No RB reviews API extension installed')

for username in usernames:
    reviews_given = reviews_extension.get_reviews(
        time_added_from=time_added_from,
        time_added_to=time_added_to,
        from_user=username,
    )
    review_count = 0
    print('Fetching reviews given. This may take a while...')
    for review_given in reviews_given.all_items:
        review_count += 1
    print('%d reviews given' % review_count)
Reply all
Reply to author
Forward
0 new messages