blob: 601f2bfa9086fe1636c7a0389aed130118d606de [file] [log] [blame]
Youssef Elghareeb78287a42021-12-06 17:04:23 +01001= Gerrit Code Review - Submit Requirements
2
3As part of the code review process, project owners need to configure rules that
4govern when changes become submittable. For example, an admin might want to
5prevent changes from being submittable until at least a “+2” vote on the
6“Code-Review” label is granted on a change. Admins can define submit
7requirements to enforce submittability rules for changes.
8
9[[configuring_submit_requirements]]
10== Configuring Submit Requirements
11
12Site administrators and project owners can define submit requirements in the
13link:config-project-config.html[project config]. A submit requirement has the
14following fields:
15
16
17[[submit_requirement_name]]
18=== submit-requirement.Name
19
20A name that uniquely identifies the submit requirement. Submit requirements
21can be overridden in child projects if they are defined with the same name in
22the child project. See the link:#inheritance[inheritance] section for more
23details.
24
25[[submit_requirement_description]]
26=== submit-requirement.Name.description
27
28A detailed description of what the submit requirement is supposed to do. This
29field is optional. The description is visible to the users in the change page
30upon hovering on the submit requirement to help them understand what the
31requirement is about and how it can be fulfilled.
32
33[[submit_requirement_applicable_if]]
34=== submit-requirement.Name.applicableIf
35
36A link:#query_expression_syntax[query expression] that determines if the submit
37requirement is applicable for a change. For example, administrators can exclude
38submit requirements for certain branch patterns. See the
39link:#exempt-branch-example[exempt branch] example.
40
Edwin Kempin329416c2022-07-25 15:52:35 +020041Often submit requirements should only apply to branches that contain source
42code. In this case this parameter can be used to exclude the
43link:config-project-config.html#refs-meta-config[refs/meta/config] branch from
44a submit requirement:
45
46----
47 applicableIf = -branch:refs/meta/config
48----
49
Youssef Elghareeb78287a42021-12-06 17:04:23 +010050This field is optional, and if not specified, the submit requirement is
51considered applicable for all changes in the project.
52
53[[submit_requirement_submittable_if]]
54=== submit-requirement.Name.submittableIf
55
56A link:#query_expression_syntax[query expression] that determines when the
57change becomes submittable. This field is mandatory.
58
59
60[[submit_requirement_override_if]]
61=== submit-requirement.Name.overrideIf
62
63A link:#query_expression_syntax[query expression] that controls when the
64submit requirement is overridden. When this expression is evaluated to true,
65the submit requirement state becomes `OVERRIDDEN` and the submit requirement
66is no longer blocking the change submission.
67This expression can be used to enable bypassing the requirement in some
68circumstances, for example if the change owner is a power user or to allow
69change submission in case of emergencies. +
70
71This field is optional.
72
73[[submit_requirement_can_override_in_child_projects]]
74=== submit-requirement.Name.canOverrideInChildProjects
75
76A boolean (true, false) that determines if child projects can override the
77submit requirement. +
78
79The default value is `false`.
80
81[[evaluation_results]]
82== Evaluation Results
83
84When submit requirements are configured, their results are returned for all
85changes requested by the REST API with the
86link:rest-api-changes.html#submit-requirement-result-info[SubmitRequirementResultInfo]
87entity. +
88
89Submit requirement results are produced from the evaluation of the submit
90requirements in the project config (
91See link:#configuring_submit_requirements[Configuring Submit Requirements])
92as well as the conversion of the results of the legacy submit rules to submit
93requirement results. Legacy submit rules are label functions
94(see link:config-labels.html[config labels]), custom and
95link:prolog-cookbook.html[prolog] submit rules.
96
97The `status` field can be one of:
98
99* `NOT_APPLICABLE`
100+
101The link:#submit_requirement_applicable_if[applicableIf] expression evaluates
102to false for the change.
103
104* `UNSATISFIED`
105+
106The submit requirement is applicable
107(link:#submit_requirement_applicable_if[applicableIf] evaluates to true), but
108the evaluation of the link:#submit_requirement_submittable_if[submittableIf] and
109link:#submit_requirement_override_if[overrideIf] expressions return false for
110the change.
111
112* `SATISFIED`
113+
114The submit requirement is applicable
115(link:#submit_requirement_applicable_if[applicableIf] evaluates to true), the
116link:#submit_requirement_submittable_if[submittableIf] expression evaluates to
117true, and the link:#submit_requirement_override_if[overrideIf] evaluates to
118false for the change.
119
120* `OVERRIDDEN`
121+
122The submit requirement is applicable
123(link:#submit_requirement_applicable_if[applicableIf] evaluates to true) and the
124link:#submit_requirement_override_if[overrideIf] expression evaluates to true.
125+
126Note that in this case, the change is overridden whether the
127link:#submit_requirement_submittable_if[submittableIf] expression evaluates to
128true or not.
129
130* `BYPASSED`
131+
132The change was merged directly bypassing code review by supplying the
133link:user-upload.html#auto_merge[submit] push option while doing a git push.
134
135* `ERROR`
136+
137The evaluation of any of the
138link:#submit_requirement_applicable_if[applicableIf],
139link:#submit_requirement_submittable_if[submittableIf] or
140link:#submit_requirement_override_if[overrideIf] expressions resulted in an
141error.
142
143
144[[query_expression_syntax]]
145== Query Expression Syntax
146
147All applicableIf, submittableIf and overrideIf expressions use the same syntax
148and operators available for link:user-search.html[searching changes]. In
149addition to that, submit requirements support extra operators.
150
151
152[[submit_requirements_operators]]
153=== Submit Requirements Operators
154
Youssef Elghareeb2c2d7512022-02-23 13:24:20 +0100155[[operator_authoremail]]
156authoremail:'EMAIL_PATTERN'::
157+
158An operator that returns true if the change author's email address matches a
159specific regular expression pattern. The
160link:http://www.brics.dk/automaton/[dk.brics.automaton library,role=external,window=_blank]
161is used for the evaluation of such patterns.
162
Patrick Hiesel02fc668d2022-02-23 16:01:04 +0100163[[operator_distinctvoters]]
164distinctvoters:'[Label1,Label2,...,LabelN],value=MAX,count>1'::
165+
166An operator that allows checking for distinct voters across more than one label.
167+
1682..N labels are supported, filtering by a value (MIN,MAX,integer) is optional.
169Count is mandatory.
170+
171Examples:
172`distinctvoters:[Code-Review,Trust],value=MAX,count>1`
173+
174`distinctvoters:[Code-Review,Trust,API-Review],count>2`
175
Youssef Elghareeb78287a42021-12-06 17:04:23 +0100176[[operator_is_true]]
177is:true::
178+
179An operator that always returns true for all changes. An example usage is to
180redefine a submit requirement in a child project and make the submit requirement
181always applicable.
182
183[[operator_is_false]]
184is:false::
185+
186An operator that always returns false for all changes. An example usage is to
187redefine a submit requirement in a child project and make the submit requirement
188always non-applicable.
189
Youssef Elghareeba6202202022-10-24 17:59:04 +0200190[[operator_has_submodule_update]]
191has:submodule-update::
192+
193An operator that returns true if the diff of the latest patchset against the
194default parent has a submodule modified file, that is, a ".gitmodules" or a
195git link file.
196+
197The optional `base` parameter can also be supplied for merge commits like
198`has:submodule-update,base=1`, or `has:submodule-update,base=2`. In these cases,
199the operator returns true if the diff of the latest patchset against parent
200number identified by `base` has a submodule modified file. Note that the
201operator will return false if the base parameter is greater than the number of
202parents for the latest patchset for the change.
203
Youssef Elghareeb79087952022-03-08 14:05:33 +0100204[[operator_file]]
205file:"'<filePattern>',withDiffContaining='<contentPattern>'"::
206+
207An operator that returns true if the latest patchset contained a modified file
208matching `<filePattern>` with a modified region matching `<contentPattern>`.
209
Youssef Elghareeb78287a42021-12-06 17:04:23 +0100210[[unsupported_operators]]
211=== Unsupported Operators
212
213Some operators are not supported with submit requirement expressions.
214
215[[operator_is_submittable]]
216is:submittable::
217+
218Cannot be used since it will result in recursive evaluation of expressions.
219
220[[inheritance]]
221== Inheritance
222
223Child projects can override a submit requirement defined in any of their parent
224projects. Overriding a submit requirement overrides all of its properties and
225values. The overriding project needs to define all mandatory fields.
226
227Submit requirements are looked up from the current project up the inheritance
228hierarchy to “All-Projects”. The first project in the hierarchy chain that sets
229link:#submit_requirement_can_override_in_child_projects[canOverrideInChildProjects]
230to false prevents all descendant projects from overriding it.
231
232If a project disallows a submit requirement from being overridden in child
233projects, all definitions of this submit requirement in descendant projects are
234ignored.
235
236To remove a submit requirement in a child project, administrators can redefine
237the requirement with the same name in the child project and set the
238link:#submit_requirement_applicable_if[applicableIf] expression to `is:false`.
239Since the link:#submit_requirement_submittable_if[submittableIf] field is
240mandatory, administrators need to provide it in the child project but can set it
241to anything, for example `is:false` but it will have no effect anyway.
242
243
244[[trigger-votes]]
245== Trigger Votes
246
247Trigger votes are label votes that are not associated with any submit
248requirement expressions. Trigger votes are displayed in a separate section in
249the change page. For more about configuring labels, see the
250link:config-labels.html[config labels] documentation.
251
252
253[[examples]]
254== Examples
255
256[[code-review-example]]
257=== Code-Review Example
258
259To define a submit requirement for code-review that requires a maximum vote for
260the “Code-Review” label from a non-uploader without a maximum negative vote:
261
262----
263[submit-requirement "Code-Review"]
264 description = A maximum vote from a non-uploader is required for the \
265 'Code-Review' label. A minimum vote is blocking.
266 submittableIf = label:Code-Review=MAX,user=non_uploader AND -label:Code-Review=MIN
267 canOverrideInChildProjects = true
268----
269
270[[exempt-branch-example]]
271=== Exempt a branch Example
272
273We could exempt a submit requirement from certain branches. For example,
274project owners might want to skip the 'Code-Style' requirement from the
275refs/meta/config branch.
276
277----
278[submit-requirement "Code-Style"]
279 description = Code is properly styled and formatted
280 applicableIf = -branch:refs/meta/config
281 submittableIf = label:Code-Style=+1 AND -label:Code-Style=-1
282 canOverrideInChildProjects = true
283----
284
Youssef Elghareebfdf38fa2022-04-07 13:53:23 +0200285
286[[test-submit-requirements]]
287== Testing Submit Requirements
288
289The link:rest-api-changes.html#check-submit-requirement[Check Submit Requirement]
290change endpoint can be used to test submit requirements on any change. Users
291are encouraged to test submit requirements before adding them to the project
292to ensure they work as intended.
293
294.Request
295----
296 POST /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/check.submit_requirement HTTP/1.0
297 Content-Type: application/json; charset=UTF-8
298
299 {
300 "name": "Code-Review",
301 "submittability_expression": "label:Code-Review=+2"
302 }
303----
304
305.Response
306----
307 HTTP/1.1 200 OK
308 Content-Disposition: attachment
309 Content-Type: application/json; charset=UTF-8
310
311 )]}'
312 {
313 "name": "Code-Review",
314 "status": "SATISFIED",
315 "submittability_expression_result": {
316 "expression": "label:Code-Review=+2",
317 "fulfilled": true,
318 "passingAtoms": [
319 "label:Code-Review=+2"
320 ]
321 },
322 "is_legacy": false
323 }
324----
325
Youssef Elghareeb78287a42021-12-06 17:04:23 +0100326GERRIT
327------
328Part of link:index.html[Gerrit Code Review]
329
330SEARCHBOX
331---------