blob: 21125a92852a2c164155a8ef2dfcb6344f6ecb39 [file] [log] [blame] [view]
Edwin Kempin9d486ed2020-09-15 15:05:23 +02001# find-owners Backend
2
3The `find-owners` backend supports the syntax of the
4[find-owners](https://gerrit-review.googlesource.com/admin/repos/plugins/find-owners)
5plugin (with some minor extensions). It is the backend that is used by default
6if no other backend is explicitly [configured](config.html#codeOwnersBackend)
7for a project or branch.
8
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +02009## <a id="codeOwnerConfiguration">Code owner configuration
Edwin Kempin9d486ed2020-09-15 15:05:23 +020010
11Code owners are defined in `OWNERS` files which are stored in the source tree.
Edwin Kempinfd42aa52021-06-24 17:26:26 +020012
Edwin Kempin9d486ed2020-09-15 15:05:23 +020013The code owners that are defined in an `OWNERS` file apply to the directory that
14contains the `OWNERS` file, and all its subdirectories (except if a subdirectory
15contains an `OWNERS` file that disables the inheritance of code owners from the
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +020016parent directories via the [set noparent](#setNoparent) keyword).
Edwin Kempin9d486ed2020-09-15 15:05:23 +020017
Edwin Kempinfd42aa52021-06-24 17:26:26 +020018**NOTE:** It is also possible to define code owners in `<prefix>_OWNERS` or
19`OWNERS_<extension>` files that can be imported into `OWNERS` files (further
20details about code owner config files are described
21[here](backends.html#codeOwnerConfigFiles)).
22
23### <a id="defaultCodeOwnerConfiguration">Default code owners
Edwin Kempin921ddee2020-11-06 16:02:48 +010024Default code owners that apply to all branches can be defined in an `OWNERS`
25file in the root directory of the `refs/meta/config` branch. This `OWNERS` file
26is the parent of the root `OWNERS` files in all branches. This means if a root
27`OWNERS` file disables the inheritance of code owners from the parent
28directories via the [set noparent](#setNoparent) keyword the `OWNERS` file in
29the `refs/meta/config` branch is ignored. Default code owners are not inherited
30from parent projects. If code owners should be defined for child projects this
31can be done by setting [global code
32owners](config.html#codeOwnersGlobalCodeOwner).
33
Edwin Kempinfd42aa52021-06-24 17:26:26 +020034### <a id="codeOwnerConfigFileExtension">Using a file extension for OWNERS files
35It's possible that projects have a [file
36extension](config.html#codeOwnersFileExtension) for code owner config files
37configured. In this case the code owners are defined in
38`OWNERS.<file-extension>` files and `OWNERS` files are ignored. Further details
39about this are described [here](backends.html#codeOwnerConfigFiles).
Edwin Kempin9d486ed2020-09-15 15:05:23 +020040
Edwin Kempin61a72592020-09-21 12:28:47 +020041## <a id="cookbook">Cookbook
42
43A cookbook with examples of `OWNERS` files for various use cases can be found
44[here](backend-find-owners-cookbook.html).
45
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +020046## <a id="syntax">Syntax
47
48An `OWNERS` file is a set of lines which are order-independent. Each line can be
49
50* a [file-level rule](#fileLevelRules)
51* an [access grant](#accessGrants), possibly with a
52 [restriction prefix](#restrictionPrefixes)
53* a [comment](#comments)
54
55### <a id="fileLevelRules">File-level rules
56
57File-level rules apply to the entire `OWNERS` file and should not be repeated.
58
59#### <a id="setNoparent">set noparent
60
61By default, a directory inherits the code owners from its parent directory. e.g.
62`/path/to/OWNERS` inherits from `/path/OWNERS`. Code owners won't be inherited
63from parent directories if the `set noparent` keyword is added to an `OWNERS`
64file.
65
66For example, the following `OWNERS` file ignores code owners from the parent
67directories and defines some local code owners:
68
69```
70 set noparent
71
72 [email protected]
73 [email protected]
74```
75
76### <a id="accessGrants">Access grants
77
78Access grants assign code ownerships to users.
79
80#### <a id="userEmails">user emails
81
82In a typical `OWNERS` file, many lines are user emails. These user emails grant
83code ownership to the users that own these emails in Gerrit.
84
85For example, the following `OWNERS` file lists a few different users who are
86code owners:
87
88```
89 [email protected]
90 [email protected]
91 [email protected]
92```
93\
94The order of the user emails is not important and doesn't have any effect, but
95for consistency an alphabetical order is recommended.
96
97User emails that are added to `OWNERS` files must be resolvable in Gerrit. This
Edwin Kempina9eb47c2021-01-07 11:36:08 +010098means:
99
100* there must be an active Gerrit account that has this email assigned,
101 which is only the case if the user logged in at least once into the Gerrit
102 WebUI (or if an administrator registered the user programatically)
103* the email is not ambiguous (the email belongs to exactly one active Gerrit
104 account)
105* the email has an allowed email domain (see [allowed email domain
106 configuration](config.html#pluginCodeOwnersAllowedEmailDomain)).
107
108##### <a id="nonResolvableCodeOwnersAreIgnored">
109**NOTE:** Non-resolvable code owners in submitted code owner configuration files
110are ignored.
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200111
112**NOTE:** In Gerrit the visibility of users is controlled via the
113[accounts.visibility](../../../Documentation/config-gerrit.html#accounts.visibility)
114configuration. This means not every user may be able to see every other user.
115For code owners this means:
116
117* you can only add users as code owner that are visible to you
118* by adding a user as code owner you expose the existence of this user to
119 everyone who can read the `OWNERS` file
120* the code owner suggestion only suggests code owners that are visible to the
121 calling user, this means if the `OWNERS` file contains code owners that are
122 not visible to the calling user, they are omitted from the suggestion
123* code owners which are referenced by secondary email cannot be resolved for
124 most users, this is because secondary emails of users are only visible to
125 users that have the
126 [Modify Account](../../../Documentation/access-control.html#capability_modifyAccount)
127 global capability assigned in Gerrit, which is normally only granted to
128 administrators
129
130**NOTE:** Via configuration it is possible to
131[limit the email domains](config.html#pluginCodeOwnersAllowedEmailDomain) that
132are allowed for code owners. User emails that have an email domain that is not
133allowed cannot be added as code owner, and are ignored if they exist.
134
135#### <a id="allUsers">All users
136
137Using '*' as [user email](#userEmails) assigns the code ownership to all
138registered users, which effectively exempts the directory (or the matches files
139if used in combination with a [per-file](#perFile) rule) from requiring code
140owner approvals on submit (this is because a code owner approval from the
141uploader is always implicit if the uploader is a code owner).
142
143#### <a id="fileKeyword">file keyword
144
145A `file:<path-to-owners-file>` line includes rules from another `OWNERS` file.
146The path may be either a relative path (e.g. `../sibling/OWNERS`) or an absolute
147path (e.g. `/build/OWNERS`). The specified path must include the name of the
148referenced code owner config file (e.g. `OWNERS`).
149
150```
151 file:/build/OWNERS
152 [email protected]
153 [email protected]
154```
155\
156Many projects prefer to use the relative form for nearby `OWNERS` files.
157Absolute paths are recommended for distant paths, but also to make it easier to
158copy or integrate the line between multiple `OWNERS` files.
159
Edwin Kempinfd42aa52021-06-24 17:26:26 +0200160The file that is referenced by the `file` keyword must be a [code owner config
161file](backends.html#codeOwnerConfigFiles). It's not possible to import arbitrary
162files.
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200163
164It's also possible to reference code owner config files from other projects or
165branches (only within the same host):
166
167* `file:<project>:<path-to-owners-file>`:
168 Loads the `<path-to-owners-file>` code owner config file from the specified
169 project. The code owner config file is loaded from the same branch that also
170 contains the importing `OWNERS` file (e.g. if the importing `OWNERS` file is
171 in the `master` branch then `<path-to-owners-file>` will be imported from the
172 `master` branch of the specified project. Example:
173 `file:foo/bar/baz:/path/to/OWNERS`
174* `file:<project>:<branch>:<path-to-owners-file>`:
175 Loads the `<path-to-owners-file>` code owner config file from the specified
176 branch of the specified project. The branch can be specified as full ref name
177 (e.g. `refs/heads/master`) or as short branch name (e.g. `master`). Example:
178 `file:foo/bar/baz:master:/path/to/OWNERS`
179
180If referenced `OWNERS` files do not exists, they are silently ignored when code
181owners are resolved, but trying to add references to non-existing `OWNERS` file
182will be rejected on upload/submit.
183
184When referencing an external `OWNERS` file via the `file` keyword, only
185non-restricted [access grants](#accessGrants) are imported. This means
186`per-file` rules from the referenced `OWNERS` file are not pulled in and also
187any [set noparent](#setNoparent) line in the referenced `OWNERS` file is
188ignored, but recursive imports are being resolved.
189
190To also import `per-file` rules and any [set noparent](#setNoparent) line use
191the [include](#includeKeyword) keyword instead.
192
193#### <a id="includeKeyword">include keyword
194
195An `include <path-to-owners-file>` line includes rules from another `OWNERS`
196file, similar to the [file](#fileKeyword) keyword. The only difference is that
197using the `include` keyword also imports `per-file` rules and any
198[set noparent](#setNoparent) line from the referenced `OWNERS` file.
199
200**NOTE:** In contrast to the [file](#fileKeyword) keyword, the `include` keyword
201is used without any ':' between the keyword and the file path (e.g.
202`include /path/to/OWNERS`).
203
Edwin Kempin61a72592020-09-21 12:28:47 +0200204**NOTE:** Using the include keyword in combination with a [per-file](#perFile)
205rule is not possible.
206
Edwin Kempin36a42ea2020-09-18 12:19:10 +0200207#### <a id="groups">Groups
208
209Groups are not supported in `OWNERS` files and assigning code ownership to them
210is not possible.
211
212Instead of using a group you may define a set of users in an `OWNERS` file with
213a prefix (`<prefix>_OWNERS`) or an extension (`OWNERS_<extension>`) and then
214import it into other `OWNERS` files via the [file](#fileKeyword) keyword or the
215[include](#includeKeyword) keyword. By using a prefix or extension for the
216`OWNERS` file it is only interpreted when it is imported into another `OWNERS`
217file, but otherwise it has no effect.
218
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200219### <a id="restrictionPrefixes">Restriction Prefixes
220
221All restriction prefixes should be put at the start of a line, before an
222[access grant](#accessGrants).
223
224#### <a id="perFile">per-file
225
226A `per-file` line restricts the given access grant to only apply to a subset of
227files in the directory:
228
229```
230 per-file <path-exp-1,path-exp-2,...>=<access-grant>
231```
232\
233The access grant applies only to the files that are matched by the given path
Edwin Kempin46b9c3a2020-09-16 13:10:34 +0200234expressions. The path expressions are [globs](path-expressions.html#globs) and
235can match absolute paths or paths relative to the directory of the `OWNERS`
236file, but they can only match files in the directory of the `OWNERS` file and
237its subdirectories. Multiple path expressions can be specified as a
238comma-separated list.
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200239
240In the example below, Jana Roe, John Doe and the code owners that are inherited
241from parent `OWNERS` files are code owners of all files that are contained in
242the directory that contains the `OWNERS` file. In addition Richard Roe is a code
Edwin Kempin2b513832020-12-21 12:33:45 +0100243owner of the `docs.config` file in this directory and all `*.md` files in this
244directory and the subdirectories.
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200245
246```
247 [email protected]
248 [email protected]
249 per-file docs.config,*[email protected]
250```
Edwin Kempin7c5ca322021-01-18 14:28:24 +0100251
Edwin Kempin7b8a7c12020-09-23 15:28:08 +0200252##### <a id="doNotUsePathExpressionsForSubdirectories">
Edwin Kempinf0168ca2020-09-17 15:35:40 +0200253**NOTE:** It is discouraged to use path expressions that explicitly name
Edwin Kempin2b513832020-12-21 12:33:45 +0100254subdirectories such as `my-subdir/*` as they will break when the subdirectory
Edwin Kempinf0168ca2020-09-17 15:35:40 +0200255gets renamed/moved. Instead prefer to define these code owners in
256`my-subdir/OWNERS` so that the code owners for the subdirectory stay intact when
257the subdirectory gets renamed/moved.
258
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200259To grant per-file code ownership to more than one user multiple [user
260emails](#userEmails) can be specified as comma-separated list, or an external
261`OWNERS` file can be referenced via the [file](#fileKeyword) keyword.
262Alternatively the `per-file` line can be repeated multiple times.
263
264```
265 [email protected]
266 [email protected]
267 per-file docs.config,*[email protected],[email protected]
268 per-file docs.config,*.md=file:/build/OWNERS
269```
270\
271When referencing an external `OWNERS` file via the [file](#fileKeyword) keyword,
272only non-restricted [access grants](#accessGrants) are imported. This means
273`per-file` rules from the referenced `OWNERS` file are not pulled in and also
274any [set noparent](#setNoparent) line in the referenced `OWNERS` file is
275ignored, but recursive imports are being resolved.
276
277Using the [include](#includeKeyword) keyword in combination with a `per-file`
278rule is not possible.
279
280It's also possible to combine [set noparent](#setNoparent) with `per-file` rules
281to prevent access by non-per-file owners from the current directory as well as
282from parent directories.
283
284In the example below, Richard Roe is the only code owner of the `docs.config`
Edwin Kempin2b513832020-12-21 12:33:45 +0100285file in this directory and all `*.md` files in this directory and the
286subdirectories. All other files in this directory and its subdirectories are
287owned by Jana Roe, John Doe and the code owners that are inherited from parent
288directories.
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200289
290```
291 [email protected]
292 [email protected]
293 per-file docs.config,*.md=set noparent
294 per-file docs.config,*[email protected]
295```
296
Edwin Kempin74a4c2f2021-05-25 13:12:45 +0200297### <a id="anotations">Annotations
298
299Lines representing [access grants](#accessGrants) can be annotated. Annotations
300have the format `#{ANNOTATION_NAME}` and can appear at the end of the line.
301E.g.:
302
303```
Edwin Kempin9a800962021-06-11 10:04:53 +0200304 [email protected] #{LAST_RESORT_SUGGESTION}
305 per-file docs.config,*[email protected] #{LAST_RESORT_SUGGESTION}
Edwin Kempin74a4c2f2021-05-25 13:12:45 +0200306```
307\
308Annotations can be mixed with [comments](#comments) that can appear before and
309after annotations, E.g.:
310
311```
Edwin Kempin9a800962021-06-11 10:04:53 +0200312 [email protected] # foo bar #{LAST_RESORT_SUGGESTION} baz
Edwin Kempin74a4c2f2021-05-25 13:12:45 +0200313```
314\
315The following annotations are supported:
316
Edwin Kempin9a800962021-06-11 10:04:53 +0200317#### <a id="lastResortSuggestion">
318* `LAST_RESORT_SUGGESTION`:
Edwin Kempin74a4c2f2021-05-25 13:12:45 +0200319 Code owners with this annotation are omitted when [suggesting code
Edwin Kempin66ee5752021-06-09 13:35:57 +0200320 owners](rest-api.html#list-code-owners-for-path-in-change), except if dropping
321 these code owners would make the suggestion result empty. If code ownership is
322 assigned to the same code owner through multiple relevant access grants in the
323 same code owner config file or in other relevant code owner config files the
Edwin Kempin9a800962021-06-11 10:04:53 +0200324 code owner gets omitted from the suggestion if it has the
325 `LAST_RESORT_SUGGESTION` set on any of the access grants.
Edwin Kempin74a4c2f2021-05-25 13:12:45 +0200326
327Unknown annotations are silently ignored.
328
329**NOTE:** If an access grant line that assigns code ownership to multiple users
330has an annotation, this annotation applies to all these users. E.g. if an
331annotation is set for the all users wildcard (aka `*`) it applies to all users.
332
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200333### <a id="comments">Comments
334
335The '#' character indicates the beginning of a comment. Arbitrary text may be
336added in comments.
337
Edwin Kempin31148042021-06-21 09:43:13 +0200338Comments can appear at the end of any line or consume the whole line (a line
339starting with '#', `# <comment-test`).
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200340
341Comments are not interpreted by the `code-owners` plugin and are intended for
342human readers of the `OWNERS` files. However some projects/teams may have own
343tooling that uses comments to store additional information in `OWNERS` files.
344
Edwin Kempin9d486ed2020-09-15 15:05:23 +0200345---
346
347Back to [@PLUGIN@ documentation index](index.html)
348
349Part of [Gerrit Code Review](../../../Documentation/index.html)