blob: 5e428e5d6d132cdff0717713c08afd7f6e49f495 [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
Edwin Kempin93516072022-11-02 12:51:34 +010023**NOTE:** Tools should never parse `OWNERS` files on their own, but instead
24always use the [REST API](rest-api.html) to access code owner information.
25
26Parsing `OWNERS` files is highly discouraged because:
27
28* it's hard for tools to implement the parsing of `OWNERS` files in a way that
29 is consistent with how Gerrit parses them
30* reimplementing the parsing logic outside of Gerrit is a lot of effort that can
31 be saved by using the REST API and letting Gerrit do the parsing
32* parsing `OWNERS` files outside of Gerrit is likely less efficient since the
33 parser likely needs to reach out to Gerrit to fetch additional input (e.g. if
34 `OWNERS` files from other branches or repositories are imported)
35* the format of `OWNERS` files may change (e.g. by the addition of new features)
36 which could break parsers outside of Gerrit
37
Edwin Kempinfd42aa52021-06-24 17:26:26 +020038### <a id="defaultCodeOwnerConfiguration">Default code owners
Edwin Kempin921ddee2020-11-06 16:02:48 +010039Default code owners that apply to all branches can be defined in an `OWNERS`
40file in the root directory of the `refs/meta/config` branch. This `OWNERS` file
41is the parent of the root `OWNERS` files in all branches. This means if a root
42`OWNERS` file disables the inheritance of code owners from the parent
43directories via the [set noparent](#setNoparent) keyword the `OWNERS` file in
44the `refs/meta/config` branch is ignored. Default code owners are not inherited
45from parent projects. If code owners should be defined for child projects this
46can be done by setting [global code
47owners](config.html#codeOwnersGlobalCodeOwner).
48
Edwin Kempinfd42aa52021-06-24 17:26:26 +020049### <a id="codeOwnerConfigFileExtension">Using a file extension for OWNERS files
50It's possible that projects have a [file
51extension](config.html#codeOwnersFileExtension) for code owner config files
52configured. In this case the code owners are defined in
53`OWNERS.<file-extension>` files and `OWNERS` files are ignored. Further details
54about this are described [here](backends.html#codeOwnerConfigFiles).
Edwin Kempin9d486ed2020-09-15 15:05:23 +020055
Edwin Kempin61a72592020-09-21 12:28:47 +020056## <a id="cookbook">Cookbook
57
58A cookbook with examples of `OWNERS` files for various use cases can be found
59[here](backend-find-owners-cookbook.html).
60
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +020061## <a id="syntax">Syntax
62
63An `OWNERS` file is a set of lines which are order-independent. Each line can be
64
65* a [file-level rule](#fileLevelRules)
66* an [access grant](#accessGrants), possibly with a
67 [restriction prefix](#restrictionPrefixes)
68* a [comment](#comments)
69
Edwin Kempin6ad792c2021-07-26 12:33:08 +020070**NOTE:** By default the `find-owners` backend uses
71[FIND_OWNERS_GLOB's](path-expressions.html) as path expressions, but it's
72possible that a different path expression syntax is
73[configured](config.html#pluginCodeOwnersPathExpressions). All examples on this
74page assume that `FIND_OWNERS_GLOB`'s are used as path expressions.
75
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +020076### <a id="fileLevelRules">File-level rules
77
78File-level rules apply to the entire `OWNERS` file and should not be repeated.
79
80#### <a id="setNoparent">set noparent
81
82By default, a directory inherits the code owners from its parent directory. e.g.
83`/path/to/OWNERS` inherits from `/path/OWNERS`. Code owners won't be inherited
84from parent directories if the `set noparent` keyword is added to an `OWNERS`
85file.
86
87For example, the following `OWNERS` file ignores code owners from the parent
88directories and defines some local code owners:
89
90```
91 set noparent
92
93 [email protected]
94 [email protected]
95```
96
97### <a id="accessGrants">Access grants
98
99Access grants assign code ownerships to users.
100
101#### <a id="userEmails">user emails
102
103In a typical `OWNERS` file, many lines are user emails. These user emails grant
104code ownership to the users that own these emails in Gerrit.
105
106For example, the following `OWNERS` file lists a few different users who are
107code owners:
108
109```
110 [email protected]
111 [email protected]
112 [email protected]
113```
114\
115The order of the user emails is not important and doesn't have any effect, but
116for consistency an alphabetical order is recommended.
117
118User emails that are added to `OWNERS` files must be resolvable in Gerrit. This
Edwin Kempina9eb47c2021-01-07 11:36:08 +0100119means:
120
121* there must be an active Gerrit account that has this email assigned,
122 which is only the case if the user logged in at least once into the Gerrit
123 WebUI (or if an administrator registered the user programatically)
124* the email is not ambiguous (the email belongs to exactly one active Gerrit
125 account)
126* the email has an allowed email domain (see [allowed email domain
127 configuration](config.html#pluginCodeOwnersAllowedEmailDomain)).
128
129##### <a id="nonResolvableCodeOwnersAreIgnored">
130**NOTE:** Non-resolvable code owners in submitted code owner configuration files
131are ignored.
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200132
133**NOTE:** In Gerrit the visibility of users is controlled via the
134[accounts.visibility](../../../Documentation/config-gerrit.html#accounts.visibility)
135configuration. This means not every user may be able to see every other user.
136For code owners this means:
137
138* you can only add users as code owner that are visible to you
139* by adding a user as code owner you expose the existence of this user to
140 everyone who can read the `OWNERS` file
141* the code owner suggestion only suggests code owners that are visible to the
142 calling user, this means if the `OWNERS` file contains code owners that are
143 not visible to the calling user, they are omitted from the suggestion
144* code owners which are referenced by secondary email cannot be resolved for
145 most users, this is because secondary emails of users are only visible to
146 users that have the
147 [Modify Account](../../../Documentation/access-control.html#capability_modifyAccount)
148 global capability assigned in Gerrit, which is normally only granted to
149 administrators
150
151**NOTE:** Via configuration it is possible to
152[limit the email domains](config.html#pluginCodeOwnersAllowedEmailDomain) that
153are allowed for code owners. User emails that have an email domain that is not
154allowed cannot be added as code owner, and are ignored if they exist.
155
156#### <a id="allUsers">All users
157
158Using '*' as [user email](#userEmails) assigns the code ownership to all
159registered users, which effectively exempts the directory (or the matches files
160if used in combination with a [per-file](#perFile) rule) from requiring code
161owner approvals on submit (this is because a code owner approval from the
162uploader is always implicit if the uploader is a code owner).
163
164#### <a id="fileKeyword">file keyword
165
166A `file:<path-to-owners-file>` line includes rules from another `OWNERS` file.
167The path may be either a relative path (e.g. `../sibling/OWNERS`) or an absolute
168path (e.g. `/build/OWNERS`). The specified path must include the name of the
169referenced code owner config file (e.g. `OWNERS`).
170
171```
172 file:/build/OWNERS
173 [email protected]
174 [email protected]
175```
176\
177Many projects prefer to use the relative form for nearby `OWNERS` files.
178Absolute paths are recommended for distant paths, but also to make it easier to
179copy or integrate the line between multiple `OWNERS` files.
180
Edwin Kempinfd42aa52021-06-24 17:26:26 +0200181The file that is referenced by the `file` keyword must be a [code owner config
182file](backends.html#codeOwnerConfigFiles). It's not possible to import arbitrary
183files.
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200184
Edwin Kempin515aec02022-02-11 15:26:27 +0100185##### <a id="referenceCodeOwnerConfigFilesFromOtherProjects">
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200186It's also possible to reference code owner config files from other projects or
187branches (only within the same host):
188
189* `file:<project>:<path-to-owners-file>`:
190 Loads the `<path-to-owners-file>` code owner config file from the specified
191 project. The code owner config file is loaded from the same branch that also
192 contains the importing `OWNERS` file (e.g. if the importing `OWNERS` file is
193 in the `master` branch then `<path-to-owners-file>` will be imported from the
194 `master` branch of the specified project. Example:
195 `file:foo/bar/baz:/path/to/OWNERS`
196* `file:<project>:<branch>:<path-to-owners-file>`:
197 Loads the `<path-to-owners-file>` code owner config file from the specified
198 branch of the specified project. The branch can be specified as full ref name
199 (e.g. `refs/heads/master`) or as short branch name (e.g. `master`). Example:
200 `file:foo/bar/baz:master:/path/to/OWNERS`
201
202If referenced `OWNERS` files do not exists, they are silently ignored when code
203owners are resolved, but trying to add references to non-existing `OWNERS` file
Edwin Kempind45c8c42021-08-30 08:59:05 +0200204will be rejected on upload/submit. Being ignored means that the `@PLUGIN@`
205doesn't bail out with an error when code owners are resolved, but the import of
206non-resolvable `OWNERS` files [prevents fallback code owners from being
207applied](config.html#pluginCodeOwnersFallbackCodeOwners). The reason for this is
208that if there is an unresolved import, it is assumed that it was intended to
209define code owners, e.g. stricter code owners than the fallback code owners, and
210hence the fallback code owners should not be applied.
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200211
212When referencing an external `OWNERS` file via the `file` keyword, only
Edwin Kempin190d67a2021-09-27 09:54:20 +0200213non-restricted [access grants](#accessGrants) are imported. If they contain
214imports (via the `file` or [include](#includeKeyword) keyword) they are
215recursively resolved. This means for the referenced `OWNERS` files the following
216things are ignored and not pulled in:
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200217
Edwin Kempin190d67a2021-09-27 09:54:20 +02002181. `per-file` rules
2192. any [set noparent](#setNoparent) line
2203. `OWNERS` files in parent directories
221
222To also import `per-file` rules and any [set noparent](#setNoparent) line (1. +
2232.) use the [include](#includeKeyword) keyword instead.
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200224
225#### <a id="includeKeyword">include keyword
226
227An `include <path-to-owners-file>` line includes rules from another `OWNERS`
228file, similar to the [file](#fileKeyword) keyword. The only difference is that
229using the `include` keyword also imports `per-file` rules and any
230[set noparent](#setNoparent) line from the referenced `OWNERS` file.
231
232**NOTE:** In contrast to the [file](#fileKeyword) keyword, the `include` keyword
233is used without any ':' between the keyword and the file path (e.g.
234`include /path/to/OWNERS`).
235
Edwin Kempin61a72592020-09-21 12:28:47 +0200236**NOTE:** Using the include keyword in combination with a [per-file](#perFile)
237rule is not possible.
238
Edwin Kempin36a42ea2020-09-18 12:19:10 +0200239#### <a id="groups">Groups
240
241Groups are not supported in `OWNERS` files and assigning code ownership to them
242is not possible.
243
244Instead of using a group you may define a set of users in an `OWNERS` file with
245a prefix (`<prefix>_OWNERS`) or an extension (`OWNERS_<extension>`) and then
246import it into other `OWNERS` files via the [file](#fileKeyword) keyword or the
247[include](#includeKeyword) keyword. By using a prefix or extension for the
248`OWNERS` file it is only interpreted when it is imported into another `OWNERS`
249file, but otherwise it has no effect.
250
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200251### <a id="restrictionPrefixes">Restriction Prefixes
252
253All restriction prefixes should be put at the start of a line, before an
254[access grant](#accessGrants).
255
256#### <a id="perFile">per-file
257
258A `per-file` line restricts the given access grant to only apply to a subset of
259files in the directory:
260
261```
262 per-file <path-exp-1,path-exp-2,...>=<access-grant>
263```
264\
265The access grant applies only to the files that are matched by the given path
Edwin Kempin46b9c3a2020-09-16 13:10:34 +0200266expressions. The path expressions are [globs](path-expressions.html#globs) and
267can match absolute paths or paths relative to the directory of the `OWNERS`
268file, but they can only match files in the directory of the `OWNERS` file and
269its subdirectories. Multiple path expressions can be specified as a
270comma-separated list.
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200271
272In the example below, Jana Roe, John Doe and the code owners that are inherited
273from parent `OWNERS` files are code owners of all files that are contained in
274the directory that contains the `OWNERS` file. In addition Richard Roe is a code
Edwin Kempin2b513832020-12-21 12:33:45 +0100275owner of the `docs.config` file in this directory and all `*.md` files in this
276directory and the subdirectories.
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200277
278```
279 [email protected]
280 [email protected]
281 per-file docs.config,*[email protected]
282```
Edwin Kempined291c92024-08-19 08:36:03 +0000283\
Edwin Kempin5e180092022-06-09 13:56:14 +0200284**NOTE:** It's important to not include additional spaces in `per-file` lines.
285E.g. "per-file docs.config, [email protected]" will make
286Richard Roe a code owner of the files "docs.config" and " test.config" (pay
287attention to the leading space), but not for the file "test.config". The correct
288line to make Richard Roe a code owner of the files "docs.config" and
289"test.config" would be "per-file docs.config,[email protected]".
290
Edwin Kempin7b8a7c12020-09-23 15:28:08 +0200291##### <a id="doNotUsePathExpressionsForSubdirectories">
Edwin Kempinf0168ca2020-09-17 15:35:40 +0200292**NOTE:** It is discouraged to use path expressions that explicitly name
Edwin Kempin2b513832020-12-21 12:33:45 +0100293subdirectories such as `my-subdir/*` as they will break when the subdirectory
Edwin Kempinf0168ca2020-09-17 15:35:40 +0200294gets renamed/moved. Instead prefer to define these code owners in
295`my-subdir/OWNERS` so that the code owners for the subdirectory stay intact when
296the subdirectory gets renamed/moved.
297
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200298To grant per-file code ownership to more than one user multiple [user
299emails](#userEmails) can be specified as comma-separated list, or an external
300`OWNERS` file can be referenced via the [file](#fileKeyword) keyword.
301Alternatively the `per-file` line can be repeated multiple times.
302
303```
304 [email protected]
305 [email protected]
306 per-file docs.config,*[email protected],[email protected]
307 per-file docs.config,*.md=file:/build/OWNERS
308```
309\
310When referencing an external `OWNERS` file via the [file](#fileKeyword) keyword,
311only non-restricted [access grants](#accessGrants) are imported. This means
312`per-file` rules from the referenced `OWNERS` file are not pulled in and also
313any [set noparent](#setNoparent) line in the referenced `OWNERS` file is
314ignored, but recursive imports are being resolved.
315
316Using the [include](#includeKeyword) keyword in combination with a `per-file`
317rule is not possible.
318
319It's also possible to combine [set noparent](#setNoparent) with `per-file` rules
320to prevent access by non-per-file owners from the current directory as well as
321from parent directories.
322
323In the example below, Richard Roe is the only code owner of the `docs.config`
Edwin Kempin2b513832020-12-21 12:33:45 +0100324file in this directory and all `*.md` files in this directory and the
325subdirectories. All other files in this directory and its subdirectories are
326owned by Jana Roe, John Doe and the code owners that are inherited from parent
327directories.
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200328
329```
330 [email protected]
331 [email protected]
332 per-file docs.config,*.md=set noparent
333 per-file docs.config,*[email protected]
334```
335
Edwin Kempin74a4c2f2021-05-25 13:12:45 +0200336### <a id="anotations">Annotations
337
Edwin Kempin8dae95c2022-03-14 15:00:53 +0100338Lines that assign code ownership to users ([email lines](#userEmails) and
339[per-file lines](#perFile)) can be annotated. Annotations have the format
340`#{ANNOTATION_NAME}` and can appear at the end of the line.
Edwin Kempin74a4c2f2021-05-25 13:12:45 +0200341E.g.:
342
343```
Edwin Kempin9a800962021-06-11 10:04:53 +0200344 [email protected] #{LAST_RESORT_SUGGESTION}
345 per-file docs.config,*[email protected] #{LAST_RESORT_SUGGESTION}
Edwin Kempin74a4c2f2021-05-25 13:12:45 +0200346```
347\
348Annotations can be mixed with [comments](#comments) that can appear before and
349after annotations, E.g.:
350
351```
Edwin Kempin9a800962021-06-11 10:04:53 +0200352 [email protected] # foo bar #{LAST_RESORT_SUGGESTION} baz
Edwin Kempin74a4c2f2021-05-25 13:12:45 +0200353```
354\
355The following annotations are supported:
356
Edwin Kempin9a800962021-06-11 10:04:53 +0200357#### <a id="lastResortSuggestion">
358* `LAST_RESORT_SUGGESTION`:
Edwin Kempin74a4c2f2021-05-25 13:12:45 +0200359 Code owners with this annotation are omitted when [suggesting code
Edwin Kempin66ee5752021-06-09 13:35:57 +0200360 owners](rest-api.html#list-code-owners-for-path-in-change), except if dropping
Edwin Kempin3acf4bd2021-07-26 11:29:48 +0200361 these code owners would make the suggestion result empty or if these code
362 owners are already reviewers of the change. If code ownership is assigned to
363 the same code owner through multiple relevant access grants in the same code
364 owner config file or in other relevant code owner config files the code owner
365 gets omitted from the suggestion if it has the `LAST_RESORT_SUGGESTION` set on
366 any of the access grants.
Edwin Kempin74a4c2f2021-05-25 13:12:45 +0200367
368Unknown annotations are silently ignored.
369
Edwin Kempin8dae95c2022-03-14 15:00:53 +0100370**NOTE:** If a line that assigns code ownership to multiple users has an
371annotation, this annotation applies to all these users. E.g. if an annotation is
372set for the all users wildcard (aka `*`) it applies to all users.
373
Edwin Kempin62dfffa2023-01-13 09:17:35 +0100374**NOTE:** Only [email lines](#userEmails) and [per-file lines](#perFile) that
375assign code ownership directly to users support annotations, for other lines
376(e.g. [file lines](#fileKeyword), [include lines](#includeKeyword) and
377[per-file lines](#perFile) that reference other `OWNERS` files via the
378[file](#fileKeyword) keyword) annotations are interpreted as
379[comments](#comments) and are silently ignored.
Edwin Kempin74a4c2f2021-05-25 13:12:45 +0200380
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200381### <a id="comments">Comments
382
383The '#' character indicates the beginning of a comment. Arbitrary text may be
384added in comments.
385
Edwin Kempin31148042021-06-21 09:43:13 +0200386Comments can appear at the end of any line or consume the whole line (a line
387starting with '#', `# <comment-test`).
Edwin Kempinc2fc7bf2020-09-16 08:15:50 +0200388
389Comments are not interpreted by the `code-owners` plugin and are intended for
390human readers of the `OWNERS` files. However some projects/teams may have own
391tooling that uses comments to store additional information in `OWNERS` files.
392
Edwin Kempin9d486ed2020-09-15 15:05:23 +0200393---
394
395Back to [@PLUGIN@ documentation index](index.html)
396
397Part of [Gerrit Code Review](../../../Documentation/index.html)