Gerrit代码评审流程

                                     作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

 

 

一.代码评审流程(如下图所示)

Gerrit代码评审流程

第一步:贡献者报建一个提交,并通过之前从gerrit下载的commit-msg hook分配一个新的全局chang-id。 (提交并不代表着说代码被推送)

第二步:贡献者推送代码到gerrit评审分支,为评审创建了一个新的更改。 Gerrit并且会分配一个唯一的URL,以便别人使用这个URL进行访问和检查。

第三步: 这一步是可选的。持续集成构建并验证更改:jenkins获取gerrit代码发生改变,并自动触发检查。然后把结果反馈给gerrit。要么是积极的(+1),或者是消极的。就是负分。

第四步: 贡献者邀请一个或多个审查人员进行代码审核并提供他们的反馈结果。别人可以自发地添加他们自己的评审意见。

第五步: 在评分的步骤中:所有被邀请人员和项目权限管理人员,都可以对代码进行评价。结果是"-2"到"+2"之间

第六步: 根据定义的规则,来校验评审结果。按默认规则来说,如果是-2分,直接否决代码成果。需要开发员进行重新开发和提交。如果是+2分,可以合并。但如果有一个-2分就不能提交合并。

第七步:如果根据第六步的规则审核未过。开发人员需要返工。

第八步: 如果评审反馈是负面的,则可以放弃更改。这样其它人也不会花费更多的精力来评审它了。被放弃的更改不会从git存储库中删除。

第九步:如果评审反馈是正面的,那么可以提交更改,提交会自动触发合并步骤。

第十步:如果合并中出现冲突,那么则必须代码必须重新更改,验证步骤返回第二步、

 

二.添加主题(topic)的两种方式

1>.本地提交代码(下面演示的为我客户端完整提交到Gerrit的完整操作)

[root@node203.yinzhengjie.org.cn ~]# git clone "ssh://jason@node201.yinzhengjie.org.cn:29418/yinzhengjie-code"
Cloning into 'yinzhengjie-code'...
remote: Counting objects: 2, done
remote: Finding sources: 100% (2/2)
remote: Total 2 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (2/2), done.
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]# 
[root@node203.yinzhengjie.org.cn ~]# cd yinzhengjie-code/
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# 
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# 
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# git config user.name "jason"
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# git config user.email "y1053419035@qq.com"
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# 
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# curl -Lo .git/hooks/commit-msg http://172.30.1.201:8080/tools/hooks/commit-msg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  4781  100  4781    0     0  71145      0 --:--:-- --:--:-- --:--:-- 71358
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# 
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# ll .git/hooks/commit-msg
-rw-r--r-- 1 root root 4781 Jun 19 04:23 .git/hooks/commit-msg
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# 
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# chmod +x .git/hooks/commit-msg
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# 
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# ll .git/hooks/commit-msg
-rwxr-xr-x 1 root root 4781 Jun 19 04:23 .git/hooks/commit-msg
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# 
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# echo "My first code review" > code-review-sample.txt
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# 
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# git add code-review-sample.txt 
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# 
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# git commit -m "First Change for review"
[master d0b962a] First Change for review
 1 file changed, 1 insertion(+)
 create mode 100644 code-review-sample.txt
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# 
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# git push origin HEAD:refs/for/master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 321 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Processing changes: new: 1, done    
remote: 
remote: New Changes:
remote:   http://172.30.1.201:8080/#/c/yinzhengjie-code/+/1 First Change for review
remote: 
To ssh://node201.yinzhengjie.org.cn:29418/yinzhengjie-code
 * [new branch]      HEAD -> refs/for/master
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# 
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# 

2>.查看Gerrit的Web UI

Gerrit代码评审流程

 

3>.查看详细的用户提交信息

Gerrit代码评审流程

4>.添加主题有两种方式

在将代码push到Gerrit时添加相应的参数来指定主题,我上面测试是没有添加的,因此只能通过图形界面进行添加,如果通过命令行添加,可在push时使用以下命令:
    "git push origin HEAD:refs/for/master%topic=first-topic"

Gerrit代码评审流程

5>.主题修改成功

Gerrit代码评审流程

 

三.分配审核者(Reviewers)的两种方式

1>.查看接收者(由于我们在提交的时候并没有在命令行中指定添加的审核者,因此点开提交信息发现并没有审核者信息)

Gerrit代码评审流程

2>.在Web UI中添加审核者信息

在将代码push到Gerrit时添加相应的参数指定主题和审核者信息,我上面测试是没有添加的,因此只能通过图形界面进行添加,如果通过命令行添加,可在push时使用以下命令:
  "git push origin HEAD:refs/for/master%topic=first-topic,r=yinzhengjie <y1053419035@qq.com>"

Gerrit代码评审流程

 

 

 

 

 

 

3>.点击"add"添加评审者

[root@node201.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/gerrit/soft/etc/gerrit.config
[gerrit]
        basePath = git
        serverId = d3dfa4e4-9c2c-4203-abfc-10bca465fa65
        canonicalWebUrl = http://172.30.1.201:8080
        ui = polygerrit
        enableGwtUi = true
[database]
        type = mysql
        hostname = node201.yinzhengjie.org.cn
        port = 3306
        database = gerrit
        username = gerrit
[index]
        type = LUCENE
[auth]
        type = ldap
        gitBasicAuthPolicy = HTTP
[receive]
        enableSignedPush = false
[sendemail]
        smtpServer = smtp.qq.com
        smtpServerPort = 465
        smtpEncryption = SSL
        smtpUser = y1053419035@qq.com
        from = y1053419035@qq.com
[container]
        user = gerrit
        javaHome = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64/jre
[sshd]
        listenAddress = node201.yinzhengjie.org.cn:29418
[httpd]
        listenUrl = http://node201.yinzhengjie.org.cn:8080/
[cache]
        directory = cache
[ldap]
        server = ldap://node202.yinzhengjie.org.cn:389
        username = cn=Manager,dc=yinzhengjie,dc=org,dc=cn
        accountBase = ou=People,dc=yinzhengjie,dc=org,dc=cn
        groupBase = ou=Group,dc=yinzhengjie,dc=org,dc=cn
[root@node201.yinzhengjie.org.cn ~]# 
[root@node201.yinzhengjie.org.cn ~]# 
[root@node201.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/gerrit/soft/etc/gerrit.config    #添加成功后,相应的评审者会收到邮件

相关文章:

  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
猜你喜欢
  • 2022-12-23
  • 2021-12-20
  • 2021-10-21
  • 2021-09-15
  • 2021-05-26
  • 2022-12-23
  • 2021-05-11
相关资源
相似解决方案