Skip to content
Versora

Manual

Checks

CODEOWNERS

6 min read

On this page

The CODEOWNERS file says who owns each part of the code. GitLab and GitHub use this file to request the review (or the approval) of the owners in a merge request. Versora reads the same file, with each service's rules, and shows each file's owner while you work: in the diff, in blame, in the merge request review and in the creation form, where the owners of the changed files become suggested reviewers.

Where the file is looked for

The first CODEOWNERS found applies, in the order of the remote's service:

ServiceOrder
GitLabCODEOWNERS, docs/CODEOWNERS, .gitlab/CODEOWNERS
GitHub.github/CODEOWNERS, CODEOWNERS, docs/CODEOWNERS

With no recognized server, a .github/CODEOWNERS means GitHub; otherwise the GitLab order and syntax apply. For the diff and blame, the working directory version applies; for the merge request, the target branch version. An edit to CODEOWNERS applies on the next lookup.

The owner in the diff and in blame

Where to find it

  • Header of a file's diff: the badge with the owners (for example, "@ana, @time-web +1"), or "No owner".
  • Blame header: the same badge.

Click the badge to see Owners of src/login.ts: each section that matches the file, the rule and the CODEOWNERS line ("Rule src/** · line 12"), the owners with their type (user or group, team, email, project role) and the requirement ("Requires 2 approvals", "Optional"). On GitLab, the note reminds you that "Approval is only required if the target branch is protected with code owner approval."

Who owns this file?

Where to find it

  • Palette (Ctrl+P): "Who owns this file?" (detail: "Owners of src/login.ts", with the file open in the diff or in blame; otherwise, "Owners from CODEOWNERS, with the matching rule and section").
  • Palette: "CODEOWNERS warnings" (detail: "2 warnings in CODEOWNERS").

Step by step

  1. Open "Who owns this file?". With a file open, it's already selected.
  2. In the Owners of a file tab, type part of the path in the File field ("Type part of the path…") and pick it.
  3. The dialog shows the source ("File CODEOWNERS · GitLab rules"), the total number of rules and, for the file, the sections, the rules and the owners.
  4. The Warnings tab (with the count, "Warnings (2)") lists the lines the server doesn't understand.

CODEOWNERS warnings

Each line with a problem appears with the line number and the reason. The warnings are the same ones the server would give:

GitLab

  • "Section header without the closing "]". GitLab ignores the line and the following rules stay in the previous section."
  • "Section without a name. GitLab reports an error; here the following rules stay in the previous section."
  • "Section header doesn't follow [Name][approvals] @owners (…). GitLab uses the section but reports a syntax error."
  • "Invalid number of approvals ("[…]"): 1 applies."
  • "An optional section (^) can't require approvals ([…]): GitLab reports an error and the section stays optional."
  • "Invalid default owner in the header: … (use @user, @group, an email or @@role). Ignored."
  • "Invalid owner: … (use @user, @group/subgroup, an email or @@developer, @@maintainer, @@owner). GitLab ignores it and uses the others."
  • "GitLab doesn't support comments at the end of a line: the text after # is read as owners (any @names there count)."
  • "Rule with no owner and no section default owners: GitLab approves its files automatically."
  • "No valid owner in this rule: its files have no owner in this section."

GitHub

  • "GitHub has no sections: the line is ignored."
  • "GitHub doesn't support # for patterns starting with #: the line is ignored."
  • "GitHub doesn't support ! (exclusion) patterns: the line is ignored."
  • "GitHub doesn't support [ ] character ranges: the line is ignored."
  • "Invalid owner: … (use @user, @org/team or an email). GitHub ignores the whole line."

Both

  • "Line without a file pattern: ignored."
  • "The file has … bytes: GitHub doesn't load a CODEOWNERS this large, so no rule applies." (the GitHub limit is 3 MB)

With no problem at all: "No warnings: GitLab understands every line."

Differences between GitLab and GitHub

GitLabGitHub
Sections[Name], optional ^[Name], with approvals [Name][2] and default ownersnone
Rule that appliesthe last one that matches, within each section (each section contributes its owners)the last one that matches, only one
!pattern exclusionsyesno (line ignored)
Comment at the end of the lineno (the text becomes an owner)yes
Rule without ownerswith no owner and no default owners, GitLab approves automaticallyremoves ownership of the files
Owners@user, @group, @group/subgroup, email, @@developer, @@maintainer, @@owner@user, @org/team, email

Suggested reviewers when creating the merge request

In the Create merge request (or Create pull request) form, the Suggested reviewers (CODEOWNERS) block shows, per section, the owners of the changed files, read from the target branch's CODEOWNERS ("CODEOWNERS on origin/main").

  • The owners (people) of the sections that require approval are already checked, except you.
  • Groups, teams and roles can be expanded with Show members to pick people.
  • "A review will be requested from 2 reviewers when the merge request is created." sums up the choice; with nothing checked, "No reviewer selected."
  • On GitLab Free, the merge request takes only one reviewer ("On GitLab Free a merge request takes a single reviewer.") and nothing comes checked.
  • On GitHub, the author can't be a reviewer of their own pull request.
  • After creating: "!42: review requested from Ana Souza and Bruno Lima."

Files without an owner are counted ("3 changed files have no owner."). With no CODEOWNERS on the target branch, the block doesn't appear. See Create merge request.

In the merge request review

In the review's Changes tab:

  • each file's header shows its owners;
  • the Code owners card sums up, per section, who the owner is and the approval state: "1 of 2 sections approved", "code owner approval complete", "Approved by Ana Souza", "Needs approval (0 of 2)" or "No approval rule on the server";
  • each owner has the + Reviewer button (request a review from them); a group or role asks you to pick people ("@time-web is a group or role: request the review from people in it.");
  • on GitLab Free, "GitLab Free: there's no approval per section; owners are only a suggestion.";
  • when the server has rules that the target's local CODEOWNERS doesn't: "Only on the server (the local target CODEOWNERS may be outdated; fetch first): …".

The review's file list can also be grouped by owner (see Review changes).

What Versora does in git

It only reads CODEOWNERS: from disk, for the diff and blame; from the target branch (a git reference), for the merge request. No file changes. Requesting reviewers uses the GitLab or GitHub API.

Caveats and messages

  • "This repository has no CODEOWNERS (GitLab looks in CODEOWNERS, docs/CODEOWNERS, .gitlab/CODEOWNERS).": the palette commands become unavailable ("This repository has no CODEOWNERS").
  • "docs/CODEOWNERS also exists, but only the first CODEOWNERS found applies.": there's more than one file; only the first one in the order applies.
  • "(remote server not recognized: GitLab rules apply)": the app doesn't know the service and used the GitLab rules.
  • "Couldn't read CODEOWNERS from origin/main (fetch first if the branch is new): …": the target branch isn't in the local repository.
  • "Add the server token in Git servers to pick reviewers.": without a token, reviewers can't be requested.
  • "!42 was created, but the review couldn't be requested: …": the merge request exists; request the review from the review in the app or in the browser.
  • Owners with a problem: "not found on the server", "no user found for this email (only public emails are visible)", "no permission to see it", "not valid on this server".

See also