ReivewBoard+Perforce代码评审平台搭建

前言:这是我放在CSDN博客里点击最好一篇文章。今天把它搬过来。 团队在应用RB的这几年,有很多变化。代码评审的习惯已经早已深得人心,工具的变化给Team也带来很多变化!Thanks to RB. 🙂

原文

代码评审(Code Review)是敏捷开发很重要的一环,是保证软件质量的最佳实践之一。要做好Code Review, 就需要有一套简单,高效,功能完善且界面友好的工具链支持。

我所在的团队原来一直使用Code Striker做为Code Reivew的平台,但其对Perforce支持的不好,且界面不很友好,给我们带来不少麻烦,使用效果也打了折扣。从去年底,我们开始使用功能和界面都 全面增强的Review Board,同时再加上少量的工具配置,就可以实现非常高效的Code Review平台。我刚刚完成服务器的迁移,所以写些心得,一来做为日后参考,二来也和各位朋友分享。

1. Review Board简介

Review Board(简称RB)是基于Django的网络应用,界面非常友好,功能也非常强大,包含一套完整的Review流程,支持现在几种流行的SCM工具和 数据库。最感谢它网站FAQ里的一句,”Review Board is absolutely free for commercial use!“。它的开发人员来自大名鼎鼎的VMWare,其mail-list非常活跃,老大Christian Hammond(chipx86@chipx86.com )也非常乐于助人。

2. 服务器安装

RB可以安装在多种平台。本文是在WinXP SP3上安装, 其他平台请参考网站上其他文档。

请先安装Python 2.5和Apache Http Server 2.2。他们的安装略去不表,但请保证“C:/Python25;C:/Python25/Scripts”在你的环境变量里 。其他软件(针对Python2.5)我已上传到http://download.csdn.net/source/2403641。

0)安装和Python相关的一些东东

在软件包中,请安装mod_python, PIL,setuptools。这几个都是双击之后,一路NEXT即可。

1)安装memcached for windows(在软件包中)

先使用命令行memcached.exe -d install

安装服务,再去WinXP服务管理界面启动该服务。

然后用命令行

安装python-memcached. (NOTE: 最近发现easy_install也被墙了,所以用easy_install时可能有点问题。如果是那样,请找个代理,然后设置HTTP_PROXY环境变量翻墙)。

2)安装数据库SQLITE(在软件包中)

软件包中是SQLITE,但RB还支持其他数据库。请到它家的网站找,安装也不困难。

SQLITE的安装很简单,只需把它的EXE放到PATH中某个路径即可。你可以直接扔到C:/Windows/system32下。呵呵。

然后再用 easy_install pysqlite, 安装相对应的python module.

3)安装GNU patch(在软件包中)

它的安装也是一路NEXT。安装完成之后,把它EXE所在的路径放到PATH里。

4)安装p4python25(在软件包中)

一路NEXT!如果你不是在使用p4,请去RB网站看其他SCM的安装方法。

5)安装RB

RB团队已经把它放到easy_install的源里了,所以可以用 easy_install ReviewBoard 安装,很方便吧。

好了,该装的都OK,下一站就是建站。

 

3. 建站

RB建站很简单,在命令行中打一句命令

rb-site install “站名”

4. RB中添加Repository

在建站完成后,你应该可以访问到RBweb页面。

添加Repository, 需要用admin用户。这里就说说Perforce的配置吧。

首先有你在建站时用的admin用户登录,然后就会进入到Admin的页面(最上面有一个Admin的链接)。

5. 如何发布一个Review Request

关于这个问题,RB提供了一个好用的工具叫post-review。 对于使用Perforce的团队来说,这个工具更是极其好用。只要用这个post-review加上checklist-id就OK了。

下面让我们来配置一下这个工具(有些是专门针对Perforce的配置):

1) 保证在”cmd”下,p4命令是可用的。

2) 保证P4的几个相关环境变量设置了(P4USER, P4PASSWD, P4CLIENT, P4PORT )

3) 用”easy_install -U RBTools“ 安装post-review工具

4) 修改post-review的相关脚本(主要是我开始是配置在老版本的RB上,新的还不太知道能不能用,但我的一定可用。:) 大家到这个地方去下载http://download.csdn.net/source/2856000。) 修改分三步,第一,到C:/Python25/Scripts,删掉post-review.py, post-review.bat, post-review.exe; 第二,拷贝压缩包里的文件到C:/Python25/Scripts); 第三,打开post-review.py, 然后修改REVIEWBOARD_URL 那一行,用真实的URL替换。

