Edwin Kempin | 9d486ed | 2020-09-15 15:05:23 +0200 | [diff] [blame] | 1 | # find-owners Backend |
| 2 | |
| 3 | The `find-owners` backend supports the syntax of the |
| 4 | [find-owners](https://gerrit-review.googlesource.com/admin/repos/plugins/find-owners) |
| 5 | plugin (with some minor extensions). It is the backend that is used by default |
| 6 | if no other backend is explicitly [configured](config.html#codeOwnersBackend) |
| 7 | for a project or branch. |
| 8 | |
Edwin Kempin | c2fc7bf | 2020-09-16 08:15:50 +0200 | [diff] [blame] | 9 | ## <a id="codeOwnerConfiguration">Code owner configuration |
Edwin Kempin | 9d486ed | 2020-09-15 15:05:23 +0200 | [diff] [blame] | 10 | |
| 11 | Code owners are defined in `OWNERS` files which are stored in the source tree. |
Edwin Kempin | fd42aa5 | 2021-06-24 17:26:26 +0200 | [diff] [blame] | 12 | |
Edwin Kempin | 9d486ed | 2020-09-15 15:05:23 +0200 | [diff] [blame] | 13 | The code owners that are defined in an `OWNERS` file apply to the directory that |
| 14 | contains the `OWNERS` file, and all its subdirectories (except if a subdirectory |
| 15 | contains an `OWNERS` file that disables the inheritance of code owners from the |
Edwin Kempin | c2fc7bf | 2020-09-16 08:15:50 +0200 | [diff] [blame] | 16 | parent directories via the [set noparent](#setNoparent) keyword). |
Edwin Kempin | 9d486ed | 2020-09-15 15:05:23 +0200 | [diff] [blame] | 17 | |
Edwin Kempin | fd42aa5 | 2021-06-24 17:26:26 +0200 | [diff] [blame] | 18 | **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 |
| 20 | details about code owner config files are described |
| 21 | [here](backends.html#codeOwnerConfigFiles)). |
| 22 | |
| 23 | ### <a id="defaultCodeOwnerConfiguration">Default code owners |
Edwin Kempin | 921ddee | 2020-11-06 16:02:48 +0100 | [diff] [blame] | 24 | Default code owners that apply to all branches can be defined in an `OWNERS` |
| 25 | file in the root directory of the `refs/meta/config` branch. This `OWNERS` file |
| 26 | is 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 |
| 28 | directories via the [set noparent](#setNoparent) keyword the `OWNERS` file in |
| 29 | the `refs/meta/config` branch is ignored. Default code owners are not inherited |
| 30 | from parent projects. If code owners should be defined for child projects this |
| 31 | can be done by setting [global code |
| 32 | owners](config.html#codeOwnersGlobalCodeOwner). |
| 33 | |
Edwin Kempin | fd42aa5 | 2021-06-24 17:26:26 +0200 | [diff] [blame] | 34 | ### <a id="codeOwnerConfigFileExtension">Using a file extension for OWNERS files |
| 35 | It's possible that projects have a [file |
| 36 | extension](config.html#codeOwnersFileExtension) for code owner config files |
| 37 | configured. In this case the code owners are defined in |
| 38 | `OWNERS.<file-extension>` files and `OWNERS` files are ignored. Further details |
| 39 | about this are described [here](backends.html#codeOwnerConfigFiles). |
Edwin Kempin | 9d486ed | 2020-09-15 15:05:23 +0200 | [diff] [blame] | 40 | |
Edwin Kempin | 61a7259 | 2020-09-21 12:28:47 +0200 | [diff] [blame] | 41 | ## <a id="cookbook">Cookbook |
| 42 | |
| 43 | A cookbook with examples of `OWNERS` files for various use cases can be found |
| 44 | [here](backend-find-owners-cookbook.html). |
| 45 | |
Edwin Kempin | c2fc7bf | 2020-09-16 08:15:50 +0200 | [diff] [blame] | 46 | ## <a id="syntax">Syntax |
| 47 | |
| 48 | An `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 | |
| 57 | File-level rules apply to the entire `OWNERS` file and should not be repeated. |
| 58 | |
| 59 | #### <a id="setNoparent">set noparent |
| 60 | |
| 61 | By 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 |
| 63 | from parent directories if the `set noparent` keyword is added to an `OWNERS` |
| 64 | file. |
| 65 | |
| 66 | For example, the following `OWNERS` file ignores code owners from the parent |
| 67 | directories 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 | |
| 78 | Access grants assign code ownerships to users. |
| 79 | |
| 80 | #### <a id="userEmails">user emails |
| 81 | |
| 82 | In a typical `OWNERS` file, many lines are user emails. These user emails grant |
| 83 | code ownership to the users that own these emails in Gerrit. |
| 84 | |
| 85 | For example, the following `OWNERS` file lists a few different users who are |
| 86 | code owners: |
| 87 | |
| 88 | ``` |
| 89 | [email protected] |
| 90 | [email protected] |
| 91 | [email protected] |
| 92 | ``` |
| 93 | \ |
| 94 | The order of the user emails is not important and doesn't have any effect, but |
| 95 | for consistency an alphabetical order is recommended. |
| 96 | |
| 97 | User emails that are added to `OWNERS` files must be resolvable in Gerrit. This |
Edwin Kempin | a9eb47c | 2021-01-07 11:36:08 +0100 | [diff] [blame] | 98 | means: |
| 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 |
| 110 | are ignored. |
Edwin Kempin | c2fc7bf | 2020-09-16 08:15:50 +0200 | [diff] [blame] | 111 | |
| 112 | **NOTE:** In Gerrit the visibility of users is controlled via the |
| 113 | [accounts.visibility](../../../Documentation/config-gerrit.html#accounts.visibility) |
| 114 | configuration. This means not every user may be able to see every other user. |
| 115 | For 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 |
| 132 | are allowed for code owners. User emails that have an email domain that is not |
| 133 | allowed cannot be added as code owner, and are ignored if they exist. |
| 134 | |
| 135 | #### <a id="allUsers">All users |
| 136 | |
| 137 | Using '*' as [user email](#userEmails) assigns the code ownership to all |
| 138 | registered users, which effectively exempts the directory (or the matches files |
| 139 | if used in combination with a [per-file](#perFile) rule) from requiring code |
| 140 | owner approvals on submit (this is because a code owner approval from the |
| 141 | uploader is always implicit if the uploader is a code owner). |
| 142 | |
| 143 | #### <a id="fileKeyword">file keyword |
| 144 | |
| 145 | A `file:<path-to-owners-file>` line includes rules from another `OWNERS` file. |
| 146 | The path may be either a relative path (e.g. `../sibling/OWNERS`) or an absolute |
| 147 | path (e.g. `/build/OWNERS`). The specified path must include the name of the |
| 148 | referenced code owner config file (e.g. `OWNERS`). |
| 149 | |
| 150 | ``` |
| 151 | file:/build/OWNERS |
| 152 | [email protected] |
| 153 | [email protected] |
| 154 | ``` |
| 155 | \ |
| 156 | Many projects prefer to use the relative form for nearby `OWNERS` files. |
| 157 | Absolute paths are recommended for distant paths, but also to make it easier to |
| 158 | copy or integrate the line between multiple `OWNERS` files. |
| 159 | |
Edwin Kempin | fd42aa5 | 2021-06-24 17:26:26 +0200 | [diff] [blame] | 160 | The file that is referenced by the `file` keyword must be a [code owner config |
| 161 | file](backends.html#codeOwnerConfigFiles). It's not possible to import arbitrary |
| 162 | files. |
Edwin Kempin | c2fc7bf | 2020-09-16 08:15:50 +0200 | [diff] [blame] | 163 | |
| 164 | It's also possible to reference code owner config files from other projects or |
| 165 | branches (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 | |
| 180 | If referenced `OWNERS` files do not exists, they are silently ignored when code |
| 181 | owners are resolved, but trying to add references to non-existing `OWNERS` file |
| 182 | will be rejected on upload/submit. |
| 183 | |
| 184 | When referencing an external `OWNERS` file via the `file` keyword, only |
| 185 | non-restricted [access grants](#accessGrants) are imported. This means |
| 186 | `per-file` rules from the referenced `OWNERS` file are not pulled in and also |
| 187 | any [set noparent](#setNoparent) line in the referenced `OWNERS` file is |
| 188 | ignored, but recursive imports are being resolved. |
| 189 | |
| 190 | To also import `per-file` rules and any [set noparent](#setNoparent) line use |
| 191 | the [include](#includeKeyword) keyword instead. |
| 192 | |
| 193 | #### <a id="includeKeyword">include keyword |
| 194 | |
| 195 | An `include <path-to-owners-file>` line includes rules from another `OWNERS` |
| 196 | file, similar to the [file](#fileKeyword) keyword. The only difference is that |
| 197 | using 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 |
| 201 | is used without any ':' between the keyword and the file path (e.g. |
| 202 | `include /path/to/OWNERS`). |
| 203 | |
Edwin Kempin | 61a7259 | 2020-09-21 12:28:47 +0200 | [diff] [blame] | 204 | **NOTE:** Using the include keyword in combination with a [per-file](#perFile) |
| 205 | rule is not possible. |
| 206 | |
Edwin Kempin | 36a42ea | 2020-09-18 12:19:10 +0200 | [diff] [blame] | 207 | #### <a id="groups">Groups |
| 208 | |
| 209 | Groups are not supported in `OWNERS` files and assigning code ownership to them |
| 210 | is not possible. |
| 211 | |
| 212 | Instead of using a group you may define a set of users in an `OWNERS` file with |
| 213 | a prefix (`<prefix>_OWNERS`) or an extension (`OWNERS_<extension>`) and then |
| 214 | import 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` |
| 217 | file, but otherwise it has no effect. |
| 218 | |
Edwin Kempin | c2fc7bf | 2020-09-16 08:15:50 +0200 | [diff] [blame] | 219 | ### <a id="restrictionPrefixes">Restriction Prefixes |
| 220 | |
| 221 | All 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 | |
| 226 | A `per-file` line restricts the given access grant to only apply to a subset of |
| 227 | files in the directory: |
| 228 | |
| 229 | ``` |
| 230 | per-file <path-exp-1,path-exp-2,...>=<access-grant> |
| 231 | ``` |
| 232 | \ |
| 233 | The access grant applies only to the files that are matched by the given path |
Edwin Kempin | 46b9c3a | 2020-09-16 13:10:34 +0200 | [diff] [blame] | 234 | expressions. The path expressions are [globs](path-expressions.html#globs) and |
| 235 | can match absolute paths or paths relative to the directory of the `OWNERS` |
| 236 | file, but they can only match files in the directory of the `OWNERS` file and |
| 237 | its subdirectories. Multiple path expressions can be specified as a |
| 238 | comma-separated list. |
Edwin Kempin | c2fc7bf | 2020-09-16 08:15:50 +0200 | [diff] [blame] | 239 | |
| 240 | In the example below, Jana Roe, John Doe and the code owners that are inherited |
| 241 | from parent `OWNERS` files are code owners of all files that are contained in |
| 242 | the directory that contains the `OWNERS` file. In addition Richard Roe is a code |
Edwin Kempin | 2b51383 | 2020-12-21 12:33:45 +0100 | [diff] [blame] | 243 | owner of the `docs.config` file in this directory and all `*.md` files in this |
| 244 | directory and the subdirectories. |
Edwin Kempin | c2fc7bf | 2020-09-16 08:15:50 +0200 | [diff] [blame] | 245 | |
| 246 | ``` |
| 247 | [email protected] |
| 248 | [email protected] |
| 249 | per-file docs.config,*[email protected] |
| 250 | ``` |
Edwin Kempin | 7c5ca32 | 2021-01-18 14:28:24 +0100 | [diff] [blame] | 251 | |
Edwin Kempin | 7b8a7c1 | 2020-09-23 15:28:08 +0200 | [diff] [blame] | 252 | ##### <a id="doNotUsePathExpressionsForSubdirectories"> |
Edwin Kempin | f0168ca | 2020-09-17 15:35:40 +0200 | [diff] [blame] | 253 | **NOTE:** It is discouraged to use path expressions that explicitly name |
Edwin Kempin | 2b51383 | 2020-12-21 12:33:45 +0100 | [diff] [blame] | 254 | subdirectories such as `my-subdir/*` as they will break when the subdirectory |
Edwin Kempin | f0168ca | 2020-09-17 15:35:40 +0200 | [diff] [blame] | 255 | gets 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 |
| 257 | the subdirectory gets renamed/moved. |
| 258 | |
Edwin Kempin | c2fc7bf | 2020-09-16 08:15:50 +0200 | [diff] [blame] | 259 | To grant per-file code ownership to more than one user multiple [user |
| 260 | emails](#userEmails) can be specified as comma-separated list, or an external |
| 261 | `OWNERS` file can be referenced via the [file](#fileKeyword) keyword. |
| 262 | Alternatively 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 | \ |
| 271 | When referencing an external `OWNERS` file via the [file](#fileKeyword) keyword, |
| 272 | only non-restricted [access grants](#accessGrants) are imported. This means |
| 273 | `per-file` rules from the referenced `OWNERS` file are not pulled in and also |
| 274 | any [set noparent](#setNoparent) line in the referenced `OWNERS` file is |
| 275 | ignored, but recursive imports are being resolved. |
| 276 | |
| 277 | Using the [include](#includeKeyword) keyword in combination with a `per-file` |
| 278 | rule is not possible. |
| 279 | |
| 280 | It's also possible to combine [set noparent](#setNoparent) with `per-file` rules |
| 281 | to prevent access by non-per-file owners from the current directory as well as |
| 282 | from parent directories. |
| 283 | |
| 284 | In the example below, Richard Roe is the only code owner of the `docs.config` |
Edwin Kempin | 2b51383 | 2020-12-21 12:33:45 +0100 | [diff] [blame] | 285 | file in this directory and all `*.md` files in this directory and the |
| 286 | subdirectories. All other files in this directory and its subdirectories are |
| 287 | owned by Jana Roe, John Doe and the code owners that are inherited from parent |
| 288 | directories. |
Edwin Kempin | c2fc7bf | 2020-09-16 08:15:50 +0200 | [diff] [blame] | 289 | |
| 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 Kempin | 74a4c2f | 2021-05-25 13:12:45 +0200 | [diff] [blame] | 297 | ### <a id="anotations">Annotations |
| 298 | |
| 299 | Lines representing [access grants](#accessGrants) can be annotated. Annotations |
| 300 | have the format `#{ANNOTATION_NAME}` and can appear at the end of the line. |
| 301 | E.g.: |
| 302 | |
| 303 | ``` |
Edwin Kempin | 9a80096 | 2021-06-11 10:04:53 +0200 | [diff] [blame] | 304 | [email protected] #{LAST_RESORT_SUGGESTION} |
| 305 | per-file docs.config,*[email protected] #{LAST_RESORT_SUGGESTION} |
Edwin Kempin | 74a4c2f | 2021-05-25 13:12:45 +0200 | [diff] [blame] | 306 | ``` |
| 307 | \ |
| 308 | Annotations can be mixed with [comments](#comments) that can appear before and |
| 309 | after annotations, E.g.: |
| 310 | |
| 311 | ``` |
Edwin Kempin | 9a80096 | 2021-06-11 10:04:53 +0200 | [diff] [blame] | 312 | [email protected] # foo bar #{LAST_RESORT_SUGGESTION} baz |
Edwin Kempin | 74a4c2f | 2021-05-25 13:12:45 +0200 | [diff] [blame] | 313 | ``` |
| 314 | \ |
| 315 | The following annotations are supported: |
| 316 | |
Edwin Kempin | 9a80096 | 2021-06-11 10:04:53 +0200 | [diff] [blame] | 317 | #### <a id="lastResortSuggestion"> |
| 318 | * `LAST_RESORT_SUGGESTION`: |
Edwin Kempin | 74a4c2f | 2021-05-25 13:12:45 +0200 | [diff] [blame] | 319 | Code owners with this annotation are omitted when [suggesting code |
Edwin Kempin | 66ee575 | 2021-06-09 13:35:57 +0200 | [diff] [blame] | 320 | 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 Kempin | 9a80096 | 2021-06-11 10:04:53 +0200 | [diff] [blame] | 324 | code owner gets omitted from the suggestion if it has the |
| 325 | `LAST_RESORT_SUGGESTION` set on any of the access grants. |
Edwin Kempin | 74a4c2f | 2021-05-25 13:12:45 +0200 | [diff] [blame] | 326 | |
| 327 | Unknown annotations are silently ignored. |
| 328 | |
| 329 | **NOTE:** If an access grant line that assigns code ownership to multiple users |
| 330 | has an annotation, this annotation applies to all these users. E.g. if an |
| 331 | annotation is set for the all users wildcard (aka `*`) it applies to all users. |
| 332 | |
Edwin Kempin | c2fc7bf | 2020-09-16 08:15:50 +0200 | [diff] [blame] | 333 | ### <a id="comments">Comments |
| 334 | |
| 335 | The '#' character indicates the beginning of a comment. Arbitrary text may be |
| 336 | added in comments. |
| 337 | |
Edwin Kempin | 3114804 | 2021-06-21 09:43:13 +0200 | [diff] [blame] | 338 | Comments can appear at the end of any line or consume the whole line (a line |
| 339 | starting with '#', `# <comment-test`). |
Edwin Kempin | c2fc7bf | 2020-09-16 08:15:50 +0200 | [diff] [blame] | 340 | |
| 341 | Comments are not interpreted by the `code-owners` plugin and are intended for |
| 342 | human readers of the `OWNERS` files. However some projects/teams may have own |
| 343 | tooling that uses comments to store additional information in `OWNERS` files. |
| 344 | |
Edwin Kempin | 9d486ed | 2020-09-15 15:05:23 +0200 | [diff] [blame] | 345 | --- |
| 346 | |
| 347 | Back to [@PLUGIN@ documentation index](index.html) |
| 348 | |
| 349 | Part of [Gerrit Code Review](../../../Documentation/index.html) |