October 31, 2016

RBTLIB - A Client-Side Library for Review Board

  —A look at a client-side library for Review Board.

I’ve been experimenting with a simple client-side library for Review Board. I named this library RBTLIB (RBTools Library). I have a basic implementation for obtaining the Root and Review Request resources from a Review Board instance.

RBTLIB started life as a project to answer how many review requests were entered into Review Board during a fixed period of time. I extended this project to see if it could become a passable RBTool replacement.

In creating RBTLIB, I mean no disrespect to the RBTools authors. RBTools provides a rich set of use cases to guide the development of RBTLIB.

During development I discovered Click, a command-line tool for Python applications. Click is simple to use to develop command-line tools.

I spent time studying Eli Bendersky’s PSS. If you enjoy learning by example, Eli’s code is an excellent place to start.

RBTLIB is primarily an experiement in developing a client-side library for a RESTful API. I set out to develop a small tool to query a Review Board instance for any reviews added during a 24 hour period. The command-line tools built using RBTLIB can answer this question.

Some challenges remain.

First, the command-line tools return JSON objects. I don’t have an answer to this challenge. It might be reasonable to leave the command-line tools as examples for other client development but this just skirts the problem.

Second, these tools provide support for only a few Review Board resources. I’m looking at ways to represent resource data programatically. It might be nice to write “root.json” or “root.capabilities.git” to access the entire Root resource as a dictionary or just the Git capabilities.

I like the layered implementation for the Root request and the Review Request request I created. For example:

It does a nice job of leveraging the structure of the Root resource and its links. So nice that I can write a Review Request getter in a single line:

get = root.links.key(

See: rbt/rbtlib/review_requests.py

Two design objectives I set for myself in writing RBTLIB are:

  • Keep the Python implementation simple. RBTLIB is written in a simple style that enables additional getters for resources to be written in a single line.

  • Expose the entirety of the resource to the client. RBTLIB exposes the Python dictionary created from the JSON response to the client. While this approach achieves the objective the current implementation is deficient because the command-line tools simply pass this dictionary along to the user.

The next revision of RBTLIB may include an implementation of the Composite design pattern that allows the library to dynamically generating a structure for accessing the elements of the Review Board response. I’m going to try and maintain simplicity by avoiding the use of Meta Classes and if successful, I should be able to improve the results returned by the command-line tools.

Source: RBTLIB v0.1

comments powered by Disqus