当前位置: 首页 > git, linux > 正文

Code review 工具gerrit之体验

之前一直使用gitlab来管理代码,由于gitlab并没有强制code-review的功能,所以仓库管理员一直在找合适的工具进行Code-review,于是推荐给我gerrit,我从开始一直认为gerrit只是个code-review的辅助工具,必须跟gitlab整合起来使用,在不将二者捏到一块不罢休的理念下把二者的关系弄得越来越糊涂,用惯了gitlab总觉得gerrit太挫,于是前阵子果断放弃gerrit。
但是在仓库管理员的逼迫及公司对Code-review的迫切程度的驱使下,不得已又抽空看了看gerrit,目前看来gerrit本身就可以管理git,跟gitlab可以没有丝毫瓜葛。以下权且算是一份安装笔记,因为gerrit的具体如何使用还没真正搞明白。

安装环境:Centos6.4 + gerrit-2.6.1 + LDAP + mysql-5.1.69

Install gerrit
参考: http://gerrit-documentation.googlecode.com/svn/Documentation/2.6/index.html
下载war
wget http://gerrit-releases.storage.googleapis.com/gerrit-2.6.1.war

初始化数据库
Install/config mysql
CREATE USER ‘gerrit’@’localhost’ IDENTIFIED BY ‘pwd’;
CREATE DATABASE reviewdb;
ALTER DATABASE reviewdb charset=utf8;
GRANT ALL ON reviewdb.* TO ‘gerrit’@’localhost’;
FLUSH PRIVILEGES;

创建用户
sudo adduser gerrit
sudo su gerrit
java -jar gerrit.war init -d /home/gerrit/gerritapp

init时mysql有个报错:

Prompt to install core plugins [y/N]?

Exception in thread “main” com.google.gwtorm.server.OrmException: Cannot apply SQL
CREATE TABLE account_project_watches (
notify_abandoned_changes CHAR(1) DEFAULT ‘N’ NOT NULL CHECK (notify_abandoned_changes IN (‘Y’,’N’)),
notify_all_comments CHAR(1) DEFAULT ‘N’ NOT NULL CHECK (notify_all_comments IN (‘Y’,’N’)),
notify_new_changes CHAR(1) DEFAULT ‘N’ NOT NULL CHECK (notify_new_changes IN (‘Y’,’N’)),
notify_new_patch_sets CHAR(1) DEFAULT ‘N’ NOT NULL CHECK (notify_new_patch_sets IN (‘Y’,’N’)),
notify_submitted_changes CHAR(1) DEFAULT ‘N’ NOT NULL CHECK (notify_submitted_changes IN (‘Y’,’N’)),
account_id INT DEFAULT 0 NOT NULL,
filter VARCHAR(255) BINARY DEFAULT ” NOT NULL,
project_name VARCHAR(255) BINARY DEFAULT ” NOT NULL
,PRIMARY KEY(account_id,filter,project_name)
)
at com.google.gwtorm.jdbc.JdbcExecutor.execute(JdbcExecutor.java:44)
at com.google.gwtorm.jdbc.JdbcSchema.createRelations(JdbcSchema.java:84)
at com.google.gwtorm.jdbc.JdbcSchema.updateSchema(JdbcSchema.java:54)
at com.google.gerrit.server.schema.SchemaCreator.create(SchemaCreator.java:103)
at com.google.gerrit.server.schema.SchemaUpdater.update(SchemaUpdater.java:55)
at com.google.gerrit.pgm.Init$SiteRun.upgradeSchema(Init.java:175)
at com.google.gerrit.pgm.Init.run(Init.java:78)
at com.google.gerrit.pgm.util.AbstractProgram.main(AbstractProgram.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gerrit.launcher.GerritLauncher.invokeProgram(GerritLauncher.java:168)
at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:92)
at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:50)
at Main.main(Main.java:25)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Specified key was too long; max key length is 1000 bytes

google大神了一下,据说是将mysql引擎改为innodb即可。
vim my.cnf and under [mysqld] add:
default-storage-engine = innodb

安装完之后的配置如下,使用了LDAP认证:
cat gerrit.config

[gerrit]
basePath = git
canonicalWebUrl = http://gerrit.2hei.net:8080/
[database]
type = mysql
hostname = localhost
database = reviewdb
username = gerrit
[auth]
type = LDAP
[ldap]
server = ldap://2hei.net
username = cn=superuser,dc=2hei,dc=net
password = mypwd
accountBase = dc=2hei,dc=net
accountPattern = (&(objectClass=*)(uid=${username}))
sslVerify = false

[sendemail]
smtpServer = localhost
[container]
user = gerrit
javaHome = /usr/java/jdk1.6.0_45/jre
[sshd]
listenAddress = *:29418
[httpd]
listenUrl = http://*:8080/
[cache]
directory = cache

客户端的操作如下:
创建project
ssh -p 29418 2hei@gerrit.2hei.net gerrit create-project –name sanew/test.git

clone到本地
git clone ssh://2hei@gerrit.2hei.net:29418/sanew/test.git

创建hooks
scp -p -P 29418 2hei@gerrit.2hei.net:hooks/commit-msg .git/hooks/

git remote -v
origin ssh://2hei@gerrit.2hei.net:29418/sanew/test.git (fetch)
origin ssh://2hei@gerrit.2hei.net:29418/sanew/test.git (push)

测试提交文件
$ echo “First file” > readme.txt
$ git add readme.txt
$ git commit -m “first add”
[master (root-commit) 4dfd8bb] first add
1 file changed, 1 insertion(+)
create mode 100644 readme.txt

提交到git server
$ git push origin HEAD:refs/for/master
Counting objects: 3, done.
Writing objects: 100% (3/3), 264 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Processing changes: new: 1, refs: 1, done
remote:
remote: New Changes:
remote: http://gerrit.2hei.net:8080/1
remote:
To ssh://2hei@gerrit.2hei.ne:29418/sanew/test.git
* [new branch] HEAD -> refs/for/master

接下来就可以通过 http://gerrit.2hei.net:8080/来进行Code-review了。

启动脚本: /home/gerrit/gerritapp/bin/gerrit.sh [start|stop|restart]

下面就是添加reviewer(组)然后找人进行score,comment,approve,merge等等一系列操作了。

本文固定链接: https://www.2hei.net/2013/09/17/code-review-tools-gerrit-use/ | 2hei.net

该日志由 u2 于2013年09月17日发表在 git, linux 分类下,
原创文章转载请注明: Code review 工具gerrit之体验 | 2hei.net
关键字: , ,

报歉!评论已关闭.