Ben Rohlfs | ab7fbbf | 2021-04-29 10:27:03 +0200 | [diff] [blame] | 1 | :linkattrs: |
| 2 | = Gerrit Code Review - JavaScript Plugin Checks API |
| 3 | |
| 4 | This API is provided by link:pg-plugin-dev.html#plugin-checks[plugin.checks()]. |
| 5 | It allows plugins to contribute to the "Checks" tab and summary: |
| 6 | |
| 7 | image::images/user-checks-overview.png[width=800] |
| 8 | |
| 9 | Each plugin can link:#register[register] a checks provider that will be called |
| 10 | when a change page is loaded. Such a call would return a list of `Runs` and each |
| 11 | run can contain a list of `Results`. |
| 12 | |
Frank Borden | 6545f3b | 2022-12-02 12:45:20 +0100 | [diff] [blame] | 13 | `Results` messages will render as markdown. It follows the |
| 14 | [CommonMark](https://commonmark.org/help/) spec except inline images and direct |
| 15 | HTML are not rendered and kept as plaintext. |
| 16 | |
Ben Rohlfs | ab7fbbf | 2021-04-29 10:27:03 +0200 | [diff] [blame] | 17 | The details of the ChecksApi are documented in the |
| 18 | link:https://gerrit.googlesource.com/gerrit/+/master/polygerrit-ui/app/api/checks.ts[source code]. |
| 19 | Note that this link points to the `master` branch and might thus reflect a |
| 20 | newer version of the API than your Gerrit installation. |
| 21 | |
| 22 | If no plugins are registered with the ChecksApi, then the Checks tab will be |
| 23 | hidden. |
| 24 | |
| 25 | You can read about the motivation, the use cases and the original plans in the |
| 26 | link:https://www.gerritcodereview.com/design-docs/ci-reboot.html[design doc]. |
| 27 | |
| 28 | Here are some examples of open source plugins that make use of the Checks API: |
| 29 | |
Orgad Shaneh | 18408fb | 2024-01-10 15:48:37 +0200 | [diff] [blame] | 30 | * link:https://gerrit.googlesource.com/plugins/checks/+/master/web/plugin.ts[Gerrit Checks Plugin] |
Josip Sokcevic | be8d63d | 2022-03-30 11:35:04 -0700 | [diff] [blame] | 31 | * link:https://chromium.googlesource.com/infra/gerrit-plugins/buildbucket/+/main/web/plugin.ts[Chromium Buildbucket Plugin] |
| 32 | * link:https://chromium.googlesource.com/infra/gerrit-plugins/code-coverage/+/main/web/plugin.ts[Chromium Coverage Plugin] |
Ben Rohlfs | ab7fbbf | 2021-04-29 10:27:03 +0200 | [diff] [blame] | 33 | |
| 34 | [[register]] |
| 35 | == register |
| 36 | `checksApi.register(provider, config?)` |
| 37 | |
| 38 | .Params |
| 39 | - *provider* Must implement a `fetch()` interface that returns a |
| 40 | `Promise<FetchResponse>` with runs and results. See also documentation in the |
| 41 | link:https://gerrit.googlesource.com/gerrit/+/master/polygerrit-ui/app/api/checks.ts[source code]. |
| 42 | - *config* Optional configuration values for the checks provider. |
| 43 | |
| 44 | [[announceUpdate]] |
| 45 | == announceUpdate |
| 46 | `checksApi.announceUpdate()` |
| 47 | |
| 48 | Tells Gerrit to call `provider.fetch()`. |
Ben Rohlfs | a1bcad7 | 2023-11-03 15:35:41 +0100 | [diff] [blame] | 49 | |
| 50 | [[updateResult]] |
| 51 | == updateResult |
| 52 | `checksApi.updateResult(run: CheckRun, result: CheckResult)` |
| 53 | |
| 54 | Updates an individual result. This can be used for lazy laoding detailled |
| 55 | information. For example, if you are using the |
| 56 | link:pg-plugin-endpoints.html#_check_result_expanded[`check-result-expanded` |
| 57 | endpoint], then you can load more result details when the user expands a result |
| 58 | row. |
| 59 | |
| 60 | The parameter `run` is only used to *find* the correct run for updating the |
| 61 | result. It will only be used for comparing `change`, `patchset`, `attempt` and |
| 62 | `checkName`. Its properties other than `results` will not be updated. |
| 63 | |
| 64 | For us being able to identify the result that you want to update you have to |
| 65 | set the `externalId` property. An undefined `externalId` will result in an |
| 66 | error. |
| 67 | |
| 68 | An example usage can be found in link:https://chromium.googlesource.com/infra/gerrit-plugins/buildbucket/+/main/web/checks-result.ts[Chromium Buildbucket Plugin]. |