doc/development/code_review.md
All merge requests for GitLab CE and EE must go through code review to ensure the code is effective, understandable, maintainable, and secure.
Before you begin, familiarize yourself with the contribution acceptance criteria.
Have your code reviewed by a reviewer from your group or a domain expert.
For small, straightforward changes, you can skip the reviewer step and go directly to a maintainer. Examples of small and straightforward changes:
Otherwise, have a reviewer in each category the MR touches before passing
to a maintainer. For security assistance, include @gitlab-com/gl-security/appsec.
After the reviewer approves, a maintainer reviews and merges. The last required approver merges.
For CODEOWNERS-required approvals, seek domain-specific approvals before generic ones. Domain-specific approvers who are also maintainers should review both aspects and approve once.
As described in the section on the responsibility of the maintainer below, you are recommended to get your merge request approved and merged by maintainers with domain expertise. The optional approval of the first reviewer is not covered here. However, your merge request should be reviewed by a reviewer before passing it to a maintainer as described in the overview section.
| If your merge request includes | It must be approved by a |
|---|---|
~backend changes <sup>1</sup> | Backend maintainer. |
~database migrations or changes to expensive queries <sup>2</sup> | Database maintainer. Refer to the database review guidelines for more details. |
~workhorse changes | Workhorse maintainer. |
~frontend changes <sup>1</sup> | Frontend maintainer. |
~UX user-facing changes <sup>3</sup> | Product Designer. Refer to the design and user interface guidelines for details. |
| Adding a new JavaScript library <sup>1</sup> | - Frontend Design System member if the library significantly increases the bundle size. |
More information about license compatibility can be found in our GitLab Licensing and Compatibility documentation. | | A new dependency or a file system change | - Distribution team member. See how to work with the Distribution team for more details.
~documentation or ~UI text changes | Technical writer based on assignments in the appropriate DevOps stage group. |
| Changes to development guidelines | Follow the review process and get the approvals accordingly. |
| End-to-end and non-end-to-end changes <sup>4</sup> | Software Engineer in Test. |
| Only End-to-end changes <sup>4</sup> or if the MR author is a Software Engineer in Test | Quality maintainer. |
| A new or updated application limit | Product manager. |
| Analytics Instrumentation (telemetry or analytics) changes | Analytics Instrumentation engineer. |
| A new service to GitLab (Puma, Sidekiq, Gitaly are examples) | Product manager. See the process for adding a service component to GitLab for details. |
| Changes related to authentication | Manage:Authentication. Check the code review section on the group page for more details. Patterns for files known to require review from the team are listed in the in the Authentication section of the CODEOWNERS file, and the team will be listed in the approvers section of all merge requests that modify these files. |
| Changes related to custom roles or policies | Manage:Authorization Engineer. |Specs other than JavaScript specs are considered ~backend code. Haml markup is considered ~frontend code.
However, Ruby code in Haml templates is considered ~backend code. When in doubt, request both a frontend and
backend review.
For Haml template changes specifically:
project_id: @project&.to_global_id) would benefit from a backend review for Ruby logic
correctness and frontend review for the component integration.We encourage you to seek guidance from a database maintainer if your merge request is potentially introducing expensive queries. It is most efficient to comment on the line of code in question with the SQL queries so they can give their advice.
User-facing changes include both visual changes (regardless of how minor), and changes to the rendered DOM which impact how a screen reader may announce the content. Groups that do not have dedicated Product Designers do not require a Product Designer to approve feature changes, unless the changes are community contributions.
End-to-end changes include all files in the qa directory.
Understand why the change is necessary (fixes a bug, improves the user experience, refactors the existing code). Then:
**non-blocking:**). When only non-blocking suggestions remain,
move the MR to the next stage rather than waiting.[!warning] If the merge request is from a fork, also check the additional guidelines for community contributions.
GitLab is used in a lot of places, from Omnibus packages, to source installations. GitLab.com itself is a large Enterprise Edition instance. This has some implications:
You are the directly responsible individual (DRI) for finding the best solution. Stay as the assignee throughout the review lifecycle. If you cannot set yourself as an assignee, ask a reviewer to do it.
Do not submit a merge request that is too large, fixes multiple issues, has high complexity, or implements more than one feature.
If the MR touches multiple CODEOWNERS sections, to minimize the approvals needed consider splitting the MR by concerns to parallelize reviews. Before requesting a maintainer review, confirm:
Self-review your MR following the Code Review guidelines. Add inline comments on lines where you made decisions or trade-offs, or where context helps the reviewer understand the code.
Involve domain experts, product managers, UX designers, and database specialists as appropriate. If you are unsure whether your MR needs a domain expert review, it does.
For features spanning 10 or more MRs, work with your EM or Staff Engineer to identify consistent maintainer who share the context.
If your MR touches multiple domains, request a review from an expert in each domain.
Before requesting review, add MR diff comments for:
Ensure reviewers have access to any projects, snippets, or assets needed to validate the solution.
When assigning reviewers, comment to specify which domain each reviewer should focus on. This avoids ambiguity when a team member has expertise in multiple areas. For examples, see MR 75921 and MR 109500.
Only add TODO comments to source code if a reviewer requires it.
If you add a TODO, include a link to the relevant issue.
Write comments that explain why, not only what the code does.
Request maintainer reviews only when tests pass. If tests are failing, explain why in a comment. Contact maintainers by email or Slack only for immediate requests. In all other cases, adding them as a reviewer is sufficient.
Reviewers are responsible for reviewing the specifics of the chosen solution.
If unavailable within the Review-response SLO, inform the author, find a replacement using the Review Workload Dashboard, and assign them.
When confident the MR meets all contribution acceptance criteria:
@ mention the author to notify them.Maintainers are responsible for the overall health, quality, and consistency of the GitLab codebase. Their reviews focus on architecture, code organization, separation of concerns, tests, DRYness, consistency, and readability.
Maintainers are the DRI for ensuring MRs reasonably meet acceptance criteria.
A maintainer makes sound judgements when evaluating the impact of an MR. If a maintainer feels that an MR is not able to merged, it is their responsibility to say so. The maintainer is also the expert adviser who knows when to pull in others for a second opinion.
When a maintainer approves an MR, they are taking responsibility alongside the author. This means that when there is a production incident, the maintainer may get paged to help resolve issues.
Certain merge requests may target a stable branch. For an overview of how to handle these requests, see the patch release runbook.
Domain experts are team members who have substantial experience with a specific technology, product feature, or area of the codebase. Team members are encouraged to self-identify as domain experts and add it to their team profiles.
When self-identifying as a domain expert, it is recommended to assign the MR changing the .yml file to be merged by an already established Domain Expert or a corresponding Engineering Manager.
We make the following assumption with regards to automatically being considered a domain expert:
We default to assigning reviews to team members with domain expertise for code reviews. UX reviews default to the recommended reviewer from the Review Roulette. Due to designer capacity limits, areas not supported by a Product Designer will no longer require a UX review unless it is a community contribution. When a suitable domain expert isn't available, you can choose any team member to review the MR, or follow the Reviewer roulette recommendation (see above for UX reviews). Double check if the person is OOO before assigning them.
To find a domain expert:
git log <file>.git log <file>.https://gitlab.com/gitlab-org/gitlab/-/commit/<SHA>.[!note] Reviewer roulette is an internal tool for GitLab.com, not available on customer installations.
The Danger bot picks a reviewer and maintainer for each codebase area your MR touches. Override the suggestion if you know a better fit.
The roulette skips people whose status contains OOO, PTO, Parental Leave, Friends and Family, or Conference, or who are at review capacity (set via a number status emoji: 2️⃣–5️⃣).
This checklist encourages the authors, reviewers, and maintainers of merge requests (MRs) to confirm changes were analyzed for high-impact risks to quality, performance, reliability, security, observability, and maintainability.
Using checklists improves quality in software engineering. This checklist is a straightforward tool to support and bolster the skills of contributors to the GitLab codebase.
For further quality guidelines, see testing.
~ux, ~frontend, ~backend, and ~database labels accordingly.Flaky test '<path/to/test>' was found in the list of files changed by this MR. but can be in jobs that pass with warnings.~security label and you have @-mentioned @gitlab-com/gl-security/appsec.@gitlab-com/gl-security/appsec.dangerbot comments, and complete the acceptance checklist.Before merging:
At least one maintainer must approve before merging. Authors and people who add commits cannot approve their own MR.
If the final approver did not set auto-merge, the MR author may merge their own MR if all required approvals are in place and they have merge rights. This aligns with the GitLab bias for action value.
When ready to merge:
[!warning] If the merge request is from a fork, also check the guidelines for community contributions.
[!warning] Review all changes thoroughly for malicious code before starting a merged results pipeline.
When reviewing community MRs:
Gemfile.lock, yarn.lock). They could introduce malicious packages.@gitlab-com/gl-security/appsec to review before starting any pipeline.When an MR needs changes but the author is unresponsive or unable to finish:
~"coach will finish" label.~"Community contribution" label.Finding the right balance in how deeply to review requires sound judgement. Keep in mind:
danger-review job failed: Check if your MR has more than 20 commits. If so, rebase and
squash. Otherwise, re-run the job.For help, comment @gitlab-bot help on the MR, or ask in the
Community Discord contribute channel.
Based on the thoughtbot code review guide.