Re: Creating a review with Python API

264 views
Skip to first unread message

Steven MacLeod

unread,
May 20, 2013, 3:07:08 PM5/20/13
to revie...@googlegroups.com
Hi,

'root.get_review_requests().get_self(id='15583', repository=repository)' will result in a
"GET http://.../api/review_requests/?id=15583&repository=<id>"

What you're looking for is 'root.get_review_requests().get_item(15583)', or alternatively 'root.get_review_request(review_request_id=15583). The former traverses the tree of resources, while the latter uses the root resource's uri-template for 'review-request'.

Additionally, retrieving the id of the repository is unnecessary to find the review request with the ID you are looking for.


On Mon, May 20, 2013 at 8:50 AM, Dave Johnston <dave.j...@me.com> wrote:
Hi,

I've been trying to following the documentation here:

To create a review for a existing review request, and then add a comment to the review.  Unfortunately I'm not getting far.
I've tried the following:

root = client.get_root()
repos = root.get_repositories()
if repos.num_items < 1:
    raise Exception('No valid repositories.')

repository = repos[0].id
review_request = root.get_review_requests().get_self(id='15583', repository=repository)
review = review_request.get_reviews().create()
filediff_id = review.get_diffs()[0].get_files()[0].id
review.get_diff_comments().create(
    filediff_id=1,
    first_line=131,
    num_lines=2,
    text='This is a diff comment!')

review.update(body_top='Test Review Comment - please ignore', public=True)

I get the error: AttributeError: 'ResourceList' object has no attribute 'get_reviews'

So it looks like  root.get_review_requests().get_self(id='15583', repository=repository) isn't the right request to return an existing review request ?
Any help would be much appreciated.

Cheers

--
Want to help the Review Board project? Donate today at http://www.reviewboard.org/donate/
Happy user? Let us know at http://www.reviewboard.org/users/
-~----------~----~----~----~------~----~------~--~---
To unsubscribe from this group, send email to reviewboard...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/reviewboard?hl=en
---
You received this message because you are subscribed to the Google Groups "reviewboard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reviewboard...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

soorajchirag

unread,
May 27, 2013, 2:25:45 PM5/27/13
to revie...@googlegroups.com
Hi Steven,

I am attempting to get the review request by using the following as you stated in your email:
root.get_review_request(review_request_id=15583)

but it failed for me with the same AttributeError as in this thread.

However, when I tried the other approach in your mail, it works fine.

The following works:
         self.review_request_id = id
         self.review_request = self.root.get_review_requests().get_item(id)

This one doesnt:
         self.review_request_id = id
         self.review_request = self.root.get_review_request(review_request_id=id)

Error:
  File ".../common/interface.py", line 95, in set_review_id
    self.review_request = self.root.get_review_request(review_request_id=str_id)
  File ".../rbtools/api/resource.py", line 273, in __getattr__
    raise AttributeError

I tried get_diffs() as well and that is also failing with the same error.

Is there something I need to do differently?

Regards,
Sundeep

Steven MacLeod

unread,
May 27, 2013, 2:46:08 PM5/27/13
to revie...@googlegroups.com
Hi Sundeep,

Using the uri-templates on the root relies on functionality specific to the root resource. The way the API Client knows it can do this is based on the Content-Type header the server returns when you request the root resource.

Could you please show me the header output of:
    curl -i http://<your-RB-url>/api/

Thanks,

Steven

Steven MacLeod

unread,
May 29, 2013, 2:40:57 AM5/29/13
to revie...@googlegroups.com
Hi Sundeep,

The minimum Review Board version which fully supports the RBTools API Client is RB 1.6.12. It's possible to use the API Client with slightly older versions, but certain operations will not be supported (I highly recommend upgrading to at least 1.6.12, if not to an even more recent version).

The actual code that generates resource specific Content-Types is primarily a part of djblets. Here is the commit which first introduced it: https://github.com/djblets/djblets/commit/89b16e35d953798411dd2b21190fbf14e72f34b6

- Steve


On Tue, May 28, 2013 at 8:47 AM, <sooraj...@gmail.com> wrote:

On debugging the issue further, I've found that the server is not returning the correct Content-Type when responding to the request to get the RootResource. It is returning "application/json" and not the "application/vnd.reviewboard.org.root" that the API is expecting.

As a result, it does not handle the uri_templates section of the response and treats like like a regular ItemResource.

The server I am running against is 1.6.3 (from http://<server>/api/info):

<rsp>
  <info>
    <product>
      <is_release>1</is_release>
      <package_version>1.6.3</package_version>
      <version>1.6.3</version>
      <name>Review Board</name>
    </product>
  ...

Is there a specific (minimum) version that we need to upgrade the server to ?

Regards,
Sundeep

PS: Could you also please point me to the server code where this Content-type is being added for RootResource.

soorajchirag

unread,
May 29, 2013, 4:38:39 AM5/29/13
to revie...@googlegroups.com
Thanks Steve.

While I was able to get past this using the other approach you had mentioned earlier. I've hit another related issue down the line. Looks like I'll have to convince my admin to upgrade the RB server. :)

Regards,
Sundeep
Reply all
Reply to author
Forward
0 new messages