David Pursehouse | 1bf7156 | 2014-12-19 13:59:40 +0900 | [diff] [blame] | 1 | = Gerrit Code Review - Plugin-based Validation |
David Pursehouse | ec31ddf | 2013-02-22 15:49:03 +0900 | [diff] [blame] | 2 | |
David Pursehouse | 1bf7156 | 2014-12-19 13:59:40 +0900 | [diff] [blame] | 3 | Gerrit provides interfaces to allow link:dev-plugins.html[plugins] to |
| 4 | perform validation on certain operations. |
David Pursehouse | ec31ddf | 2013-02-22 15:49:03 +0900 | [diff] [blame] | 5 | |
David Pursehouse | 8f9e9f5 | 2013-05-30 10:35:24 +0900 | [diff] [blame] | 6 | [[new-commit-validation]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 7 | == New commit validation |
David Pursehouse | 8f9e9f5 | 2013-05-30 10:35:24 +0900 | [diff] [blame] | 8 | |
| 9 | |
David Pursehouse | cde597d4 | 2013-05-30 10:16:17 +0900 | [diff] [blame] | 10 | Plugins implementing the `CommitValidationListener` interface can |
| 11 | perform additional validation checks against new commits. |
David Pursehouse | ec31ddf | 2013-02-22 15:49:03 +0900 | [diff] [blame] | 12 | |
David Pursehouse | cde597d4 | 2013-05-30 10:16:17 +0900 | [diff] [blame] | 13 | If the commit fails the validation, the plugin can either provide a |
| 14 | message that will be sent back to the git client, or throw an exception |
| 15 | which will cause the commit to be rejected. |
| 16 | |
| 17 | Validation applies to both commits uploaded via `git push`, and new |
| 18 | commits generated via Gerrit's Web UI features such as the rebase, revert |
| 19 | and cherry-pick buttons. |
David Pursehouse | ec31ddf | 2013-02-22 15:49:03 +0900 | [diff] [blame] | 20 | |
David Pursehouse | 9437b7b | 2012-11-05 23:48:58 +0900 | [diff] [blame] | 21 | Out of the box, Gerrit includes a plugin that checks the length of the |
| 22 | subject and body lines of commit messages on uploaded commits. |
| 23 | |
Edwin Kempin | 0b400596c | 2021-03-12 14:37:01 +0100 | [diff] [blame] | 24 | [plugin-push-options]] |
| 25 | === Plugin push options |
| 26 | |
| 27 | Plugins can register push options by implementing the `PluginPushOption` |
| 28 | interface. If a plugin push option was specified it is available from |
| 29 | the `CommitReceivedEvent` that is passed into `CommitValidationListener`. |
| 30 | This way the plugin commit validation can be controlled by push options. |
| 31 | |
Jacek Centkowski | 0b94246 | 2014-09-10 07:53:51 -0400 | [diff] [blame] | 32 | [[user-ref-operations-validation]] |
| 33 | == User ref operations validation |
Jacek Centkowski | 6fd218d | 2014-09-10 07:42:46 -0400 | [diff] [blame] | 34 | |
| 35 | |
| 36 | Plugins implementing the `RefOperationValidationListener` interface can |
Jacek Centkowski | 0b94246 | 2014-09-10 07:53:51 -0400 | [diff] [blame] | 37 | perform additional validation checks against user ref operations (resulting |
| 38 | from either push or corresponding Gerrit REST/SSH endpoints call e.g. |
| 39 | create branch etc.). Namely including ref creation, deletion and update |
| 40 | (also non-fast-forward) before they are applied to the git repository. |
Jacek Centkowski | 6fd218d | 2014-09-10 07:42:46 -0400 | [diff] [blame] | 41 | |
Jacek Centkowski | 0b94246 | 2014-09-10 07:53:51 -0400 | [diff] [blame] | 42 | The plugin can throw an exception which will cause the operation to fail, |
| 43 | and prevent the ref update from being applied. |
Jacek Centkowski | 6fd218d | 2014-09-10 07:42:46 -0400 | [diff] [blame] | 44 | |
David Pursehouse | 8f9e9f5 | 2013-05-30 10:35:24 +0900 | [diff] [blame] | 45 | [[pre-merge-validation]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 46 | == Pre-merge validation |
David Pursehouse | 8f9e9f5 | 2013-05-30 10:35:24 +0900 | [diff] [blame] | 47 | |
| 48 | |
| 49 | Plugins implementing the `MergeValidationListener` interface can |
| 50 | perform additional validation checks against commits before they |
| 51 | are merged to the git repository. |
| 52 | |
| 53 | If the commit fails the validation, the plugin can throw an exception |
| 54 | which will cause the merge to fail. |
| 55 | |
Andrii Shyshkalov | da2034f | 2017-01-19 13:44:16 -0800 | [diff] [blame] | 56 | [[on-submit-validation]] |
| 57 | == On submit validation |
| 58 | |
| 59 | |
| 60 | Plugins implementing the `OnSubmitValidationListener` interface can |
David Pursehouse | 4b06775 | 2017-03-03 15:54:53 +0900 | [diff] [blame] | 61 | perform additional validation checks against ref operations resulting |
Andrii Shyshkalov | da2034f | 2017-01-19 13:44:16 -0800 | [diff] [blame] | 62 | from execution of submit operation before they are applied to any git |
| 63 | repositories (there could be more than one in case of topic submits). |
| 64 | |
| 65 | Plugin can throw an exception which will cause submit operation to be |
| 66 | aborted. |
| 67 | |
Hugo Arès | 0c14990 | 2014-04-17 08:35:16 -0400 | [diff] [blame] | 68 | [[pre-upload-validation]] |
| 69 | == Pre-upload validation |
| 70 | |
| 71 | |
| 72 | Plugins implementing the `UploadValidationListener` interface can |
| 73 | perform additional validation checks before any upload operations |
| 74 | (clone, fetch, pull). The validation is executed right before Gerrit |
| 75 | begins to send a pack back to the git client. |
| 76 | |
| 77 | If upload fails the validation, the plugin can throw an exception |
| 78 | which will cause the upload to fail and the exception's message text |
| 79 | will be reported to the git client. |
| 80 | |
Edwin Kempin | de3bfb2 | 2014-01-22 16:13:03 +0100 | [diff] [blame] | 81 | [[new-project-validation]] |
| 82 | == New project validation |
| 83 | |
| 84 | |
| 85 | Plugins implementing the `ProjectCreationValidationListener` interface |
| 86 | can perform additional validation on project creation based on the |
| 87 | input arguments. |
| 88 | |
| 89 | E.g. a plugin could use this to enforce a certain name scheme for |
| 90 | project names. |
| 91 | |
Edwin Kempin | 42b7b4e | 2014-01-22 20:16:20 +0100 | [diff] [blame] | 92 | [[new-group-validation]] |
| 93 | == New group validation |
| 94 | |
| 95 | |
| 96 | Plugins implementing the `GroupCreationValidationListener` interface |
| 97 | can perform additional validation on group creation based on the |
| 98 | input arguments. |
| 99 | |
| 100 | E.g. a plugin could use this to enforce a certain name scheme for |
| 101 | group names. |
| 102 | |
Gustaf Lundh | 53c26a3 | 2016-09-20 22:06:47 +0200 | [diff] [blame] | 103 | [[assignee-validation]] |
| 104 | == Assignee validation |
| 105 | |
| 106 | |
| 107 | Plugins implementing the `AssigneeValidationListener` interface can perform |
| 108 | validation of assignees before they are assigned to a change. |
| 109 | |
David Pursehouse | 1fe4ed6 | 2014-09-13 00:30:37 +0200 | [diff] [blame] | 110 | [[hashtag-validation]] |
| 111 | == Hashtag validation |
| 112 | |
| 113 | |
| 114 | Plugins implementing the `HashtagValidationListener` interface can perform |
| 115 | validation of hashtags before they are added to or removed from changes. |
| 116 | |
Zalan Blenessy | 81671c9 | 2014-12-23 11:42:28 +0100 | [diff] [blame] | 117 | [[outgoing-email-validation]] |
| 118 | == Outgoing e-mail validation |
| 119 | |
| 120 | |
| 121 | This interface provides a low-level e-mail filtering API for plugins. |
| 122 | Plugins implementing the `OutgoingEmailValidationListener` interface can perform |
| 123 | filtering of outgoing e-mails just before they are sent. |
| 124 | |
Edwin Kempin | f0d71a8 | 2018-04-20 13:03:34 +0200 | [diff] [blame] | 125 | [[account-activation-validation]] |
| 126 | == Account activation validation |
| 127 | |
| 128 | |
| 129 | Plugins implementing the `AccountActivationValidationListener` interface can |
| 130 | perform validation when an account is activated or deactivated via the Gerrit |
| 131 | REST API or the Java extension API. |
| 132 | |
Joerg Zieren | 81c899f | 2019-07-24 17:39:26 +0200 | [diff] [blame] | 133 | [[review-comment-validation]] |
| 134 | == Review comment validation |
| 135 | |
| 136 | |
| 137 | The `CommentValidator` interface allows plugins to validate all review comments, |
| 138 | i.e. inline comments, file comments and the review message. This works for the |
| 139 | REST API, for `git push` when `--publish-comments` is used and for comments sent |
| 140 | via email. |
| 141 | |
David Pursehouse | ec31ddf | 2013-02-22 15:49:03 +0900 | [diff] [blame] | 142 | |
| 143 | GERRIT |
| 144 | ------ |
| 145 | Part of link:index.html[Gerrit Code Review] |
| 146 | |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 147 | |
| 148 | SEARCHBOX |
| 149 | --------- |