Gerrit代码评审流程

                                     作者:尹正杰

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

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

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

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

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

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

第五步: 在评分的步骤中:所有被邀请人员和项目权限管理人员,都可以对代码进行评价。结果是"-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: , done
remote: Finding sources: % (/)
remote: Total (delta ), reused (delta )
Receiving objects: % (/), 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
--:--:-- --:--:-- --:--:--
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]#
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# ll .git/hooks/commit-msg
-rw-r--r-- root root Jun : .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 root root Jun : .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
file changed, insertion(+)
create mode 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: , done.
Delta compression using up to threads.
Compressing objects: % (/), done.
Writing objects: % (/), bytes | bytes/s, done.
Total (delta ), reused (delta )
remote: Processing changes: new: , 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

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

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

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

5>.主题修改成功

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

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

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

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

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

[root@node201.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/gerrit/soft/etc/gerrit.config
[gerrit]
basePath = git
serverId = d3dfa4e4-9c2c--abfc-10bca465fa65
canonicalWebUrl = http://172.30.1.201:8080
ui = polygerrit
enableGwtUi = true
[database]
type = mysql
hostname = node201.yinzhengjie.org.cn
port =
database = gerrit
username = gerrit
[index]
type = LUCENE
[auth]
type = ldap
gitBasicAuthPolicy = HTTP
[receive]
enableSignedPush = false
[sendemail]
smtpServer = smtp.qq.com
smtpServerPort =
smtpEncryption = SSL
smtpUser = y1053419035@qq.com
from = y1053419035@qq.com
[container]
user = gerrit
javaHome = /usr/lib/jvm/java-1.8.-openjdk-1.8.0.212.b04-.el7_6.x86_64/jre
[sshd]
listenAddress = node201.yinzhengjie.org.cn:
[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    #添加成功后,相应的评审者会收到邮件

四.评审者进行评审级命令行的追加修改

1>.评审者收到链接后需要登陆Gerrit平台

2>.查看评审信息(需要注意的是,尽管不是评审者本人,也可以看到如下图所示的消息哟~)

3>.review代码

4>.对局部代码进行评论操作

5>.评论代码成功

6>.将代码下载到本地

[root@node203.yinzhengjie.org.cn ~]# git clone "ssh://jason@node201.yinzhengjie.org.cn:29418/yinzhengjie-code"
Cloning into 'yinzhengjie-code'...
remote: Counting objects: , done
remote: Finding sources: % (/)
remote: Total (delta ), reused (delta )
Receiving objects: % (/), done.
[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]# git fetch "http://172.30.1.201:8080/yinzhengjie-code" refs/changes/// && git checkout FETCH_HEAD
remote: Counting objects: , done
remote: Finding sources: % (/)
remote: Total (delta ), reused (delta )
Unpacking objects: % (/), done.
From http://172.30.1.201:8080/yinzhengjie-code
* branch refs/changes/// -> FETCH_HEAD
Note: checking out 'FETCH_HEAD'. You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name> HEAD is now at c1985ca... First Change for review
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]#
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# ll
total
-rw-r--r-- root root Jun : code-review-sample.txt
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]#
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# echo "Change amended" >> a.txt
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]#
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# git commit --amend #随机编辑文件内容
[root@node203.yinzhengjie.org.cn ~/yinzhengjie-code]# git push origin HEAD:refs/for/master
Counting objects: , done.
Delta compression using up to threads.
Compressing objects: % (/), done.
Writing objects: % (/), bytes | bytes/s, done.
Total (delta ), reused (delta )
remote: Processing changes: updated: , done
remote: (I) 6770e65: no files changed, message updated
remote:
remote: Updated Changes:
remote: http://172.30.1.201:8080/#/c/yinzhengjie-code/+/1 SECOND 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]#

7>.我们发现有对应的Changes

8>.我们可以对给代码打分

