简体   繁体   English

如何使用 Gitlab 设置代码审查?

[英]How to set up a code review using Gitlab?

How does one set up a code review using Gitlab?如何使用 Gitlab 设置代码审查? I see it listed as a feature on the Gitlab website, but I can't seem to find instructions on how to set one up (For that matter, any link to a Gitlab user manual would be most appreciated).我看到它被列为 Gitlab 网站上的一项功能,但我似乎找不到有关如何设置的说明(就此而言,任何指向 Gitlab 用户手册的链接都将不胜感激)。

Some of my searching has indicated that 'Merge Requests' are the way to go... but I'm finding them limiting.我的一些搜索表明“合并请求”是要走的路......但我发现它们有限制。 An issued merge request shows all of the commits between one branch and the other.发出的合并请求显示一个分支和另一个分支之间的所有提交。 I seem to only be able to view diffs generated for each individual commit.我似乎只能查看为每个单独提交生成的差异。 For example, let's say I have a file I want to review.例如,假设我有一个要查看的文件。 It is a new file but I've submitted changes to it over 10 commits on a dev branch.这是一个新文件,但我已经在 dev 分支上提交了超过 10 次提交的更改。 If I issue a merge request for that dev branch from integration I see 10 commits each of which show the incremental changes made to the file... I want to review the entire thing.如果我从集成中为该开发分支发出合并请求,我会看到 10 个提交,每个提交都显示对文件所做的增量更改...我想查看整个内容。 It is new!这是新的!

Am I barking up the wrong tree here?我在这里吠错树了吗? Is there an actual code-review tool I can use in GitLab, or are merge requests the way to go, and if they are am I using them incorrectly?是否有我可以在 GitLab 中使用的实际代码审查工具,或者合并请求是否可行,如果是,我是否错误地使用了它们? what's the best way to set up a proper code review here?在这里设置适当的代码审查的最佳方法是什么?

Note: since GitLab 6.4, side-by-side diff view is available: see " pull request 5308 ".注意:从 GitLab 6.4 开始,可以使用并排差异视图:请参阅“ pull request 5308 ”。

(July 2013) (2013 年 7 月) There is no possibility yet to comment on each line though, only at the file level.不过,目前还不可能对每一行进行评论,只能在文件级别进行评论。
Daniel Sokolowski mentions in the comments that Per line comments are now supported (09/2014): Daniel Sokolowski 在评论中提到现在支持每行评论(09/2014):

Your team members can comment on the merge request in general or on specific lines with line comments.您的团队成员可以对合并请求进行一般性评论,也可以对带有行注释的特定行进行评论。

That still can help for code review activity.这仍然有助于代码审查活动。

https://f.cloud.github.com/assets/4224518/1558702/e0fe633a-4fa3-11e3-9388-3f3e445cb6d4.png


6 years later, for GitLab 13.1 (June 2020) : 6 年后,对于GitLab 13.1(2020 年 6 月)

Merge Request Reviews moved to Core合并请求评论移至核心

Originally introduced in GitLab 11.4 as a GitLab Premium feature, Merge Request Reviews allow merge request reviewers to:最初在 GitLab 11.4 中作为 GitLab 高级功能引入,合并请求审查允许合并请求审查者:

  • submit multiple comments at once,一次提交多条评论,
  • cutting down on notification noise for the merge request author, and减少合并请求作者的通知噪音,以及
  • allowing for a more cohesive and streamlined review process.允许更有凝聚力和简化的审查过程。

https://about.gitlab.com/images/13_1/batch_comments.png

Since its introduction, we've re-evaluated its place in our buyer-based pricing model and as part of 13.1 we're excited to announce this feature has now moved to GitLab Core.自推出以来,我们重新评估了它在基于买方的定价模型中的地位,作为 13.1 的一部分,我们很高兴地宣布此功能现已转移到 GitLab Core。

See Documentation and Issue请参阅文档问题


With GitLab 13.9 (February 2021), you also have:使用GitLab 13.9 (2021 年 2 月),您还可以:

Request a follow-up review from a Reviewer要求审稿人进行后续审阅

Merge request authors receive feedback from reviewers .合并请求作者会收到审阅者的反馈 Often, this feedback needs to be re-reviewed to make sure all issues have been appropriately addressed.通常,需要重新审查这些反馈,以确保所有问题都得到了适当的解决。 As the author of the contribution, you need to communicate the need for a follow-up to your reviewer.作为贡献的作者,您需要向您的审稿人传达跟进的需求。

For reviewers who have already reviewed a merge request , you can now request a re-review.对于已经审核过合并请求的审核者,您现在可以请求重新审核。 This request triggers a To-Do item and email notification to alert the user that you need a follow-up review of your contribution.此请求会触发待办事项和电子邮件通知,以提醒用户您需要对您的贡献进行后续审查。

https://about.gitlab.com/images/13_9/create_code_review-request-re-review.png -- 要求审稿人进行后续审查

See Documentation and Issue .请参阅文档问题


With GitLab 13.11 (April 2021)使用GitLab 13.11 (2021 年 4 月)

Add standalone comments to merge request reviews添加独立评论以合并请求评论