5) 安装GNUDiff,这是用来生成diff文件的时候用的。别忘了,把diff加到PATH里,一般是这个路径”C:/Program files/GnuWin32/bin”。

好了,都配好了,下面让我们来post review吧。

1) 在你建的RB上,注册一个新账号;

2) 打开cmd, 用命令”post-review PendingChangelistId -o

3) 第一次用这个命令,它会让你输入username和passwd,以后就不会了。

4) 上传DIFF之后,它会用默认的浏览器打开网页, 显示你刚上传的Request, 这时它处于draft状态。

5) 加上一些必要的信息, 比如谁来review之类的,然后就Pulish吧!

6. 关于和P4V的集成

使用其它SCM的这一段就不用读了。

P4V是一个非常好用的工用,它也非常容易和post-review集成,那就是使用external tools. 步骤如下:

1) 打开P4V
2) 选择menu Tools->Manage Custom Tools… 打开窗口


3) New->Tool… and 打开窗口


4) 可以按如下填写


如果用<strong>”%p -o”</strong>
打开浏览器。

5) 然后在P4V里就可以使用了,如下图。


6) Post-review之后就可以在RB里看到了。

7 总结

RB的基础配置就这么多,它的网站上还有更丰富的内容,包括其他代码服务器的配置,RB升级,搬移等等。总的来说都是非常容易的。

BTW,用Perforce的朋友在提交Request时,可能会遇到一些关于权限的问题。我猜和P4服务配置有关。我问过chipx86, 他说会fix。不过在最新1.5中还没有改,所以我只好还用我自己的hack过的文件。如果有朋友遇到,可以告诉我,我会把文件发给你。

How to migrate ReviewBoard database from sqlite to MySQL

About 3 years ago, I introduced Review Board into our team with a great help from RB group and replaced CodeStrike. We deployed RB on a WinXP VM and the backend database is sqlite. I can’t remember the reason. Maybe I just wanted to save some time. Actually, it has spent a lot of time of our team.

Why? Because sqlite is a lightweight DB and it have bad performace in concurrency scenario. For our team, we have about 20 developers and RB is the most popular daily tools. Now we have to say, we highly depend it to control the quality of team’s code.

Recently, the dababase issue was getting worse. RB pages can’t be created well and there are many warnings/errors on it. And yesterday, the database was dead finally-“The database is locked!”. That’s a message from Django. I googled and the best solution is to use better database to avoid such issues in future.

I took about 3 hours to migrate database to MySQL 5.1. Maybe my experience can help you to save some time.

Step 1. sqlite bump

Go to sqlite.com and download a command line. For window version, you can find it here.

Unzip it and use command to dump sqlite database.

reviewboard.db is the database file of sqlite.

Step 2. Convert to MySQL dump

Now we have the sqlite dump file. But you can’t import it into a MySQL database directly. Because some syntax is not supported by MySQL.

I googled and got a free converter to do that. You can find it here and download sqlite3_mysql.zip.

In the deep of the zip , you can find a executable file – sqlite_mysql.exe. Run it and convert the sqlite dump file to a MySQL one.

Step 3. Import MySQL dump

Before that, please create a database in your MySQL database.

In my case, the dump is about 180M and I waited very long time. (And there may be some warning messages. I don’t know why but for now the migrated server works well. So maybe we can’t ignore them.)

Step 3.1 Alter database structure

Actually, this issue was found when I finished Step 4 and restarted RB. At the beginning, RB worked well. But a minute later, a guy said he could’t submit any comments.

The root cause was the “id” field of some tables lost the property of “AUTO_INCREMENT”. I didn’t know why and SQL in dump file was right. Then I write a very simple .py script to fix this issue.

I just went through all tables and alter the property of “id” field if the table has one.

Step 4. Change RB configuration file

Change rb_site_root/conf/settings_local.py to:

Make sure MySQLdb is installed or there will be error when restart RB.

The best moment came finally! RB restarted successfully and all review request/comment/diff were there. And the performance was improved. You can feel the page is loaded fast. Cheers! 😀

If you have the same problem with me, I hope this post can help and save some time.