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