I have been struggling to post a diff to ReviewBoard through their
API. I've managed to login to the server and create a new post, but
I've failed to post correctly the contents of the diff file.

I'm new to writing this kind of application, but my goal is to have a
one step script to:

diff a file (pre-commit) with the svn repository,
add a review request to ReviewBoard and post the diff from the current
May be later, the script can be part of a svn pre-commit hook.

My python attempt looks like:

import urllib.request
import urllib.parse
import os.path

... login to the reviewboard server with
urllib.request.HTTPBasicAuthHandler ...

diff_path = '/path/to/file'
diff_name = 'my.diff'
diff_path = os.path.join(diff_path, diff_name)

diff_val = open(diff_path,'r')

# load the diff into the http data POST request
diff_header =                                                    \
     '-- SoMe BoUnDaRy   \n'                                     \
  +  'Content-Disposition: form-data; name=path; filename='      \
  +  '"' + diff_name + '"\n\n'                                   \
  +  diff_val.read()  + '\n'                                     \
  +  '-- SoMe BoUnDaRy --'

data ={'path': diff_header, 'basedir': '/path/to/file/in/rep'}
print( data['path'] )
data = urllib.parse.urlencode(data)
data = data.encode('utf-8')

opener.open(                                      \
    'http://xxx.xxx.x.xxx/api/review-requests/26/diffs/', data)
With this code I get a BAD REQUEST(400) error, specifically: "One or
more fields had errors" (105).

I'm aware that there are some libraries out there that can talk with
the ReviewBoard's API. I'd rather not have to distribute to the other
developers another python library.

I'm also aware that post-review exists.  I don't think that post-
review can upload a diff of a files with versions committed to
different paths in the repository.  I have reason for this.  We have
just begun implementing code reviews and we've inherit a lot of old
code that needs to be reviewed from this point forward.  To keep track
of the files that have been reviewed and their reviewed content, I've
created a peer-reviewed branch.  Now, each time a file is reviewed
it's copied to this branch.  If a file is modified, then it is diffed
against the branch and the new version moved with svn.  At some point
we'll get to 100% review coverage, and the branch will go away.

Want to help the Review Board project? Donate today at 
Happy user? Let us know at http://www.reviewboard.org/users/
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to