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

如何使用 Gitlab 设置代码评审?我看到它被列为 Gitlab 网站上的一个功能,但我似乎找不到关于如何设置的说明(就此而言,任何链接到 Gitlab 用户手册将是最受欢迎的)。

我的一些搜索已经表明,“合并请求”的方式去... 但我发现他们限制。发出的合并请求显示了一个分支和另一个分支之间的所有提交。我似乎只能查看为每个单独提交生成的差异。例如,假设我有一个要查看的文件。这是一个新文件,但是我已经在一个 dev 分支上提交了超过10次的更改。如果我从集成中为那个开发分支发出合并请求,我会看到10次提交,每次提交都显示了对文件所做的增量更改... ... 我想回顾一下整个过程。这是新的!

我是不是找错人了?在 GitLab 中是否有一个实际的代码审查工具可以使用,或者合并请求是否正确,如果是,我是否使用错误?在这里设置适当的代码审查的最佳方法是什么?

82925 次浏览

You can see submitted code in Merge Request for other repository or in current repository.
example http://demo.gitlab.com/diaspora/diaspora/commits/master

Then you can add comments to committed file changes (button Reply) or to the whole commit

example 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.

For a file revue that has a lot of commits, e.g. http://demo.gitlab.com/diaspora/diaspora/blame/master/README.md look at it using blame to understand who did what. 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).

The video also explains nicely how it can be used to peer review.

I've been doing code reviews in Gitlab for over two months with almost no friction. I've setup rss2email to send email notifications everytime a developer pushes new commits. Then I use Gitlab's comment feature for commits to make some comments about the pushed code.

Unfortunately, Gitlab does not allow comments on files itself, only in commits (just like Github, I guess). 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.

It is far from perfect, but it is working good so far.

Note: since GitLab 6.4, side-by-side diff view is available: see "pull request 5308".

(July 2013)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):

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):

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:

  • 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.

See Documentation and Issue


With GitLab 13.9 (February 2021), you also have:

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 -- Request a follow-up review from a Reviewer

See Documentation and Issue.


With GitLab 13.11 (April 2021)

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.

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!

https://about.gitlab.com/images/13_11/code-review-add-comment-mr-review.png -- Add standalone comments to merge request reviews

See Documentation and Issue.

The normal use-case of code reviews is to review code on a branch before merging into master or similar. 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

  • It is one merging from LAST_COMMIT to FIRST_COMMIT

Works for me!