Edwin Kempin | f79cd7c | 2019-03-26 11:10:50 +0100 | [diff] [blame] | 1 | # @PLUGIN@ - /plugins/@PLUGIN@/checkers/ REST API |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 2 | |
| 3 | This page describes the checker-related REST endpoints that are added by the |
| 4 | @PLUGIN@ plugin. |
| 5 | |
| 6 | Please also take note of the general information on the |
| 7 | [REST API](../../../Documentation/rest-api.html). |
| 8 | |
| 9 | ## <a id="checker-endpoints"> Checker Endpoints |
| 10 | |
| 11 | ### <a id="get-checker"> Get Checker |
Edwin Kempin | f79cd7c | 2019-03-26 11:10:50 +0100 | [diff] [blame] | 12 | _'GET /plugins/@PLUGIN@/checkers/[\{checker-id\}](#checker-id)'_ |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 13 | |
| 14 | Retrieves a checker. |
| 15 | |
| 16 | Note that only users with the [Administrate |
| 17 | Checkers](access-control.md#capability_administrateCheckers) global capability |
| 18 | are permitted to retrieve checkers. |
| 19 | |
| 20 | #### Request |
| 21 | |
| 22 | ``` |
Edwin Kempin | 9ae9e16 | 2019-03-26 11:19:08 +0100 | [diff] [blame] | 23 | GET /plugins/@PLUGIN@/checkers/test%3Amy-checker HTTP/1.0 |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 24 | ``` |
| 25 | |
| 26 | As response a [CheckerInfo](#checker-info) entity is returned that describes the |
| 27 | checker. |
| 28 | |
| 29 | #### Response |
| 30 | |
| 31 | ``` |
| 32 | HTTP/1.1 200 OK |
| 33 | Content-Disposition: attachment |
| 34 | Content-Type: application/json; charset=UTF-8 |
| 35 | )]}' |
| 36 | { |
Dave Borowitz | 3c43c32 | 2019-02-28 15:27:14 -0800 | [diff] [blame] | 37 | "uuid": "test:my-checker", |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 38 | "name": "MyChecker", |
| 39 | "repository": "examples/Foo", |
Dave Borowitz | b8a3e7a | 2019-02-14 14:02:22 -0800 | [diff] [blame] | 40 | "blocking": [], |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 41 | "description": "A simple checker.", |
| 42 | "created_on": "2019-01-31 09:59:32.126000000" |
| 43 | } |
| 44 | ``` |
| 45 | |
| 46 | ### <a id="create-checker"> Create Checker |
Edwin Kempin | f79cd7c | 2019-03-26 11:10:50 +0100 | [diff] [blame] | 47 | _'POST /plugins/@PLUGIN@/checkers/'_ |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 48 | |
| 49 | Creates a new checker. |
| 50 | |
| 51 | In the request body the data for the checker must be provided as a |
| 52 | [CheckerInput](#checker-input) entity. |
| 53 | |
| 54 | Note that only users with the [Administrate |
| 55 | Checkers](access-control.md#capability_administrateCheckers) global capability |
| 56 | are permitted to create checkers. |
| 57 | |
| 58 | #### Request |
| 59 | |
| 60 | ``` |
Edwin Kempin | f79cd7c | 2019-03-26 11:10:50 +0100 | [diff] [blame] | 61 | POST /plugins/@PLUGIN@/checkers/ HTTP/1.0 |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 62 | Content-Type: application/json; charset=UTF-8 |
| 63 | { |
Dave Borowitz | 3c43c32 | 2019-02-28 15:27:14 -0800 | [diff] [blame] | 64 | "uuid": "test:my-checker", |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 65 | "name": "MyChecker", |
| 66 | "description": "A simple checker.", |
| 67 | "repository": "examples/Foo", |
| 68 | } |
| 69 | ``` |
| 70 | |
| 71 | As response the [CheckerInfo](#checker-info) entity is returned that describes |
| 72 | the created checker. |
| 73 | |
| 74 | #### Response |
| 75 | |
| 76 | ``` |
| 77 | HTTP/1.1 201 Created |
| 78 | Content-Disposition: attachment |
| 79 | Content-Type: application/json; charset=UTF-8 |
| 80 | )]}' |
| 81 | { |
Dave Borowitz | 3c43c32 | 2019-02-28 15:27:14 -0800 | [diff] [blame] | 82 | "uuid": "test:my-checker", |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 83 | "name": "MyChecker", |
| 84 | "description": "A simple checker.", |
| 85 | "repository": "examples/Foo", |
| 86 | "created_on": "2019-01-31 09:59:32.126000000", |
| 87 | "updated_on": "2019-01-31 09:59:32.126000000" |
| 88 | } |
| 89 | ``` |
| 90 | |
| 91 | ### <a id="update-checker"> Update Checker |
Edwin Kempin | f79cd7c | 2019-03-26 11:10:50 +0100 | [diff] [blame] | 92 | _'POST /plugins/@PLUGIN@/checkers/[\{checker-id\}](#checker-id)'_ |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 93 | |
| 94 | Updates a checker. |
| 95 | |
| 96 | The new property values must be set in the request body in a |
| 97 | [CheckerInput](#checker-input) entity. |
| 98 | |
| 99 | This REST endpoint supports partial updates of the checker property set. Only |
| 100 | properties that are set in the [CheckerInput](#checker-input) entity are |
| 101 | updated. Properties that are not set in the input (or that have `null` as value) |
| 102 | are not touched. |
| 103 | |
| 104 | Unsetting properties: |
| 105 | |
Dave Borowitz | 3c43c32 | 2019-02-28 15:27:14 -0800 | [diff] [blame] | 106 | * `uuid`: Cannot be unset or otherwise modified. |
| 107 | * `name`: Can be unset by setting an empty string ("") for it. |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 108 | * `description`: Can be unset by setting an empty string ("") for it. |
| 109 | * `url`: Can be unset by setting an empty string ("") for it. |
| 110 | * '`repository`: Cannot be unset. Attempting to set it to an empty string ("") |
| 111 | or a string that is empty after trim is rejected as `400 Bad Request`. |
| 112 | * `status`: Cannot be unset. |
Dave Borowitz | b8a3e7a | 2019-02-14 14:02:22 -0800 | [diff] [blame] | 113 | * `blocking`: Can be unset by setting an empty list (\[\]) for it. |
Dave Borowitz | 67629ae | 2019-02-21 16:55:53 -0800 | [diff] [blame] | 114 | * `query`: Can be unset by setting an empty string ("") for it. Note that the |
| 115 | default for newly-created checkers is not empty; see [below](#query). |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 116 | |
| 117 | Note that only users with the [Administrate |
| 118 | Checkers](access-control.md#capability_administrateCheckers) global capability |
| 119 | are permitted to update checkers. |
| 120 | |
| 121 | #### Request |
| 122 | |
| 123 | ``` |
Edwin Kempin | 9ae9e16 | 2019-03-26 11:19:08 +0100 | [diff] [blame] | 124 | POST /plugins/@PLUGIN@/checkers/test%3Amy-checker HTTP/1.0 |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 125 | Content-Type: application/json; charset=UTF-8 |
| 126 | { |
| 127 | "description": "A simple checker." |
| 128 | } |
| 129 | ``` |
| 130 | |
| 131 | As response the [CheckerInfo](#checker-info) entity is returned that describes |
| 132 | the updated checker. |
| 133 | |
| 134 | #### Response |
| 135 | |
| 136 | ``` |
| 137 | HTTP/1.1 200 OK |
| 138 | Content-Disposition: attachment |
| 139 | Content-Type: application/json; charset=UTF-8 |
| 140 | )]}' |
| 141 | { |
Dave Borowitz | 3c43c32 | 2019-02-28 15:27:14 -0800 | [diff] [blame] | 142 | "uuid": "test:my-checker", |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 143 | "name": "MyChecker", |
| 144 | "description": "A simple checker.", |
| 145 | "repository": "examples/Foo", |
| 146 | "status": "ENABLED", |
| 147 | "created_on": "2019-01-31 09:59:32.126000000", |
| 148 | "updated_on": "2019-02-01 07:23:44.158000000" |
| 149 | } |
| 150 | ``` |
| 151 | |
| 152 | ## <a id="ids"> IDs |
| 153 | |
| 154 | ### <a id="checker-id"> \{checker-id\} |
| 155 | |
| 156 | The UUID of a checker. |
| 157 | |
Dave Borowitz | 3c43c32 | 2019-02-28 15:27:14 -0800 | [diff] [blame] | 158 | UUIDs are of the form `SCHEME ':' ID`. The scheme and ID portions may only |
| 159 | contain alphanumeric characters (`a-z`, `A-Z`, `0-9`) plus the punctuation |
| 160 | characters `.`, `_`, and `-`. Thus UUIDs are URL-safe without escaping. |
| 161 | |
Dave Borowitz | c7e597c | 2019-03-07 11:04:45 -0800 | [diff] [blame] | 162 | The scheme is by convention a short string (max 100 chars) associated with the |
| 163 | external system that created the checker, for example `jenkins`. The scheme must |
| 164 | also be a valid ref name component according to |
| 165 | [`git-check-ref-format`](https://git-scm.com/docs/git-check-ref-format), for |
| 166 | example it may not start or end with a period. |
| 167 | |
| 168 | The ID is an arbitrary identifier that may have meaning to the external system. |
Dave Borowitz | 3c43c32 | 2019-02-28 15:27:14 -0800 | [diff] [blame] | 169 | |
| 170 | UUIDs must be unique and are immutable after creation. |
| 171 | |
| 172 | Checker names cannot be used as identifiers in the REST API since checker names |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 173 | may be ambiguous. |
| 174 | |
Edwin Kempin | 52b8418 | 2019-03-13 09:40:59 +0100 | [diff] [blame] | 175 | ## <a id="json-entities"> JSON Entities |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 176 | |
| 177 | ### <a id="checker-info"> CheckerInfo |
| 178 | The `CheckerInfo` entity describes a checker. |
| 179 | |
| 180 | | Field Name | | Description | |
| 181 | | --------------- | -------- | ----------- | |
Dave Borowitz | 3c43c32 | 2019-02-28 15:27:14 -0800 | [diff] [blame] | 182 | | `uuid` | | The [UUID](#checker-id) of the checker. |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 183 | | `name` | | The name of the checker, may not be unique. |
| 184 | | `description` | optional | The description of the checker. |
| 185 | | `url` | optional | The URL of the checker. |
| 186 | | `repository` | | The (exact) name of the repository for which the checker applies. |
| 187 | | `status` | | The status of the checker; one of `ENABLED` or `DISABLED`. |
Dave Borowitz | b8a3e7a | 2019-02-14 14:02:22 -0800 | [diff] [blame] | 188 | | `blocking` | | A list of [conditions](#blocking-conditions) that describe when the checker should block change submission. |
Dave Borowitz | 67629ae | 2019-02-21 16:55:53 -0800 | [diff] [blame] | 189 | | `query` | optional | A [query](#query) that limits changes for which the checker is relevant. |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 190 | | `created_on` | | The [timestamp](../../../Documentation/rest-api.html#timestamp) of when the checker was created. |
| 191 | | `updated_on` | | The [timestamp](../../../Documentation/rest-api.html#timestamp) of when the checker was last updated. |
| 192 | |
| 193 | ### <a id="checker-input"> CheckerInput |
| 194 | The `CheckerInput` entity contains information for creating a checker. |
| 195 | |
| 196 | | Field Name | | Description | |
| 197 | | --------------- | -------- | ----------- | |
| 198 | | `name` | optional | The name of the checker. Must be specified for checker creation. |
| 199 | | `description` | optional | The description of the checker. |
| 200 | | `url` | optional | The URL of the checker. |
| 201 | | `repository` | optional | The (exact) name of the repository for which the checker applies. |
| 202 | | `status` | optional | The status of the checker; one of `ENABLED` or `DISABLED`. |
Dave Borowitz | b8a3e7a | 2019-02-14 14:02:22 -0800 | [diff] [blame] | 203 | | `blocking` | optional | A list of [conditions](#blocking-conditions) that describe when the checker should block change submission. |
Dave Borowitz | 67629ae | 2019-02-21 16:55:53 -0800 | [diff] [blame] | 204 | | `query` | optional | A [query](#query) that limits changes for which the checker is relevant. |
Dave Borowitz | b8a3e7a | 2019-02-14 14:02:22 -0800 | [diff] [blame] | 205 | |
| 206 | ## <a id="blocking-conditions"> Blocking Conditions |
| 207 | |
| 208 | Blocking conditions allow checkers to specify the conditions under which checks |
| 209 | will block change submission. The conditions configured for a checker are |
| 210 | represented as a list of enum values. When there are multiple blocking |
| 211 | conditions, any one of them is sufficient to block submission; in other words, |
| 212 | conditions are ORed together. |
| 213 | |
| 214 | There is currently only a single type of blocking condition: |
| 215 | `STATE_NOT_PASSING`. Intuitively, if a checker sets this blocking condition, |
| 216 | that means that users need to wait for all checks, for example build and test, |
| 217 | to pass before submitting the change. In other words, we might say the checker |
| 218 | is _required_. |
| 219 | |
| 220 | Technically, `STATE_NOT_PASSING` requires the combined check state on the change |
Dave Borowitz | 8022003 | 2019-03-18 12:44:13 -0700 | [diff] [blame] | 221 | to be either `SUCCESSFUL`, `WARNING`, or `NOT_RELEVANT`. |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 222 | |
Dave Borowitz | 67629ae | 2019-02-21 16:55:53 -0800 | [diff] [blame] | 223 | ## <a id="query"> Query |
| 224 | |
| 225 | If the `query` field is specified in the checker config, then the checker is |
| 226 | only considered relevant for changes matching that query. The query field is |
| 227 | interpreted as a [change query](../../../Documentation/user-search.html), with a |
| 228 | limited subset of supported operators. By default, the query for newly-created |
| 229 | checkers is `status:open`. An empty query matches all changes. |
| 230 | |
| 231 | In order to determine the relevant checkers for a given change, Gerrit first |
| 232 | looks up all enabled checkers matching that change's repository, then executes |
| 233 | the query for each checker in sequence. Because of this algorithm, there are |
| 234 | restrictions on which operators can be supported in checker queries: |
| 235 | |
| 236 | * Operators related to projects are not supported, since the algorithm already |
| 237 | only considers checkers with a matching repository. |
| 238 | * Full-text operators (e.g. `message`) are not supported, since these cannot be |
| 239 | efficiently evaluated sequentially. |
| 240 | * Operators with an explicit or implied `self` user are not supported, since the |
| 241 | algorithm must return the same set of relevant checkers regardless of the end |
| 242 | user looking at the change. |
| 243 | |
| 244 | Currently, the set of allowed query operators is: |
| 245 | |
| 246 | `added, after, age, assignee, author, before, branch, committer, deleted, delta, |
| 247 | destination, dir, directory, ext, extension, f, file, footer, hashtag, intopic, |
| 248 | label, onlyextensions, onlyexts, ownerin, path, r, ref, reviewer, reviewerin, |
| 249 | size, status, submittable, topic, unresolved, wip` |
| 250 | |
Dave Borowitz | 540ee6d | 2019-02-21 16:03:17 -0800 | [diff] [blame] | 251 | --- |
| 252 | |
| 253 | Part of [Gerrit Code Review](../../../Documentation/index.html) |