When you're reviewing changes, you may want to summarize your feedback, or comment on something unrelated to the specific changes.当您查看更改时,您可能想要总结您的反馈,或评论与特定更改无关的内容。 Reviews in GitLab only allowed commenting on the changes or replying to existing comments, which meant that other kinds of comments had to be made after submitting the review. 评论在GitLab只允许评论更改或答复现有评论,这意味着其他种类的意见提交了审查后作出。

As part of your review process, you can now submit a general comment along with your replies or change-specific comments.作为审核过程的一部分,您现在可以提交一般性评论以及您的回复或特定于更改的评论。 General comments make it simple to provide feedback to the author and use quick actions to update items across the merge request.通用注释使向作者提供反馈并使用快速操作更新合并请求中的项目变得简单。

Thanks to Lee Tickett for the contribution!感谢Lee Tickett的贡献!

https://about.gitlab.com/images/13_11/code-review-add-comment-mr-review.png -- 添加独立评论以合并请求评论

See Documentation and Issue .请参阅文档问题

I've been doing code reviews in Gitlab for over two months with almost no friction.我在 Gitlab 中进行代码审查已经两个多月了,几乎没有任何摩擦。 I've setup rss2email to send email notifications everytime a developer pushes new commits.我已经设置了rss2email以在开发人员每次推送新提交时发送电子邮件通知。 Then I use Gitlab's comment feature for commits to make some comments about the pushed code.然后我使用Gitlab 的comment 功能进行commits 对推送的代码做一些评论。

Unfortunately, Gitlab does not allow comments on files itself, only in commits (just like Github, I guess).不幸的是,Gitlab 不允许对文件本身进行评论,只允许在提交中(就像 Github,我猜)。 Whenever I find myself in a situation that I need to comment something that I've missed in a previous commit, I use the blame tool to find the commit that introduced/changed the code section to be commented.每当我发现自己需要评论之前提交中遗漏的某些内容时,我都会使用blame工具来查找引入/更改要评论的代码部分的提交。

It is far from perfect, but it is working good so far.它远非完美,但到目前为止运行良好。

You can see submitted code in Merge Request for other repository or in current repository.您可以在其他存储库或当前存储库的合并请求中查看提交的代码。
example http://demo.gitlab.com/diaspora/diaspora/commits/master示例http://demo.gitlab.com/diaspora/diaspora/commits/master

Then you can add comments to committed file changes (button Reply ) or to the whole commit然后您可以向提交的文件更改(按钮Reply )或整个提交添加注释

example http://demo.gitlab.com/diaspora/diaspora/commit/42f47626890218a180870bc3f44ec57625b0779c示例http://demo.gitlab.com/diaspora/diaspora/commit/42f47626890218a180870bc3f44ec57625b0779c

The resulting communication is code review .由此产生的交流是代码审查 However, I personally recommend to do code review on one PC with face-to-face communication whenever possible, and use tools for recording results or when more formality is needed.但是,我个人建议尽可能在一台 PC 上进行代码审查,并进行面对面的交流,并使用工具来记录结果或需要更多形式。

For a file revue that has a lot of commits, eghttp://demo.gitlab.com/diaspora/diaspora/blame/master/README.md look at it using blame to understand who did what.对于有很多提交的文件评论,例如http://demo.gitlab.com/diaspora/diaspora/blame/master/README.md使用blame查看它以了解谁做了什么。 However in this view there is no option to communicate and add comments.但是,在此视图中,无法进行交流和添加评论。 I would recommend just add changes as comments in this case.在这种情况下,我建议只将更改添加为注释。

Yes.是的。 Merge requests are how peer reviews are accomplished.合并请求是同行评审的完成方式。

There should be a 'diff' tab that will show the changes of all the commits (mentioned here: http://youtu.be/DyAX8ws5OIc?t=3m2s ).应该有一个“差异”选项卡,将显示所有提交的更改(此处提到:http: //youtu.be/DyAX8ws5OIc?t=3m2s )。

The video also explains nicely how it can be used to peer review.该视频还很好地解释了如何将其用于同行评审。

The normal use-case of code reviews is to review code on a branch before merging into master or similar.代码审查的正常用例是在合并到 master 或类似分支之前审查分支上的代码。 I have a situation where I've developed a project and want all the code to be reviewed by everyone on the team.我有一种情况,我开发了一个项目,并希望团队中的每个人都审查所有代码。

What I did was:我所做的是:

Checkout the first commit, make a change to it, commit and push签出第一个提交,对其进行更改,提交并推送

git co -b FIRST_COMMIT eb67f06c2b3222c0219214b176c41922bc454881
vi README.md
git add README.md
git ci -m "First commit modified so can get full diff against it"
git push --set-upstream origin FIRST-COMMIT

Checkout the last commit, make a change to it, commit and push签出最后一次提交,对其进行更改,提交并推送

git co -b master
vi README.md
git add README.md
git ci -m "Last commit modified so can get full diff against it"
git push --set-upstream origin LAST-COMMIT

On GitLab / GitHub, create a pull request在 GitLab / GitHub 上,创建一个拉取请求

  • It is one merging from LAST_COMMIT to FIRST_COMMIT它是从 LAST_COMMIT 到 FIRST_COMMIT 的合并

Works for me!为我工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM