Christian Aistleitner | 1179f72 | 2014-09-11 09:25:54 +0200 | [diff] [blame] | 1 | Rule base configuration |
| 2 | ======================= |
| 3 | |
| 4 | #### Table of Contents |
| 5 | * [Overview][overview] |
| 6 | * [Rules][rules] |
| 7 | * [Conditions][conditions] |
| 8 | * [Event Properties][event-properties] |
| 9 | * [Actions][actions] |
| 10 | |
| 11 | [overview]: #overview |
| 12 | <a name="overview">Overview</a> |
| 13 | ------------------------------- |
| 14 | |
| 15 | In this part we describe how to specify which events in Gerrit (E.g.: |
| 16 | “Change Merged”, or “User ‘John Doe’ voted ‘+2’ for ‘Code-Review’ on a |
| 17 | change”) trigger which actions (e.g.: “Set issue's status to |
| 18 | ‘Resolved’”) on the ITS. |
| 19 | |
| 20 | Actions on the ITS and conditions for the action to take place are |
Christian Aistleitner | 162d2c6 | 2014-10-05 21:02:46 +0200 | [diff] [blame] | 21 | configured through the rule bases in `etc/its/actions.config` (for global rules |
| 22 | to be picked up by all configured ITS plugins) and |
| 23 | `etc/its/actions-@PLUGIN@.config` (for rules to be picked up only by @PLUGIN@) |
| 24 | in the site directory. A rule base is a git config file, and may contain an |
| 25 | arbitrary number of rules. Each rule can have an arbitrary number of conditions |
| 26 | and actions. A rule fires all associated actions, once all of its conditions are |
| 27 | met. |
Christian Aistleitner | 1179f72 | 2014-09-11 09:25:54 +0200 | [diff] [blame] | 28 | |
Christian Aistleitner | 162d2c6 | 2014-10-05 21:02:46 +0200 | [diff] [blame] | 29 | A simple `etc/its/actions.config` (or |
| 30 | `etc/its/actions-@PLUGIN@.config`) may look like |
Christian Aistleitner | 1179f72 | 2014-09-11 09:25:54 +0200 | [diff] [blame] | 31 | |
| 32 | ``` |
| 33 | [rule "rule1"] |
| 34 | event-type = change-merged |
| 35 | action = add-standard-comment |
| 36 | [rule "rule2"] |
| 37 | event-type = comment-added |
| 38 | approval-Code-Review = -2,-1 |
| 39 | action = add-comment Oh my Goodness! Someone gave a negative code review in Gerrit on an associated change. |
| 40 | ``` |
| 41 | |
| 42 | This snippet defines two rules (`rule1`, and `rule2`). On merging a |
| 43 | change that's associated to some issues, `rule1` adds a predefined |
| 44 | standard comment for “Change Merged” to each such issue. If someone |
| 45 | adds a comment to a change that is associated to some issues and votes |
| 46 | “-2”, or “-1” for “Code-Review”, `rule2` adds the comment “Oh my |
| 47 | Goodness! Someone gave a negative code review in Gerrit on an |
| 48 | associated change.” to each such issue. |
| 49 | |
Khai Do | 7a29a3a | 2014-12-18 13:20:35 -0800 | [diff] [blame] | 50 | The order of rules in `etc/its/actions.config` need not be |
Christian Aistleitner | 1179f72 | 2014-09-11 09:25:54 +0200 | [diff] [blame] | 51 | respected. So in the above example, do not rely on `rule1` being |
| 52 | evaluated before `rule2`. |
| 53 | |
| 54 | [rules]: #rules |
| 55 | <a name="rules">Rules</a> |
| 56 | ------------------------- |
| 57 | |
| 58 | Each rule consists of three items: A name, a set of conditions, and a |
| 59 | set of actions. |
| 60 | |
| 61 | The rule's name (`rule1`, and `rule2` in the above example) is |
| 62 | currently not used and only provided for convenience. |
| 63 | |
| 64 | For each rule the option `action` is interpreted as action. Any other |
| 65 | option of a rule is considered a condition. |
| 66 | |
| 67 | Each of a rule's actions is taken for events that meet all of a |
| 68 | rule's conditions. If a rule contains more than one action |
| 69 | specifications, the order in which they are given need not be |
| 70 | respected. |
| 71 | |
| 72 | There is no upper limit on the number of elements in a rules set of |
| 73 | conditions, and set of actions. Each of those sets may be empty. |
| 74 | |
| 75 | [conditions]: #conditions |
| 76 | <a name="conditions">Conditions</a> |
| 77 | ----------------------------------- |
| 78 | |
| 79 | The conditions are lines of the form |
| 80 | |
| 81 | ``` |
| 82 | name = value1, value2, ..., valueN |
| 83 | ``` |
| 84 | |
| 85 | and match (if 'value1' is not `!`), if the event comes with a property |
| 86 | 'name' having 'value1', or 'value2', or ..., or 'valueN'. So for |
| 87 | example to match events that come with an `association` property |
| 88 | having `subject`, or `footer-Bug`, the following condition can be |
| 89 | used: |
| 90 | |
| 91 | ``` |
| 92 | association = subject,footer-Bug |
| 93 | ``` |
| 94 | |
| 95 | If 'value1' is `!`, the conditon matches if the event does not come |
| 96 | with a property 'name' having 'value2', or ..., or 'valueN'. So for |
| 97 | example to match events that do not come with a `status` property |
| 98 | having `DRAFT`, the following condition can be used: |
| 99 | |
| 100 | ``` |
| 101 | status = !,DRAFT |
| 102 | ``` |
| 103 | |
| 104 | [event-properties]: #event-properties |
| 105 | <a name="event-properties">Event Properties</a> |
| 106 | ----------------------------------------------- |
| 107 | |
| 108 | The properties exposed by events depend on the kind of event. |
| 109 | |
| 110 | For all events, the event's class name is provided in the `event` |
| 111 | property. Most native Gerrit events provide the `event-type` |
| 112 | property. So `event-type` (or `event` for other events fired by |
| 113 | plugins) allows you to write filters that fire only for a certain type |
| 114 | of event. |
| 115 | |
| 116 | The common properties for each event are |
| 117 | |
| 118 | `event` |
| 119 | : The event's class name. |
| 120 | |
| 121 | `issue` |
| 122 | : Issue to which this event is associated. Each event is associated to |
| 123 | exactly one issue. If for example an event is fired for a commit |
| 124 | message, that would contain more than one issue id (say issue “23”, |
| 125 | and issue “47”), then the event is duplicated and sent once for each |
| 126 | associated issue (i.e.: once with `issue` being `23`, and once with |
| 127 | `issue` being `47`). |
| 128 | |
| 129 | `association` |
| 130 | : How the issue of property `issue` got associated to this event. |
| 131 | See [Property: `association`][property-association]. |
| 132 | |
Christian Aistleitner | 823cabd | 2014-10-05 23:00:29 +0200 | [diff] [blame^] | 133 | `its-name` |
| 134 | : Name of this plugin (i.e.: `@PLUGIN@`). This property can be used to |
| 135 | make a rule in the rulebase match only for certain ITS plugins, if more |
| 136 | than one is installed. |
| 137 | |
| 138 | For example |
| 139 | |
| 140 | ``` |
| 141 | [rule "someRuleForBugzillaOnly"] |
| 142 | its-name = its-bugzilla |
| 143 | approval-Code-Review = -2 |
| 144 | action = add-comment Heya Bugzilla users, the change had a -2 Code-Review approval. |
| 145 | [rule "someRuleForJiraOnly"] |
| 146 | its-name = its-jira |
| 147 | approval-Code-Review = -2 |
| 148 | action = add-comment Dear JIRA users, the change had a -2 Code-Review approval. |
| 149 | ``` |
| 150 | |
| 151 | would report the “Heya Bugzilla...” text only through its-bugzilla for |
| 152 | changes that had a -2 Code-Review and have an association through |
| 153 | its-bugzilla. And for changes that had a -2 Code-Review and have an |
| 154 | association through its-jira, its-jira would report “Dear Jira users, ...”. |
Christian Aistleitner | 1179f72 | 2014-09-11 09:25:54 +0200 | [diff] [blame] | 155 | |
| 156 | The further properties are listed in the event's |
| 157 | corresponding subsection below: |
| 158 | |
| 159 | * [ChangeAbandonedEvent][event-properties-ChangeAbandonedEvent] |
| 160 | * [ChangeMergedEvent][event-properties-ChangeMergedEvent] |
| 161 | * [ChangeRestoredEvent][event-properties-ChangeRestoredEvent] |
| 162 | * [CommentAddedEvent][event-properties-CommentAddedEvent] |
| 163 | * [DraftPublishedEvent][event-properties-DraftPublishedEvent] |
| 164 | * [PatchSetCreatedEvent][event-properties-PatchSetCreatedEvent] |
| 165 | * [RefUpdatedEvent][event-properties-RefUpdatedEvent] |
| 166 | * [Common properties for events on a change][event-properties-change] |
| 167 | * [Common properties for events on a patch set][event-properties-patch-set] |
| 168 | |
| 169 | [property-association]: #property-association |
| 170 | ### <a name="property-association">Property: `association`</a> |
| 171 | |
| 172 | The property `association` describes how the `issue` got associated to |
| 173 | this event. |
| 174 | |
| 175 | An event typically has several `association` properties. Possible |
| 176 | values are: |
| 177 | |
| 178 | `somewhere` |
| 179 | : issue id occurs somewhere in the commit message of the change/the |
| 180 | most recent patch set. |
| 181 | |
| 182 | `subject` |
| 183 | : issue id occurs in the first line of the commit message of the |
| 184 | change/the most recent patch set. |
| 185 | |
| 186 | `body` |
| 187 | : issue id occurs after the subject but before the footer of the |
| 188 | commit message of the change/the most recent patch set. |
| 189 | |
| 190 | `footer` |
| 191 | : issue id occurs in the last paragraph after the subject of the |
| 192 | commit message of the change/the most recent patch set |
| 193 | |
| 194 | `footer-<Key>` |
| 195 | : issue id occurs in the footer of the commit message of the |
| 196 | change/the most recent patch set, and is in a line with a key |
| 197 | (part before the colon). |
| 198 | |
| 199 | So for example, if the footer would contain a line |
| 200 | |
| 201 | ``` |
| 202 | Fixes-Issue: issue 4711 |
| 203 | ``` |
| 204 | |
| 205 | then a property `association` with value `footer-Fixes-Issue` |
| 206 | would get added to the event for issue “4711”. |
| 207 | |
| 208 | `added@<Association-Value>` |
| 209 | : (only for events that allow to determine the patch set number. |
| 210 | So for example, this `association` property is not set for |
| 211 | RevUpdatedEvents) |
| 212 | |
| 213 | issue id occurs at `<Association-Value>` in the most recent |
| 214 | patch set of the change, and either the event is for patch set |
| 215 | 1 or the issue id does not occur at `<Association-Value>` in |
| 216 | the previous patch set. |
| 217 | |
| 218 | So for example if issue “4711” occurs in the subject of patch |
| 219 | set 3 (the most recent patch set) of a change, but not in |
| 220 | patch set 2. When adding a comment to this change, the event |
| 221 | for issue “4711” would get a property 'association' with value |
| 222 | `added@subject`. |
| 223 | |
| 224 | [event-properties-ChangeAbandonedEvent]: #event-properties-ChangeAbandonedEvent |
| 225 | ### <a name="event-properties-ChangeAbandonedEvent">ChangeAbandonedEvent</a> |
| 226 | |
| 227 | `abandoner-email` |
| 228 | : email address of the user abandoning the change. |
| 229 | |
| 230 | `abandoner-name` |
| 231 | : name of the user abandoning the change. |
| 232 | |
| 233 | `abandoner-username` |
| 234 | : username of the user abandoning the change. |
| 235 | |
| 236 | `event` |
| 237 | : `com.google.gerrit.server.events.ChangeAbandonedEvent` |
| 238 | |
| 239 | `event-type` |
| 240 | : `change-abandoned` |
| 241 | |
| 242 | `reason` |
| 243 | : reason why the change has been abandoned. |
| 244 | |
| 245 | In addition to the above properties, the event also provides |
| 246 | properties for the abandoned [Change][event-properties-change], and |
| 247 | its most recent [Patch Set][event-properties-patch-set]. |
| 248 | |
| 249 | [event-properties-ChangeMergedEvent]: #event-properties-ChangeMergedEvent |
| 250 | ### <a name="event-properties-ChangeMergedEvent">ChangeMergedEvent</a> |
| 251 | |
| 252 | `event` |
| 253 | : `com.google.gerrit.server.events.ChangeMergedEvent` |
| 254 | |
| 255 | `event-type` |
| 256 | : `change-merged` |
| 257 | |
| 258 | `submitter-email` |
| 259 | : email address of the user causing the merge of the change. |
| 260 | |
| 261 | `submitter-name` |
| 262 | : name of the user causing the merge of the change. |
| 263 | |
| 264 | `submitter-username` |
| 265 | : username of the user causing the merge of the change. |
| 266 | |
| 267 | In addition to the above properties, the event also provides |
| 268 | properties for the merged [Change][event-properties-change], and its |
| 269 | most recent [Patch Set][event-properties-patch-set]. |
| 270 | |
| 271 | [event-properties-ChangeRestoredEvent]: #event-properties-ChangeRestoredEvent |
| 272 | ### <a name="event-properties-ChangeRestoredEvent">ChangeRestoredEvent</a> |
| 273 | |
| 274 | `event` |
| 275 | : `com.google.gerrit.server.events.ChangeRestoredEvent` |
| 276 | |
| 277 | `event-type` |
| 278 | : `change-restored` |
| 279 | |
| 280 | `reason` |
| 281 | : reason why the change has been restored. |
| 282 | |
| 283 | `restorer-email` |
| 284 | : email address of the user restoring the change. |
| 285 | |
| 286 | `restorer-name` |
| 287 | : name of the user restoring the change. |
| 288 | |
| 289 | `restorer-username` |
| 290 | : username of the user restoring the change. |
| 291 | |
| 292 | In addition to the above properties, the event also provides |
| 293 | properties for the restored [Change][event-properties-change], and it's |
| 294 | most recent [Patch Set][event-properties-patch-set]. |
| 295 | |
| 296 | [event-properties-CommentAddedEvent]: #event-properties-CommentAddedEvent |
| 297 | ### <a name="event-properties-CommentAddedEvent">CommentAddedEvent</a> |
| 298 | |
| 299 | NOTE: For consistency with the other events, the `author-...` |
| 300 | properties of the CommentAddedEvent do not refer to the author of the |
| 301 | comment, but refer to the author of the change's latest patch set. The |
| 302 | author of the comment is accessible via the `commenter-...` |
| 303 | properties. |
| 304 | |
| 305 | `commenter-email` |
| 306 | : email address of the comment's author. |
| 307 | |
| 308 | `commenter-name` |
| 309 | : name of the comment's author. |
| 310 | |
| 311 | `commenter-username` |
| 312 | : username of the comment's author. |
| 313 | |
| 314 | `comment` |
| 315 | : added comment itself. |
| 316 | |
| 317 | `event` |
| 318 | : `com.google.gerrit.server.events.CommentAddedEvent+ |
| 319 | |
| 320 | `event-type` |
| 321 | : `comment-added` |
| 322 | |
| 323 | For each new or changed approval that has been made for this change, a |
| 324 | property of key `approval-<LabelName>` and the approval's value as |
| 325 | value is added. So for example voting “-2” for the approval |
| 326 | “Code-Review” would add the following property: |
| 327 | |
| 328 | `approval-Code-Review` |
| 329 | : `-2` |
| 330 | |
| 331 | In addition to the above properties, the event also provides |
| 332 | properties for the [Change][event-properties-change] the comment was |
| 333 | added for, and it's most recent [Patch Set][event-properties-patch-set]. |
| 334 | |
| 335 | [event-properties-DraftPublishedEvent]: #event-properties-DraftPublishedEvent |
| 336 | ### <a name="event-properties-DraftPublishedEvent">DraftPublishedEvent</a> |
| 337 | |
| 338 | `event` |
| 339 | : `com.google.gerrit.server.events.DraftPublishedEvent` |
| 340 | |
| 341 | `event-type` |
| 342 | : `draft-published` |
| 343 | |
| 344 | In addition to the above properties, the event also provides |
| 345 | properties for the uploaded [Patch Set][event-properties-patch-set], |
| 346 | and the [Change][event-properties-change] it belongs to. |
| 347 | |
| 348 | [event-properties-PatchSetCreatedEvent]: #event-properties-PatchSetCreatedEvent |
| 349 | ### <a name="event-properties-PatchSetCreatedEvent">PatchSetCreatedEvent</a> |
| 350 | |
| 351 | `event` |
| 352 | : `com.google.gerrit.server.events.PatchSetCreatedEvent` |
| 353 | |
| 354 | `event-type` |
| 355 | : `patchset-created` |
| 356 | |
| 357 | In addition to the above properties, the event also provides |
| 358 | properties for the uploaded [Patch Set][event-properties-patch-set], |
| 359 | and the [Change][event-properties-change] it belongs to. |
| 360 | |
| 361 | [event-properties-RefUpdatedEvent]: #event-properties-RefUpdatedEvent |
| 362 | ### <a name="event-properties-RefUpdatedEvent">RefUpdatedEvent</a> |
| 363 | |
| 364 | `event` |
| 365 | : `com.google.gerrit.server.events.RefUpdatedEvent` |
| 366 | |
| 367 | `event-type` |
| 368 | : `ref-updated` |
| 369 | |
| 370 | `project` |
| 371 | : full name of the project from which a ref was updated. |
| 372 | |
| 373 | `ref` |
| 374 | : git ref that has been updated (Typcially the branch, as for example |
| 375 | `master`). |
| 376 | |
| 377 | `revision` |
| 378 | : git commit hash the rev is pointing to now. |
| 379 | |
| 380 | `revision-old` |
| 381 | : git commit hash the rev was pointing to before. |
| 382 | |
| 383 | `submitter-email` |
| 384 | : email address of the user that updated the ref. |
| 385 | |
| 386 | `submitter-name` |
| 387 | : name of the user that updated the ref. |
| 388 | |
| 389 | `submitter-username` |
| 390 | : username of the user that updated the ref. |
| 391 | |
| 392 | [event-properties-change]: #event-properties-change |
| 393 | ### <a name="event-properties-change">Common properties for events on a change</a> |
| 394 | |
| 395 | `branch` |
| 396 | : name of the branch the change belongs to. |
| 397 | |
| 398 | `change-id` |
| 399 | : Change-Id for the change („I-followed by 40 hex digits” string). |
| 400 | |
| 401 | `change-number` |
| 402 | : number for the change (plain integer). |
| 403 | |
| 404 | `change-url` |
| 405 | : url of the change. |
| 406 | |
| 407 | `owner-email` |
| 408 | : email address of the change's owner. |
| 409 | |
| 410 | `owner-name` |
| 411 | : name of the change's owner. |
| 412 | |
| 413 | `owner-username` |
| 414 | : username of the change's owner. |
| 415 | |
| 416 | `project` |
| 417 | : full name of the project the change belongs to. |
| 418 | |
| 419 | `subject` |
| 420 | : first line of the change's most recent patch set's commit message. |
| 421 | |
Eugene Baranov | d15ede2 | 2014-10-29 13:25:56 +0200 | [diff] [blame] | 422 | `commit-message` |
| 423 | : full commit message of the most recent patch set |
| 424 | |
Christian Aistleitner | 1179f72 | 2014-09-11 09:25:54 +0200 | [diff] [blame] | 425 | `status` |
| 426 | : status of the change (`null`, `NEW`, `SUBMITTED`, `DRAFT`, `MERGED`, |
| 427 | or `ABANDONED` ) |
| 428 | |
| 429 | `topic` |
| 430 | : name of the topic the change belongs to. |
| 431 | |
| 432 | [event-properties-patch-set]: #event-properties-patch-set |
| 433 | ### <a name="event-properties-patch-set">Common properties for events on a patch set</a> |
| 434 | |
| 435 | `author-email` |
| 436 | : email address of this patch set's author. |
| 437 | |
| 438 | `author-name` |
| 439 | : name of this patch set's author. |
| 440 | |
| 441 | `author-username` |
| 442 | : username of this patch set's author. |
| 443 | |
| 444 | `created-on` |
| 445 | : Timestamp of creation of the patch set (Seconds since 1st January 1970). |
| 446 | |
| 447 | `deletions` |
| 448 | : number of lines deleted by the patch set. |
| 449 | |
| 450 | `insertions` |
| 451 | : number of lines inserted by the patch set. |
| 452 | |
| 453 | `is-draft` |
| 454 | : 'true', if the patch set is a draft patch set, 'false' otherwise. |
| 455 | |
| 456 | `parents` |
| 457 | : A list of git commit hashes that are parents to the patch set. |
| 458 | |
| 459 | `patch-set-number` |
| 460 | : patch set's number within the change. |
| 461 | |
| 462 | `ref` |
| 463 | : git ref for the patch set (For the 5-th patch set of change 4711, this |
| 464 | will be `refs/changes/11/4711/5`). |
| 465 | |
| 466 | `revision` |
| 467 | : git commit hash of the patch set |
| 468 | |
| 469 | `uploader-email` |
| 470 | : email address of the user that uploaded this patch set. |
| 471 | |
| 472 | `uploader-name` |
| 473 | : name of the user that uploaded this patch set. |
| 474 | |
| 475 | `uploader-username` |
| 476 | : username of the user that uploaded this patch set. |
| 477 | |
| 478 | [actions]: #actions |
| 479 | <a name="actions">Actions</a> |
| 480 | ----------------------------- |
| 481 | |
| 482 | Lines of the form |
| 483 | |
| 484 | ``` |
| 485 | action = name param1 param2 ... paramN |
| 486 | ``` |
| 487 | |
| 488 | represent the action `name` being called with parameters `param1`, |
| 489 | `param2`, ... `paramN`. |
| 490 | |
| 491 | The following actions are available: |
| 492 | |
| 493 | [`add-comment`][action-add-comment] |
| 494 | : adds the parameters as issue comment |
| 495 | |
| 496 | [`add-standard-comment`][action-add-standard-comment] |
| 497 | : adds a predefined standard comment for certain events |
| 498 | |
| 499 | [`add-velocity-comment`][action-add-velocity-comment] |
| 500 | : adds a rendered Velocity template as issue comment |
| 501 | |
| 502 | [`log-event`][action-log-event] |
| 503 | : appends the event's properties to Gerrit's log |
| 504 | |
| 505 | [Further actions][further-actions] may be provided by @PLUGIN@. |
| 506 | |
| 507 | [further-actions]: config-rulebase-plugin-actions.md |
| 508 | |
| 509 | [action-add-comment]: #action-add-comment |
| 510 | ### <a name="action-add-comment">Action: add-comment</a> |
| 511 | |
| 512 | The `add-comment` action adds the given parameters as comment to any |
| 513 | associated rule. |
| 514 | |
| 515 | So for example |
| 516 | |
| 517 | ``` |
| 518 | action = add-comment This is a sample command |
| 519 | ``` |
| 520 | |
| 521 | would add a comment “This is a sample command” to associated issues. |
| 522 | |
| 523 | If no parameters are given, no comment gets added. |
| 524 | |
| 525 | [action-add-standard-comment]: #action-add-standard-comment |
| 526 | ### <a name="action-add-standard-comment">Action: add-standard-comment</a> |
| 527 | |
| 528 | The `add-standard-comment` action adds predefined comments to |
| 529 | associated issues for change abandoned, merged, restored, and patch |
| 530 | set created events. For other events, no comment is added to the |
| 531 | associated issues. |
| 532 | |
| 533 | The added comments contain the person responsible for the event |
| 534 | (abandoner, merger, ...), the change's subject, a reason (if one has |
| 535 | been given), and a link to the change. |
| 536 | |
| 537 | [action-add-comment]: #action-add-comment |
| 538 | ### <a name="action-add-comment">Action: add-comment</a> |
| 539 | |
| 540 | [action-add-velocity-comment]: #action-add-velocity-comment |
| 541 | ### <a name="action-add-velocity-comment">Action: add-velocity-comment</a> |
| 542 | |
| 543 | The `add-velocity-comment` action renders a Velocity template for the |
| 544 | event and adds the output as comment to any associated issue. |
| 545 | |
| 546 | So for example |
| 547 | |
| 548 | ``` |
| 549 | action = add-velocity-comment TemplateName |
| 550 | ``` |
| 551 | |
| 552 | would render the template `etc/its/templates/TemplateName.vm` add the |
| 553 | output as comment to associated issues. |
| 554 | |
| 555 | If 'TemplateName' is `inline`, the Velocity template to render is not |
| 556 | loaded from a file, but the template is built by joining the remaining |
| 557 | parameters. So for example |
| 558 | |
| 559 | ``` |
| 560 | action = add-velocity-comment inline Sample template using $subject property. |
| 561 | ``` |
| 562 | |
| 563 | would render “Sample template using $subject property.” as Velocity |
| 564 | template. |
| 565 | |
| 566 | If 'TemplateName' is not `inline`, further parameters get ignored. |
| 567 | |
| 568 | Any [property][event-properties] of the event may be used from |
| 569 | templates. So for example `$subject` in the above example refers to |
| 570 | the event's subject property, and `$change-number` would refer to the |
| 571 | change's number. |
| 572 | |
| 573 | Additionally, the context's `its` property provides an object that |
| 574 | allows to format links using the its' syntax: |
| 575 | |
| 576 | `formatLink( url )` |
| 577 | : Formats a link to a url. |
| 578 | |
| 579 | So for example upon adding a comment to a change, the |
| 580 | following rule formats a link to the change: |
| 581 | |
| 582 | ``` |
| 583 | [rule "formatLinkSampleRule"] |
| 584 | event-type = comment-added |
| 585 | action = add-velocity-comment inline Comment for change $change-number added. See ${its.formatLink($change-url)} |
| 586 | ``` |
| 587 | |
| 588 | `formatLink( url, caption )` |
| 589 | : Formats a link to a url using 'caption' to represent the url. |
| 590 | |
| 591 | So for example upon adding a comment to a change, the following rule |
| 592 | formats a link to the change using the change number as link |
| 593 | capition: |
| 594 | |
| 595 | ``` |
| 596 | [rule "formatLinkSampleRule"] |
| 597 | event-type = comment-added |
| 598 | action = add-velocity-comment inline Comment for change ${its.formatLink($change-url, $change-number)} added. |
| 599 | ``` |
| 600 | |
| 601 | [action-log-event]: #action-log-event |
| 602 | ### <a name="action-log-event">Action: log-event</a> |
| 603 | |
| 604 | The `log-event` action appends the event's properties to Gerrit's log. |
| 605 | |
| 606 | Logging happens at the info level per default, but can be overriden by |
| 607 | adding the desired log level as parameter. Supported values are |
| 608 | `error`, `warn`, `info`, and `debug`). So for example |
| 609 | |
| 610 | ``` |
| 611 | action = log-event error |
| 612 | ``` |
| 613 | |
| 614 | appends the event's properties to Gerrit's log at error level. All |
| 615 | other parameters are ignored. |
| 616 | |
| 617 | This action is useful, when testing rules or trying to refine |
| 618 | conditions on rules, as it make the available properties visible. |
| 619 | |
| 620 | [Back to @PLUGIN@ documentation index][index] |
| 621 | |
Khai Do | 7a29a3a | 2014-12-18 13:20:35 -0800 | [diff] [blame] | 622 | [index]: index.html |