Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 36 ยท Projects and Merge Requests

Code Review and Approvals

Review code in GitLab merge requests: inline comments, threads, suggestions, reviewers, approval rules, code owners and the checks that gate a merge.

Review is where a merge request earns its value. A second pair of eyes catches bugs, spreads knowledge and keeps the codebase consistent. GitLab gives reviewers structured tools: inline comments grouped into threads, one-click suggestions, review submission and approval rules that can require specific people to sign off.

Reviewing as a reviewer

Open the Changes tab of the merge request. Hovering a line number shows a comment icon. Click it and write your remark. You can also select a range of lines to comment on several at once.

Instead of sending each comment immediately, choose Start a review. Your comments stay as pending drafts that only you can see. When you finish, press Submit review. The author receives a single notification with all comments, instead of twenty emails, and you can add a summary and approve in the same step.

A comment is a thread: a conversation that can be replied to and then marked resolved. Resolving says "this has been dealt with". Projects can require that all threads are resolved before merging, which prevents forgotten feedback from slipping through.

Suggestions

A reviewer can propose an exact change. In the comment editor, click the Insert suggestion button, or write a fenced block yourself:

MARKDOWN
```suggestion:-0+0
return items.length === 0;
```

The author sees a diff of the proposed replacement and clicks Apply suggestion. GitLab creates a commit with the change on the author's branch, so a typo fix costs two clicks rather than a round trip. Several suggestions can be batched into one commit.

What to look for

  • Correctness: does it do what the issue asks, including edge cases?
  • Tests: are new behavior and bug fixes covered?
  • Readability: can you understand it without the author present?
  • Safety: input validation, secrets, permissions.
  • Scope: unrelated changes belong in another MR.

Be kind and specific. Prefix non-blocking remarks ("nit:") so the author knows what must change and what is optional. Ask questions rather than issue commands when you are unsure.

Reviewing as an author

  1. Read your own diff first. You will find mistakes before anyone else does.
  2. Add comments on tricky lines to explain intent.
  3. Request reviews from the right people using the Reviewers field. GitLab can suggest reviewers based on who changed the same code.
  4. Respond to every thread: either push a fix and resolve it, or explain why not.
  5. Re-request review after you push changes. The reviewer's name has a Request review icon for this.

Do not resolve a thread on a reviewer's behalf unless the project's convention allows it. Many teams let the original commenter resolve.

Approvals

An approval is a formal "I'm happy with this". In the Free tier, anyone with permission can approve an MR and the count is shown. In Premium and Ultimate you can make approval required.

Under project Settings, in the merge request approvals area, you create approval rules:

  • A rule has a name, a number of required approvals, and eligible approvers (users or groups).
  • Several rules can apply at once: for example one approval from the Backend group and one from Security if certain files change.
  • Settings can prevent authors from approving their own work and prevent committers from approving, and can reset approvals when new commits are pushed.

Code owners extend this idea to files. A CODEOWNERS file in the repository (at the root, in docs/, or in .gitlab/) maps paths to people or groups:

TEXT
# Everything in the payments directory needs the payments team
/src/payments/   @acme/payments-team

# Documentation
*.md             @grace

[Security]
/src/auth/       @acme/security-team

When a merge request touches a matching path, the owners become eligible (and, if you enable it, required) approvers. Sections in square brackets group rules. The stand-in below evaluates whether a merge request has enough approvals under rules of this kind.

Python Stand-in: is this merge request approved?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Other gates before merging

Besides approvals, the merge request widget can be blocked by:

  • Pipelines must succeed (a project setting): the latest pipeline must pass.
  • All threads must be resolved.
  • Merge conflicts with the target branch.
  • Draft status.
  • Merge checks for status checks: external services (Ultimate) that must report success.
  • Blocking merge requests: a dependency on another MR merging first.

Teams usually combine "pipelines must succeed", "resolve all threads" and at least one approval. The next stand-in lists the blockers for a set of conditions, mirroring the logic of the widget.

Python Stand-in: why is the merge button disabled?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Healthy review culture

  • Aim to review within a working day; stale MRs rot and conflict.
  • Review the tests as carefully as the code.
  • If a discussion exceeds a few comments, talk face to face and write down the conclusion in the thread.
  • Automate the boring parts (formatting, linting, tests) in the pipeline so humans focus on design.
  • Keep MRs small enough that a good review is possible, as described in Merge Requests Basics.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why use Start a review instead of single comments?

    A review batches your draft comments so the author gets one notification when you submit.
  2. 2. What does Apply suggestion do?

    GitLab commits the proposed edit to the author's branch.
  3. 3. What does a CODEOWNERS file define?

    CODEOWNERS maps file patterns to owners; for changes touching those paths the owners review and may be required to approve.
  4. 4. Which is a typical gate that can block the merge button?

    Projects can require all threads to be resolved, along with passing pipelines and approvals.

Summary

  • Review inline in the Changes tab, batch comments with a review, and resolve threads when handled.
  • Suggestions let reviewers propose exact changes that authors apply in one click.
  • Approval rules (Premium and above) require a set number of approvals from chosen people; Free tiers allow optional approvals.
  • CODEOWNERS ties paths to owners.
  • Combine approvals, successful pipelines and resolved threads as merge gates.

Next: Merge Methods and Protected Branches