blob: be2c40d2f682a6d6f52496fef8aab8c038d103c1 [file] [log] [blame] [view]
Edwin Kempin6b2a18c2020-09-22 17:04:56 +02001# Validation
2
3The code owners functionality relies on the validity of the following:
4
5* [code owner config files](user-guide.html#codeOwnerConfigFiles) that define
6 the code owners
7* [code-owner.config](config.html#projectLevelConfigFile) files in the
8 'refs/meta/config' branches of the projects that contain the project-level
9 configuration of the `@PLUGIN@` plugin
10
11To reduce the risk that these files become invalid, they are validated when
Edwin Kempin3d489e22020-09-30 12:57:08 +020012they are modified and invalid modifications are rejected. In addition code owner
13config files in a repository can be validated on demand by the [Check code
14owners files REST endpoint](rest-api.html#check-code-owner-config-files).
Edwin Kempin6b2a18c2020-09-22 17:04:56 +020015
16**NOTE:** Most configuration issues are gracefully handled and do not break the
17code owners functionality (e.g. non-resolveable code owners or non-resolveable
18imports are silently ignored), however some configuration issue (non-parseable
19configuration files, configuration of a non-existing [backend](backends.html)
20etc.) are severe errors and block the submission of all changes for which the
21affected configuration files are relevant.
22
Edwin Kempin205285a2020-12-01 09:53:04 +010023**NOTE:** It's possible to disable the validation of code owner config files on
24push and setup an [external
25validation](config-guide.html#externalValidationOfCodeOwnerConfigs) by a CI bot
26instead. In this case findings would be posted on the change.
27
Edwin Kempin6b2a18c2020-09-22 17:04:56 +020028All validations are best effort to prevent invalid configurations from
29entering the repository, but not all possible issues can be prevented. Doing the
30validation is useful since it prevents most issues and also gives quick feedback
31to uploaders about typos (e.g. if an email is misspelled it's not breaking
32anything, but the intended change of the uploader is not working).
33
34No validation is done when:
35
36* the `@PLUGIN@` plugin is not installed/enabled (this means when the `@PLUGIN@`
37 plugin gets installed/enabled, it is possible that invalid configuration files
38 already exist in the repository)
39* updates happen behind Gerrit's back (e.g. pushes that bypass Gerrit)
Edwin Kempinb05f24f2020-12-11 13:03:29 +010040* the validation is disabled via the
41 [enableValidationOnCommitReceived](config.html#codeOwnersEnableValidationOnCommitReceived)
42 or [enableValidationOnSubmit](config.html#codeOwnersEnableValidationOnSubmit)
43 config options
Edwin Kempinea5f8322021-03-12 15:37:48 +010044* the [--code-owners~skip-validation](#skipCodeOwnerConfigValidationOnDemand)
45 push option was specified on push
Edwin Kempin6b2a18c2020-09-22 17:04:56 +020046
47In addition for [code owner config files](user-guide.html#codeOwnerConfigFiles)
48no validation is done when:
49
50* the code owners functionality is disabled for the repository or branch (this
51 means when the code owners functionality gets enabled, it is possible that
52 invalid code owner configs already exist in the repository)
53* the `@PLUGIN@` plugin configuration is invalid (in this case we don't know
54 which files are code owner config files, so we allow all uploads rather than
55 blocking all uploads, to reduce the risk of breaking the plugin configuration
56 `code-owner.config` files are validated too)
57
Edwin Kempin29b692c2021-01-19 11:45:22 +010058## <a id="howCodeOwnerConfigsCanGetIssuesAfterSubmit">
Edwin Kempin6b2a18c2020-09-22 17:04:56 +020059In addition it is possible that [code owner config
60files](user-guide.hmtl#codeOwnerConfigFiles) get issues after they have been
61submitted:
62
63* configuration parameters that are relevant for the validation are changed
64 (e.g. the [accounts.visibility](../../../Documentation/config-gerrit.html#accounts.visibility)
65 setting is changed, [another code owners backend is
66 configured](setup-guide.html#configureCodeOwnersBackend) which now uses a
Edwin Kempinc85684a2021-01-19 12:01:01 +010067 different syntax or different names for code owner config files, the [file
68 extension for code owner config file is set/changed](config.html#codeOwnersFileExtension),
Edwin Kempin3ded05a2021-06-09 15:09:37 +020069 [arbitrary file extensions for code owner config files](config.html#codeOwnersEnableCodeOwnerConfigFilesWithFileExtensions)
70 get enabled/disabled or the [allowed email domains are
71 changed](config.html#pluginCodeOwnersAllowedEmailDomain))
Edwin Kempin6b2a18c2020-09-22 17:04:56 +020072* emails of users may change so that emails in code owner configs can no longer
73 be resolved
74* imported code owner config files may get deleted or renamed so that import
75 references can no longer be resolved
76
77When updating [code owner config files](user-guide.html#codeOwnerConfigFiles)
78the validation only rejects the update if it introduces **new** issues. This
79means the update is allowed if:
80
81* there are issues that are still present after the update, but the update
82 doesn't introduce any new issues
83* the file was non-parseable and the update makes it parseable, but issues are
84 present (since a parseable file with issues is better than a non-parseable
85 file)
86* the file was non-parseable and with the update it is still non-parseable
87
88For [code owner config files](user-guide.html#codeOwnerConfigFiles) the
Edwin Kempin1914db52021-03-24 15:31:23 +010089validation may also be performed on submit (in addition to the validation that
90is performed on upload of the change, see
91[enableValidationOnSubmit](config.html#codeOwnersEnableValidationOnSubmit)
92config setting). Repeating the validation on submit can make sense because
93relevant configuration can change between the time a change is uploaded and the
94time a change is submitted. If enabled, on submit we repeat the exact same
95validation that was done on upload. This means, all visibility checks will be
96done from the perspective of the uploader.
Edwin Kempin6b2a18c2020-09-22 17:04:56 +020097
Edwin Kempin2fd84e02021-05-17 09:02:53 +000098## <a id="skipCodeOwnerConfigValidationOnDemand">Skip code owner config validation on demand
99
Edwin Kempin65181c42021-06-15 14:32:12 +0200100By setting the `code-owners~skip-validation` push option it is possible to skip
101the code owner config validation on push:
102`git push -o code-owners~skip-validation origin HEAD:refs/for/master`
Edwin Kempin2fd84e02021-05-17 09:02:53 +0000103
Edwin Kempin0be91192021-06-15 14:28:41 +0200104For the [Create Change](../../../Documentation/rest-api-changes.html#create-change)
105REST endpoint skipping the code owner config validation is possible by setting
106`code-owners~skip-validation` with the value `true` as a validation option in
107the [ChangeInput](../../../Documentation/rest-api-changes.html#change-input)
108(see field `validation_options`).
109
Edwin Kempinec23f6e2022-02-10 09:20:31 +0100110Similarly, for the [Cherry Pick
111Revision](../../../Documentation/rest-api-changes.html#cherry-pick) REST endpoint
112skipping the code owner config validation is possible by setting
113`code-owners~skip-validation` with the value `true` as a validation option in
114the [CherryPickInput](../../../Documentation/rest-api-changes.html#cherrypick-input)
115(see field `validation_options`).
116
Edwin Kempin0be91192021-06-15 14:28:41 +0200117Using the push option or the validation option requires the calling user to
118have the `Can Skip Code Owner Config Validation` global capability. Host
119administrators have this capability implicitly assigned via the `Administrate
120Server` global capability.
Edwin Kempin2fd84e02021-05-17 09:02:53 +0000121
122**NOTE:** Using this option only makes sense if the [code owner config validation
123on submit](config.html#pluginCodeOwnersEnableValidationOnSubmit) is disabled, as
124otherwise it's not possible to submit the created change (using the push option
125only skips the validation for the push, but not for the submission of the
126change).
127
Edwin Kempin6b2a18c2020-09-22 17:04:56 +0200128### <a id="codeOwnerConfigFileChecks">Validation checks for code owner config files
129
130For [code owner config files](user-guide.html#codeOwnerConfigFiles) the
131following checks are performed:
132
133* the code owner config files are parseable
Edwin Kempin91664dd2021-03-24 14:12:50 +0100134* the code owner emails are resolveable (unless this check is
135 [disabled](config.html#codeOwnersRejectNonResolvableCodeOwners)):\
Edwin Kempin6b2a18c2020-09-22 17:04:56 +0200136 a code owners email is not resolveable if:
137 * the account that owns it is inactive
138 * the account that owns it is not visible to the uploader (according to
139 [accounts.visibility](../../../Documentation/config-gerrit.html#accounts.visibility)
140 setting)
141 * it is a non-visible secondary email
142 * there is no account that has this email assigned
Edwin Kempinba6cd402021-02-24 10:11:35 +0100143 * it is ambiguous (the same email is assigned to multiple active accounts)
Edwin Kempin6b2a18c2020-09-22 17:04:56 +0200144 * it has an email domain that is disallowed (see
145 [allowedEmailDomain](config.html#pluginCodeOwnersAllowedEmailDomain))
146 configuration
Edwin Kempin91664dd2021-03-24 14:12:50 +0100147* the imports are resolveable (unless this check is
148 [disabled](config.html#codeOwnersRejectNonResolvableImports)):\
Edwin Kempin6b2a18c2020-09-22 17:04:56 +0200149 an import is not resolveable if:
150 * the imported file is not a code owner config file
151 * the imported file is not parseable
152 * the imported file doesn't exists
153 * the branch from which the file should be imported doesn't exist or is not
154 visible to the uploader
155 * the project from which the file should be imported doesn't exist or is not
156 visible to the uploader
157 * the project from which the file should be imported doesn't permit reads
158 (e.g. has the state `HIDDEN`)
159
Edwin Kempin21660042020-12-11 15:42:54 +0100160**NOTE:** Whether commits that newly add non-resolvable code owners and
161non-resolvable imports are rejected on commit received and on submit is
162controlled by the
163[rejectNonResolvableCodeOwners](config.html#pluginCodeOwnersRejectNonResolvableCodeOwners)
164and [rejectNonResolvableImports](config.html#pluginCodeOwnersRejectNonResolvableImports)
165config settings.
166
Edwin Kempin6b2a18c2020-09-22 17:04:56 +0200167The following things are **not** checked (not an exhaustive list):
168
169* Cycles in imports of owner config files:\
170 Detecting cycles in imports can be expensive and they are not seen as a
171 problem. When imports are resolved we keep track of the imported code owner
172 config files and stop if we see a code owner config file that weve imported
173 already. This behaviour is consistent with how Gerrit handles cycles in group
174 includes.
175* Impossible code owner configurations:\
176 It is possible to create a code owner configuration where some folders/files
177 have no code owners. In this case nobody can give a code owner approval for
178 these folders/files, and submitting changes to them requires a
179 [code owner override](user-guide.html#codeOwnerOverride).
180
181
Edwin Kempinbdb32822020-12-11 14:05:24 +0100182### <a id="codeOwnersConfigFileChecks">Validation checks for code-owners.config files
Edwin Kempin6b2a18c2020-09-22 17:04:56 +0200183
184For the [code-owner.config](config.html#projectLevelConfigFile) in the
185`refs/meta/config` branch the following checks are performed:
186
187* `code-owner.config` file is parseable
188* the [codeOwners.backend](config.html#codeOwnersBackend) and
189 [codeOwners.\<branch\>.backend](config.html#codeOwnersBranchBackend)
190 configurations are valid (that they reference an existing [code owner
191 backend](backends.html))
192* the [codeOwners.disabled](config.html#codeOwnersDisabled) and
193 [codeOwners.disabledBranch](config.html#codeOwnersDisabledBranch)
194 configurations are valid (that they have parseable value)
195* the [codeOwners.requiredApproval](config.html#codeOwnersRequiredApproval)
196 and [codeOwners.overrideApproval](config.html#codeOwnersOverrideApproval)
197 configurations are valid (that they reference an existing label that has a
198 range that covers the specified voting value, it's currently not possible to
199 add the definition of this label in the same commit but it must be present
200 before)
Edwin Kempin748b63a2020-09-24 09:13:50 +0200201* the [codeOwners.mergeCommitStrategy](config.html#codeOwnersMergeCommitStrategy)
202 configuration is valid
Edwin Kempine1849882020-11-26 13:19:13 +0100203* the [codeOwners.fallbackCodeOwners](config.html#codeOwnersFallbackCodeOwners)
204 configuration is valid
Edwin Kempinaa2c2552020-12-14 09:29:29 +0100205* the [codeOwners.maxPathsInChangeMessages](config.html#codeOwnersMaxPathsInChangeMessages)
206 configuration is valid
Edwin Kempin6b2a18c2020-09-22 17:04:56 +0200207
208---
209
210Back to [@PLUGIN@ documentation index](index.html)
211
212Part of [Gerrit Code Review](../../../Documentation/index.html)