code_owners.md 4,1 КБ
Newer Older
GitLab Bot's avatar
GitLab Bot включено в состав коммита
1
2
3
4
---
type: reference
---

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
5
# Code Owners **(STARTER)**
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
6

GitLab Bot's avatar
GitLab Bot включено в состав коммита
7
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/6916)
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
8
in [GitLab Starter](https://about.gitlab.com/pricing/) 11.3.
GitLab Bot's avatar
GitLab Bot включено в состав коммита
9
> - [Support for group namespaces](https://gitlab.com/gitlab-org/gitlab-foss/issues/53182) added in GitLab Starter 12.1.
GitLab Bot's avatar
GitLab Bot включено в состав коммита
10
> - Code Owners for Merge Request approvals was [introduced](https://gitlab.com/gitlab-org/gitlab/issues/4418) in [GitLab Premium](https://about.gitlab.com/pricing/) 11.9.
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
11

Igor's avatar
Igor включено в состав коммита
12
13
14
You can use a `CODEOWNERS` file to specify users or
[shared groups](members/share_project_with_groups.md)
that are responsible for certain files in a repository.
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
15
16
17

You can choose and add the `CODEOWNERS` file in three places:

GitLab Bot's avatar
GitLab Bot включено в состав коммита
18
19
20
- To the root directory of the repository
- Inside the `.gitlab/` directory
- Inside the `docs/` directory
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
21
22
23
24
25
26
27

The `CODEOWNERS` file is scoped to a branch, which means that with the
introduction of new files, the person adding the new content can
specify themselves as a code owner, all before the new changes
get merged to the default branch.

When a file matches multiple entries in the `CODEOWNERS` file,
GitLab Bot's avatar
GitLab Bot включено в состав коммита
28
29
30
31
32
33
34
35
36
37
38
39
the users from last pattern matching the file are displayed on the
blob page of the given file. For example, you have the following
`CODEOWNERS` file:

```
README.md @user1

# This line would also match the file README.md
*.md @user2
```

The user that would show for `README.md` would be `@user2`.
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
40

GitLab Bot's avatar
GitLab Bot включено в состав коммита
41
42
43
44
45
## Approvals by Code Owners

Once you've set Code Owners to a project, you can configure it to
receive approvals:

GitLab Bot's avatar
GitLab Bot включено в состав коммита
46
- As [merge request eligible approvers](merge_requests/merge_request_approvals.md#code-owners-as-eligible-approvers).
GitLab Bot's avatar
GitLab Bot включено в состав коммита
47
48
49
50
51
52
- As required approvers for [protected branches](protected_branches.md#protected-branches-approval-by-code-owners-premium). **(PREMIUM)**

Once set, Code Owners are displayed in merge requests widgets:

![MR widget - Code Owners](img/code_owners_mr_widget_v12_4.png)

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
53
54
55
56
## The syntax of Code Owners files

Files can be specified using the same kind of patterns you would use
in the `.gitignore` file followed by the `@username` or email of one
Igor's avatar
Igor включено в состав коммита
57
or more users or by the `@name` of one or more groups that should
GitLab Bot's avatar
GitLab Bot включено в состав коммита
58
59
be owners of the file. Groups must be added as [members of the project](members/index.md),
or they will be ignored.
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

The order in which the paths are defined is significant: the last
pattern that matches a given path will be used to find the code
owners.

Starting a line with a `#` indicates a comment. This needs to be
escaped using `\#` to address files for which the name starts with a
`#`.

Example `CODEOWNERS` file:

```
# This is an example code owners file, lines starting with a `#` will
# be ignored.

# app/ @commented-rule

Yoginth's avatar
Yoginth включено в состав коммита
77
# We can specify a default match using wildcards:
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
78
79
80
81
82
83
84
85
86
87
* @default-codeowner

# Rules defined later in the file take precedence over the rules
# defined before.
# This will match all files for which the file name ends in `.rb`
*.rb @ruby-owner

# Files with a `#` can still be accesssed by escaping the pound sign
\#file_with_pound.rb @owner-file-with-pound

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
88
# Multiple codeowners can be specified, separated by spaces or tabs
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
89
CODEOWNERS @multiple @code @owners
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
90
91
92
93
94
95
96

# Both usernames or email addresses can be used to match
# users. Everything else will be ignored. For example this will
# specify `@legal` and a user with email `janedoe@gitlab.com` as the
# owner for the LICENSE file
LICENSE @legal this_does_not_match janedoe@gitlab.com

Igor's avatar
Igor включено в состав коммита
97
98
99
100
# Group names can be used to match groups and nested groups to specify
# them as owners for a file
README @group @group/with-nested/subgroup

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Ending a path in a `/` will specify the code owners for every file
# nested in that directory, on any level
/docs/ @all-docs

# Ending a path in `/*` will specify code owners for every file in
# that directory, but not nested deeper. This will match
# `docs/index.md` but not `docs/projects/index.md`
/docs/* @root-docs

# This will make a `lib` directory nested anywhere in the repository
# match
lib/ @lib-owner

# This will only match a `config` directory in the root of the
# repository
/config/ @config-owner

# If the path contains spaces, these need to be escaped like this:
path\ with\ spaces/ @space-owner
```