2010-09-07

Integrating Subversion and Review Board

At Google, all production code must be peer reviewed before it is allowed to be submitted to their source control system. Since I'm no longer a Googler, I don't have access to their awesome infrastructure so I had to roll my own. Review Board is a pretty good code review system, and unlike the open source implementation of Google's internal one, you can host Review Board on your own hardware.

We use Subversion as our SCM. Out of the box, Subversion doesn't force code to be reviewed before submission, and I couldn't find any documentation about forcing code reviews through pre-submit hooks. Subversion's hooks are pretty powerful, and Review Board has a decent API, so I wrote my own. Hopefully this is useful to someone out there. It's written in PHP5. Put this in your subversion hooks directory, call it pre-submit, and make it executable.

7 comments:

  1. Thanks for the info!
    I'm looking, though, to the script to do pre-commints in reviewboard 1.5. The API is based on REST instead of JSON so this script would not work (at least it does not when I tried). Do you have this same script for the REST interface? :)
    Thanks a lot!

    ReplyDelete
  2. We haven't upgraded our Review Board instance at $employer, so I haven't really needed to try it. I'll see if I can rewrite the script to handle 1.5 as well.

    ReplyDelete
  3. Hi, We wanted to implemented the same. We made changes to pre-submit hook. It was giving error in the following 2 lines..

    $repository = $_SERVER['argv'][1];
    $transaction = $_SERVER['argv'][2];

    Hence I hard coded the $repository path as /var/www/svn/project1 where project files exist in repo.
    Also changed the $transaction path to the reviewboard path. After changes the code looks as follows.

    #$repository = $_SERVER['argv'][1];
    #$transaction = $_SERVER['argv'][2];
    $repository = '/var/www/svn/project1';
    $transaction = '/var/www/html/htdocs';

    But after uploading files to SVN, I am not able to see in Reviewboard. Please let me know how to fix this issue.

    ReplyDelete
    Replies
    1. I think my script may not work for you. This script is supposed to keep you from being able to submit code to SVN unless there's a review with a Ship It in Review Board.

      Delete
  4. Hi Omni Adams,
    after applying you script following error has been encountered. please look into this.

    [root@reviewboard ART]# svn ci -m 'review: 39'
    Sending mukul.txt
    Transmitting file data .svn: Commit failed (details follow):
    svn: Commit blocked by pre-commit hook (exit code 1) with output:
    PHP Parse error: syntax error, unexpected ';' in /home/cmteam/csvn/data/repositories/CCRForms3/hooks/pre-submit.php on line 130

    ReplyDelete
    Replies
    1. It looks like my gist had some escaped HTML in it. Change the < to < and it should work.

      Delete