CODEOWNERS
Ensure that a project has a valid CODEOWNERS file. On the default branch, the
component creates the file or updates it when the configured content differs.
It then checks GitLab syntax, verifies that path patterns match tracked files,
and confirms that referenced users, groups, group aliases, email addresses, and
role owners are eligible for the project.
Store a token with api scope in a protected, masked CI/CD variable named
GITLAB_TOKEN. The token must be allowed to commit to the default branch and
read the project, its eligible users and groups, and member email addresses when
email owners are used.
Add default ownership
Include the component in .gitlab-ci.yml:
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/codeowners@stable
The first default-branch pipeline writes this file to CODEOWNERS:
# Specify Code Owners, read more at https://docs.gitlab.com/user/project/codeowners/
[Default]
* @@maintainer @@owner
The API commit starts another default-branch pipeline. That pipeline finds the same content and does not create another commit. On other protected refs, the job validates the file without writing it.
Configure ownership
Set codeowners to the complete file content. Set path to use
docs/CODEOWNERS or .gitlab/CODEOWNERS instead of the repository root.
include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/codeowners@stable
inputs:
codeowners: |
/docs/ @documentation
/src/ @application-team
path: .gitlab/CODEOWNERS
The default override: true updates an existing file when it differs. Set
override: false to preserve existing content and only create a missing file.
The preserved file is still validated.
Set token-variable to use a differently named CI/CD variable. Set
check-paths: false when intentionally declaring ownership for files that do
not exist yet.
Inputs
| Name | Description | Default | Type |
| --- | --- | --- | --- |
| check-paths | Require every non-exclusion CODEOWNERS path pattern to match a tracked file. | true | boolean |
| codeowners | CODEOWNERS file content written to the default branch. | # Specify Code Owners, read more at https://docs.gitlab.com/user/project/codeowners/ [Default] * @@maintainer @@owner | string |
| name | Name of the CODEOWNERS job. | project | string |
| needs | Jobs required before validation. | [] | array |
| override | Replace an existing CODEOWNERS file when its content differs. | true | boolean |
| path | Repository-relative CODEOWNERS path to ensure and validate. | CODEOWNERS | string |
| ref | Repository branch or tag containing the CODEOWNERS file. | $CI_COMMIT_REF_NAME | string |
| rules | Rules controlling when CODEOWNERS validation runs. | [{"if":"$CI_COMMIT_REF_PROTECTED == \"true\"","when":"on_success"}] | array |
| stage | Stage where CODEOWNERS validation runs. | lint | string |
| tags | Runner tags for the validation job. | [] | array |
| timeout | GitLab API timeout in seconds. | 30 | number |
| token-variable | Protected CI/CD variable containing a GitLab token with api scope. | GITLAB_TOKEN | string |