Guest mode. You can read posts without signing up. Comments, ratings, job contacts and your own posts open after you sign up and accept the rules. What is Kommit →

Редакция КоммитРедакция портала
commit ca6112c · 15 days ago

Git for the team, part 3: code review and merge request — rules, templates, CODEOWNERS, and protected branches

🌐 Machine-translated from Russian. Show original

In this part:

Why review code#

A review is not a "supervisor check," but a way to:

  • catching mistakes before selling when to fix them is the cheapest;
  • to spread knowledge: at least two people know about each section of the code;
  • maintain a unified style and architecture;
  • to teach beginners on real problems.

A merge request (MR, on GitHub — pull request) is a "merge my branch into main" request with discussion, diff, CI results, and a Merge button.

Rules worth agreeing on#

For the author:

  • MR is small: up to 300–400 lines of changes. We split a large task into several MR.
  • The title is clear without revealing the code: "Sales Report: Branch Filter (#142)."
  • In the description: what has been done, why, how to check, screenshots for the interface.
  • Before sending — I read my diff myself, CI is green.
  • Not ready yet — mark MR as Draft (Mark as draft button or prefix Draft: in the title): it cannot be accidentally merged.

For the reviewer:

  • Response within one business day. A review that waits a week kills the entire process.
  • First the meaning and architecture, then the details. Style and formatting are the concerns of the linter, not the person.
  • Write specifically and to the point: not "bad," but "here is N+1 query to the database, remove the sample from the loop."
  • Separate the mandatory and the wishes: prefixes nit: (small thing), question:, blocker:.
  • Suggest editing with the Insert suggestion button — the author will apply it with one click.

For the team:

  • At least one approving reviewer, for critical modules — two.
  • The author does not leak their MR without approval (except for agreed exceptions, such as typos in documentation).
  • Threads must be resolved before merging.

Merge request template#

Create a .gitlab/merge_request_templates/Default.md file in the repository — GitLab will insert it into each new MR (works in all editions, including the free one; the file must be in the default branch):

## Что сделано

<!-- Кратко, 1–3 пункта -->

## Зачем

Задача: #

## Как проверить

1.
2.

## Чек-лист автора

- [ ] Самостоятельно просмотрел дифф
- [ ] Добавлены или обновлены тесты
- [ ] Миграции базы обратимы или согласованы
- [ ] Нет секретов, паролей и токенов в коде
- [ ] Обновлена документация / README

You can create several templates (Bugfix.md, Release.md) — they are selected from the list when creating MR. Task templates in .gitlab/issue_templates/also work.

Protected branches#

Settings → Repository → Protected branches → branch main (and production, if available):

ParameterValue
Allowed to mergeMaintainers (or Developers + Maintainers)
Allowed to push and mergeNo one — only via MR
Allowed to force pushoff

Now, in main , you can't start directly and you can't rewrite history.

Additionally, in Settings → Merge requests:

  • Pipelines must succeed — MR cannot be merged with red CI;
  • All threads must be resolved — cannot be merged with open discussions;
  • Delete source branch by default — branches do not dig;
  • Squash commits when merging — Encourage or Require.

Approvals and CODEOWNERS#

Here, the GitLab editorial is important:

CapabilityFree (CE)Premium / Ultimate
Apply button, assign reviewers✅✅
Approvals block merging❌ approval only "for information"✅ rule: "N approvals required from group X"
CODEOWNERS❌✅
Mandatory code owner approval on the secure branch❌✅

That is, in free GitLab, approval is a team agreement, not a technical limitation. A working option for CE: only Maintainers (through Protected branches) can merge MRs, and they only merge approved MRs.

CODEOWNERS file (Premium and above, as well as GitHub, Gitea, Forgejo)#

GitLab searches for a file in the root, docs/ , or .gitlab/ (the first found one is taken):

# Кто отвечает за какие части кода
*                    @team-lead
/src/payments/       @ivanov @petrova
/db/migrations/      @dba-team
*.tf                 @devops
/docs/               @tech-writer

When files are changed in /src/payments/ , GitLab automatically assigns owners as reviewers, and when the Code owner approval option is enabled on a protected branch, it prevents merges without their approval.

Let the robot check the routine#

The person in the review should not look for missing gaps. Give this to CI (detailed — Git for the team, part 5: GitLab CI in practice — tests, building the Docker image, and deploying to the server):

CheckingTools
FormattingPrettier, Black, gofmt, dotnet format
LinterESLint, Ruff, golangci-lint, BSL Language Server (1C)
TestsJest, Vitest, pytest, Vanessa / YAxUnit (1C)
Secrets in Gitleaks codebuilt-in GitLab Secret Detection
Vulnerable dependenciesnpm audit, Trivy, Dependency Scanning

For local verification before the commit — pre-commit hooks ( pre-commit.com framework or Husky for JS).

How to understand if a review is working#

MetricReference
Time until the reviewer's first response< 1 business day
Time from opening to MR fusion1–3 days
Average MR< 400 lines
Share of MR merged without review~0%

Merge time and deployment frequency are DORA metrics; they are analyzed in the editorial article "KPIs for the IT Department: What to Measure to Improve Performance, Not Reports."

Part 3 checklist#

  • Review rules are recorded: MR size, response time, who is leaking
  • There is a .gitlab/merge_request_templates/Default.md template
  • main protected: push — No one, force push off
  • Included "Pipelines must succeed" and "All threads must be resolved"
  • Linters and tests run in CI, not 'by eye'

It's time to launch your GitLab: Git for the team, part 4: your GitLab CE on Ubuntu 24.04 — installation, HTTPS, email, backups, and runners.

Comments 00 участников · 0 гостей🔒 Rate and discuss after signing up

Comments · 0

No comments yet.Sign in to comment, rate and see all comments.