在CentOS上进行代码审查前,需先完成GitLab的安装与基础配置。
sudo yum install -y curl policycoreutils openssh-server postfix
sudo systemctl enable sshd && sudo systemctl start sshd # 启用SSH sudo firewall-cmd --permanent --add-service=https --add-service=http # 开放HTTP/HTTPS端口 sudo systemctl reload firewalld # 重载防火墙规则
EXTERNAL_URL
为你的服务器域名/IP,执行:curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash sudo EXTERNAL_URL="http://your-server-ip" yum install -y gitlab-ee
gitlab-ee
替换为gitlab-ce
即可。sudo gitlab-ctl reconfigure # 应用配置 sudo gitlab-ctl restart # 重启GitLab服务
安装完成后,通过浏览器访问http://your-server-ip
,完成管理员账号设置。feature/new-login
):git checkout -b feature/new-login # 创建并切换到新分支 git add . && git commit -m "Add user login functionality" # 提交代码 git push origin feature/new-login # 推送分支到远程仓库
feature/new-login
)和Target branch(目标分支,如main
或develop
)。@mention
(如@dev-user1
)指定审查者,并设置Required approvals(如需要1人批准)。main
)有更新导致冲突,审查者可在MR页面点击Resolve conflicts,直接在线解决冲突后提交;或开发者本地拉取目标分支合并,解决冲突后推送。为防止未经审查的代码直接合并,需配置分支保护规则:
main
),设置: Maintainer
或Owner
角色可合并。通过.gitlab-ci.yml
文件配置自动化任务,确保代码通过测试、代码风格检查等流程后再合并:
stages: - test - lint # 代码风格检查(使用Checkstyle) lint: stage: lint image: openjdk:11 script: - apt-get update && apt-get install -y checkstyle - checkstyle -c /path/to/checkstyle.xml src/ # 单元测试 test: stage: test image: python:3.9 script: - pip install -r requirements.txt - pytest tests/
配置完成后,每次推送代码到源分支,GitLab会自动触发流水线,只有所有任务通过,MR才能被批准。merge_request_template.md
),要求开发者填写变更目的、测试结果等,减少沟通成本。Closes #123
),实现“问题-修复”的闭环管理。通过以上步骤,可在CentOS系统上借助GitLab实现规范的代码审查流程,确保团队代码质量与协作效率。