目录

目录

1、前言

2、角色权限

3、强制代码审查

一、设置受保护分支

二、创建及批核Merge Request

三、历史查询


1、前言


团队目前在日常开发工作中都是在线下进行代码审查,但是这样的模式根本无法做到过程留痕。因此,需要使用GitLab的Merge Request或者Gerrit这样的工具进行过程管理。这里详述一下如何通过Merge Request进行线上的代码审查。

2、角色权限


首先,在GitLab中的角色分为以下5种:Guest、Reporter、Developer、Maintainer、Owner。具体权限可以参考官方文档

https://docs.gitlab.com/ee/user/permissions.html

具体的权限可以参考以下:

ActionGuestReporterDeveloperMaintainerOwner*
Download project✓ (1)
Leave comments✓ (1)
View allowed and denied licenses ✓ (1)
View License Compliance reports ✓ (1)
View Security reports ✓ (3)
View Dependency list ✓ (1)
View License list ✓ (1)
View licenses in Dependency list ✓ (1)
View Design Management pages
View project code✓ (1)
Pull project code✓ (1)
View GitLab Pages protected by access control
View wiki pages
See a list of jobs✓ (3)
See a job log✓ (3)
Download and browse job artifacts✓ (3)
Create new issue✓ (1)
See related issues
Create confidential issue✓ (1)
View confidential issues(2)
View Releases✓ (6)
View requirements 
Manage user-starred metrics dashboards (7)
Assign issues 
Label issues 
Set issue weight 
Lock issue threads 
Manage issue tracker 
Manage related issues  
Manage labels 
Create code snippets 
See a commit status 
See a container registry 
See environments 
See a list of merge requests 
View project statistics  
View Error Tracking list 
Create new merge request 
View metrics dashboard annotations 
Create/edit requirements  
Pull packages  
Publish packages   
Upload Design Management files  
Create/edit/delete Releases  
Create new branches  
Push to non-protected branches  
Force push to non-protected branches  
Remove non-protected branches  
Assign merge requests  
Label merge requests  
Lock merge request threads  
Approve merge requests (9)  
Manage/Accept merge requests  
Create new environments  
Stop environments  
Enable Review Apps  
Add tags  
Cancel and retry jobs  
Create or update commit status  ✓ (5)
Update a container registry  
Remove a container registry image  
Create/edit/delete project milestones  
Use security dashboard   
View vulnerability findings in Dependency list   
Create issue from vulnerability finding   
Dismiss vulnerability finding   
View vulnerability   
Create vulnerability from vulnerability finding   
Resolve vulnerability   
Dismiss vulnerability   
Apply code change suggestions  
Create and edit wiki pages  
Rewrite/remove Git tags  
Manage Feature Flags   
Create/edit/delete metrics dashboard annotations  
Use environment terminals   
Run Web IDE’s Interactive Web Terminals    
Add new team members   
Enable/disable branch protection   
Push to protected branches   
Turn on/off protected branch push for devs   
Enable/disable tag protections   
Edit project   
Edit project badges   
Share (invite) projects with groups   ✓ (8)✓ (8)
Add deploy keys to project   
Configure project hooks   
Manage Runners   
Manage job triggers   
Manage CI/CD variables   
Manage GitLab Pages   
Manage GitLab Pages domains and certificates   
Remove GitLab Pages   
Manage clusters   
Manage Project Operations   
View Pods logs   
Manage license policy    
Edit comments (posted by any user)   
Manage Error Tracking   
Delete wiki pages   
View project Audit Events   
Manage push rules   
Manage project access tokens    
Switch visibility level    
Transfer project to another namespace    
Rename project    
Remove fork relationship    
Remove project    
Archive project    
Delete issues    
Delete merge request    
Disable notification emails    
Force push to protected branches (4)     
Remove protected branches (4)     
View CI\CD analytics 
View Code Review analytics  
View Insights 
View Issues analytics 
View Repository analytics 
View Value Stream analytics

 

       从上图可以看出来,Maintainer能够push代码到受保护分支,而Developer只能创建Merge Request,这就为团队推行强制代码审查并做到有迹可循提供了技术保证。

3、强制代码审查


一、设置受保护分支


通过菜单 Project -> Settings -> Repository -> Protected Branches,然后按照下图步骤设置,最终可以得到第十步的结果:

二、创建及批核Merge Request
我们把本地修改的代码提交到个人远程分支上,并想把个人分支合并到某个Dev分支上用于SIT提测即可参考以下步骤。这里用从dev_sp16_man 合并到 Dev_Sprint16_Kid 作为例子。

第一步:Team1_Dev(开发人员)创建MR并提交,MR主要填写以下5个参数:(同步你可以根据团队情况选择勾选【remove source branch when merge request is accepted】)

Title
Description
Assignee
Source branch
Target branch


第二步:Team1_Leader登录,在【Merge Request】的角标已经提醒有一个request需要审核。

然后,在点击该merge request后,可以通过GitLab自带的Web IDE或者下载到本地IDE进行查看。

第三步:在代码审核无误后,可以添加comment并点击【Merge】进行代码合并,可以看到这时候的左上角状态仍然是【Open】。

第四步:在点击【Merge】后,可以看到代码合并已经成功,这时候左上角状态变为【Merged】。

三、历史查询
通过菜单 Project 选择你想进入的项目,然后点击【Merge Request】,然后再点击【All】即可展示所有的代码审查历史,这样就能在流程层面保证所有的代码合并是经过审核的,并可以做到有迹可循。

 

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