Gerrit代码评审流程的更多相关文章

  1. Gerrit - 代码评审工具Gerrit简介与安装

    1 - 前言 Code Review 代码评审是指在软件开发过程中,对源代码的系统性检查,改进代码质量,查找系统缺陷,保证软件总体质量和提高开发者自身水平. 简单的说,Code Review是用来确认 ...

  2. Gerrit代码审核服务器搭建全过程

    Gerrit代码审核服务器搭建全过程 转载请标明出处:http://blog.csdn.net/ganshuyu/article/details/8978614 环境:Ubuntu12.xx 1.建立 ...

  3. ubuntu搭建Gerrit代码审核服务器

    谷歌的 Android 开源项目在 Git 的使用上有两个重要的创新,一个是为多版本库协同而引入的 repo,另外一个重要的创新就是 Gerrit —— 代码审核服务器.Gerrit 为 git 引入 ...

  4. 15个最佳的代码评审(Code Review)工具

    代码评审可以被看作是计算机源代码的测试,它的目的是查找和修复引入到开发阶段的应用程序的错误,提高软件的整体素质和开发者的技能.代码审查程序以各种形式,如结对编程,代码抽查等.在这个列表中,我们编制了1 ...

  5. iOS - CodeReview 代码评审

    1.CodeReview Code Review 中文应该译作 "代码审查" 或是 "代码评审",这是一个流程,当开发人员写好代码后,需要让别人来 review ...

  6. Gerrit代码Review实战

    代码审核(Code Review)是软件研发质量保障机制中非常重要的一环,但在实际项目执行过程中,却因为种种原因被Delay甚至是忽略.在实践中,给大家推荐一款免费.开放源代码的代码审查软件Gerri ...

  7. Openstack贡献者须知 2 — 社区工作运作 & 代码贡献流程

    目录 目录 前文列表 订阅邮件列表 Mailing Lists 社区工作运作流程 Openstack 代码贡献流程 PEP8 Python编程风格 查阅相关资源 前文列表 Openstack贡献者须知 ...

  8. CR(Code Review)代码评审如何发挥作用

    在CODE中经常会发起代码评审和进行评审任务,可是根据目前的做法流程,我认为它就是走走形式,为了应付检查,根本没有达到预期的效果,即审查代码质量.学习他人写的代码和提高自身写代码的能力.对此,将从两方 ...

  9. 使用ReSharper打造团队代码检查流程

    首先我想跟大家分享一下我们团队的代码检查流程. 1. 项目经理随时会检查成员的代码,如果发现有不符合规范的代码,会在注释里面加todo.比如,假设leo的代码不符合规范,那么项目经理就会加注释: // ...

随机推荐

  1. ShenZhenXiaoLengHuanYou Technology Co.,Ltd 技术支持网站

    本网页为ShenZhenXiaoLengHuanYou Technology Co.,Ltd 团队的技术支持网址,如果在我们开发的游戏中遇到任何问题,欢迎联系我们! QQ:2535510006 邮箱: ...

  2. hive 字符串截取

    语法 :substr(字段,starindex,len)  下标从 1 开始 测试 ,) from siebel_cx_order limit ; -- -- -- -- -- -- -- -- -- ...

  3. Rust基础

    一:编译器 Rust的编译器叫rustc,类似javac一样,负责将源代码编译成可执行文件或者库文件(.a/.so/.lib/.dll等) 二:核心库和标准库 Rust语言由核心库和标准库组成,核心库 ...

  4. Word 去除文字底纹

    有时候从网页复制的文字有底纹,如何清除呢? 未完 ...... 点击访问原文(进入后根据右侧标签,快速定位到本文)

  5. Scratch学习中需要注意的地方,学习Scratch时需要注意的地方

    在所有的编程工具中,Scratch是比较简单的,适合孩子学习锻炼,也是信息学奥赛的常见项目.通常Scratch学习流程是,先掌握程序相关模块,并且了解各个模块的功能使用,然后通过项目的编写和练习,不断 ...

  6. 快速排序(Quick Sort)C语言

    已知数组 src 如下: [5, 3, 7, 6, 4, 1, 0, 2, 9, 10, 8] 快速排序1 在数组 src[low, high] 中,取 src[low] 作为 关键字(key) . ...

  7. Go基础编程实践(二)—— 类型转换

    bool to string strconv包的FormatBool函数用于将bool转为string package main import ( "fmt" "strc ...

  8. 关于使用KubeSphere中的docker配置Harbor仓库http访问docker login登陆报错的解决办法

    # 先进入harbor目录中,停止harbor docker-compose stop # 然后修改docker相关文件 # 第一种方式:修改/etc/docker/daemon.json { &qu ...

  9. Java jms学习

    /** * <html> * <body> * <P> https://github.com/Jasonandy </p> * <p> Al ...

  10. MVC学习笔记(四)---使用linq多表联查(SQL)

    1.数据库原型(Students表中的ID和Scores表中的StudentID是对应的) 2.实现效果:查询出每个学生各个科目的成绩(用的是MVC学习笔记(三)—用EF向数据库中添加数据的架构) C ...