Skip to content
BETAGuardrails are in beta. The library, the configuration format and the CLI command can still change.

Guardrails / gitlab

Each CODEOWNERS rule names a workable number of owners

gitlab/codeowners-owners-per-rule@v1

Every rule in CODEOWNERS ends up with at least the minimum owners and no more than the maximum, counting the default owners its section header hands down, so review is neither one person's bus factor nor everybody's problem.

Idgitlab/codeowners-owners-per-rule
Versionv1
Categorygitlab
Default severitywarning
Interpreterpython3
Timeout30 seconds
Violations tolerated0
Collectsgitlab

Collectors

This guardrail gathers nothing itself. It depends on the collectors below, which the CLI runs once per build before any check, and reads what they found out of GUARDRAIL_FACTS. A collector that collects nothing skips this guardrail rather than failing it.

CollectorGathersInputs it is given
gitlabWhat GitLab itself reads out of the repository: the .gitlab-ci.yml, read as GitLab writes it, and the CODEOWNERS file, read as sections of rules. For the pipeline, the stages it declares, what it includes, and for every job the stage it sits in, the image and runner tags it asks for, how long it may run, the rules that decide whether it runs at all, and each script section with the variables it interpolates. For CODEOWNERS, every section with whether it is optional and how many approvals it needs, the rules under each, and the owners that apply to the paths a guardrail asks about, resolved per section the way GitLab resolves them. Names and shapes only, never a secret, a variable value or an environment value.pipelines

The inputs above are this guardrail's own, passed straight through. Configuring one in buildnote.json changes what is collected, and two guardrails configured the same way share the one collection.

Configuration

json
{
  "guardrails": {
      "failOn": "error",
      "comment": true,
      "checks": [
          {
              "use": "gitlab/codeowners-owners-per-rule@v1",
              "severity": "warning",
              "with": {
                  "pipelines": ".gitlab-ci.yml,.gitlab-ci.yaml",
                  "minOwners": "1",
                  "maxOwners": "5"
              },
              "exemptions": []
          }
      ]
  }
}

Inputs

InputDescriptionDefaultEnvironment variable
pipelinesComma separated globs naming the GitLab CI files to read..gitlab-ci.yml,.gitlab-ci.yamlGUARDRAIL_INPUT_PIPELINES
minOwnersFewest owners a rule may end up with. A rule ending up with none is left to gitlab/codeowners-no-unowned-rules.1GUARDRAIL_INPUT_MINOWNERS
maxOwnersMost owners a rule may end up with. 0 means no ceiling.5GUARDRAIL_INPUT_MAXOWNERS

How to fix

Adjust the rules named in the violations, or the section header they inherit their owners from. One owner is a single point of failure: when they are on leave the path is unapprovable. A long list is the opposite failure, because GitLab asks all of them and each assumes another will pick it up.

A group owner counts as one:

[Backend][2] @acme/backend
/api/

which is usually the right answer, because membership then lives in the group rather than in this file, and the section's approval count says how many of them have to approve.

More in gitlab

  • gitlab/codeowners-catch-all. A section whose approval is required declares a rule matching every path, so a file nobody thought about still has an owner who has to approve it.
  • gitlab/codeowners-no-unowned-rules. No rule in CODEOWNERS ends up with an empty set of owners, counting the default owners its section header hands down, so no section claims a path it names nobody for.
  • gitlab/codeowners-parses. Every line of CODEOWNERS that is not a comment reads either as a section header or as a rule, so no ownership is silently lost to a line GitLab ignores.
  • gitlab/codeowners-present. The project carries a CODEOWNERS file in one of the three places GitLab reads one from, and at least one section of it declares a rule, so every change has somebody to review it.
  • gitlab/codeowners-team-owned. Every rule in CODEOWNERS ends up owned by at least one GitLab group, so ownership survives the people currently in it.
  • gitlab/job-timeout-set. Every job declares how long it may run, so a hung job is cut off rather than holding a runner until the project's own limit.

All 7 gitlab guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412