Gitlab do the code review Gitlab do the code review

Gitlab do the code review

Code review is a means to protect the quality of the code, but also a way of developing code review technical exchanges among members, although it will take some time, but the team, the thing overall is more good than harm. How to use existing tools in the form of code review process and norms within the team, team leader or technical problem managers need to consider. This Share based on one kind of code review process Gitlab merge codes for reference and discussion. If a better way to welcome the exchange.

1. Set member roles

First, you need to be allocated to members of the team role, select a group in Gitlab groups, and then click the Members on the left menu bar, you can add or edit a member of a role in the Members page, as shown below.

group members

 

Which role includes the following categories:

  • Guest: minimum rights, basic viewing functionality
  • Reporter: can only be viewed, not push
  • Developer: can push, but also merge unrestricted branch
  • Master: In addition to the migration project, delete and other administrative privileges no other rights are basic
  • Owner: maximum authority, including the migration project, delete and other management authority

Details Permissions Reference:  https://docs.gitlab.com/ee/user/permissions.html

Determine the level of technical team, experienced members for the better Master, responsible for merger review and the branch code; the other members of the Developer, submit merge requests, accepted review comments; can review each other Master.

 

2. Configure the branch protection

Project page left menu bar Settings -> Repository, enter "Protected Branches" branch protection portion is configured, as shown in FIG.

Branch protection

在这里可以针对每个分支,设置允许什么角色可以merge,允许什么角色可以push,选项包括三个:“Masters”, “Developers + Masters”, “No one”。这里设置成只允许master可以直接push与merge这几个常设分支的代码。(如果更严格一点,可以将“Allowed to push”设置成“No one”)

 

3. 代码review流程

3.1. 开发(开发者负责)

  1. 本地切到develop分支, 拉取最新代码(相关命令如下,GUI工具操作自行查相关文档)
    git branch #查看当前位于哪个分支,前面打星号即为当前分支
    git checkout develop   #切换到develop分支
    git pull  #拉取最新代码
  1. 从develop分支切出子分支
    git checkout -b feature-1101  #从当前分支切出子分支,命名为"feature-1101"
  1. 编码、本地自测完之后,提交子分支到远程仓库
    git add *  #加入暂存区
    git commit -m "commit msg" #提交到本地仓库
    git push origin feature-1101 #提交到远程仓库

 

3.2 发起Merge请求(开发者负责)

 

  1.  在项目主页面,依次点击左侧“Merge Requests”(下图1),“New merge request”(下图2),打开新建Merge请求页面3.2 发起Merge请求(开发者负责)

Merge Request

 

  1. 在新建Merge请求页面,选择merge的源分支,及目标分支,如下图源分支为“feature-1101”,目标分支为“develop”,点击“Compare branches and continue”按钮进入对比与提交页面

New Merge Request

 

  1. 在对比与提交页面,可以点击“Changes” tab查看本次修改(这里我为了演示,只是加了两个换行),确认无误,点击“Submit merge request”按钮,提交merge请求

Contrast modification

  1. 提交之后,将结果页面的浏览器地址发到团队即时通讯群(如钉钉),并@相应的同事申请review

3.3 代码Review(code reviewer负责)

  1. 负责代码Review的同事收到申请后,点击merge请求地址,打开页面,查看“Changes”。这里可通过“Inline”单边查看,也可以通过“Side-by-side”两个版本对比查看

Contrast modification

 

  1. review完成后,若无问题,则可点击”Merge”按钮完成merge,同时可删除对应的子分支“feature-1101”;若有问题,则可点击“Close merge request”按钮关闭该merge请求(也可以不关闭复用该merge请求),同时通知开发者进行相应调整,重新提交代码发起merge请求(如果之前没关闭merge请求,则刷新即可看到调整)。

3.4 冲突解决(开发者负责)

  1. merge的时候,可能存在代码冲突,这时,开发者可从develop分支重新拉取最新代码进行本地merge, 解决冲突后重新提交代码进行review
    Copy the code
    git pull origin develop #在当前子分支拉取develop分支的最新代码进行本地merge
    
    # 解决冲突代码
    
    # 提交
    git add *
    git commit -m "fix merge conflict"
    git push origin feature-1101
    Copy the code
  1. 自行解决不了时,寻求协助

 

4. 借助阿里钉钉机器人来改善体验

前面流程中提醒code reviewer是需要开发者自己来发消息通知的,可不可以把这个流程自动化。我们可以借助Gitlab的webhook与钉钉机器人来实现。

  1. In the top right click nails group "...", the group set open, the robot group click Add robot, the robot will display type can be added, as shown in FIG.

Nails robot

  1. Select Gitlab, click Add, enter the name of the robot, such as "Gitlab", click Done That created a robot Gitlab of nails. Back to the "group robot" window, the robot will be able to see Gitlab just created, as

Nails robot list

      Click the gear button to enter the settings page, you can see webhook address, click Copy to copy webhook address the robot. Figure

Nails robot webhook

  1. In Gitlab project home page to enter the Settings -> Integrations, copy the URL address to the box in front of webhook, Trigger section, select "Merge request events" (do not hook too much, or too little reminder harassment), then click on the "Add webhook "It's finished. Figure

GitlabWebhook

  1. When developers submit merge requests, nailing robot will be issued to inform the group nails, code reviewer click on the link in the message to enter the page to code review, review is completed, after which the branch merge, nailing robot will be issued message (merge all events related issues a message). Figure

Robot nail notice

 

5. Summary

Teamwork, process, standardize very important, different groups may have different applicable procedures and specifications. Share this article based on the code review process Gitlab group with Ali nails robot, hope to have a certain reference value for the R & D team collaboration, are also welcome to explore and exchange.





My personal blog address: http://blog.jboost.cn
my headline space:  https://www.toutiao.com/c/user/5833678517/#mid=1636101215791112

Guess you like

Origin www.cnblogs.com/Leo_wl/p/11071714.html