Post messages about code owner approved files asynchronously by default

When a code owner approves a change the code-owners plugin extends the
change message that Gerrit core posts for the approval to include the
paths that have been code-owner approved by the approval.

Computing the owned path is expensive, so this extension of the change
can be slow which goes at the expense of the post review latency.

To improve the post review latency we add a new configuration option to
post the approved path asynchronously in a separate change message and
turn this configuration on by default.

The new code-owner.enableAsyncMessageOnCodeOwnerApproval configuration
option follows the example of the existing
code-owners.enableAsyncMessageOnAddReviewer configuration which controls
whether the change message with paths owned by a newly added reviewer
should be posted asynchronously.

If asynchronous posting is enabled, 2 changes messages are posted when a
code owner applies an approval:

1. "Patch Set X: Code-Owner+1" posted by Gerrit core
2. "Patch Set X: By voting Code-Review+1 the following files are now
   code-owner approved by YYY: ..." posted by the code-owners plugin

If asynchronous posting is disabled, there is only a single change
message:

1. "Patch Set X: Code-Owner+1\n\nBy voting Code-Review+1 the following
   files are now code-owner approved by YYY: ..." posted by Gerrit core
   and extended by the code-owners plugin

Posting the change message asynchronously in OnCodeOwnerApproval follows
the example of how asynchronous posting is done in
CodeOwnersOnAddReviewer.

For running tests asynchronous message posting is disabled by default.
This is important to avoid LOCK_FAILUREs (see comment in
AbstractCodeOwnersTest.defaultConfig). So far disabling asynchronous
message posting for CodeOwnersOnAddReviewer was only relevant for
integration tests but the OnCodeOwnerApproval logic is also executed by
unit tests, hence we have to pull up this configuration from
AbstractCodeOwnersIT to AbstractCodeOwnersTest and add it to custom
default configs.

The asynchronous message posting is tested by a new test in
OnCodeOwnerApprovalIT which follows the example of the async test in
CodeOwnersOnAddReviewerIT.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I129e611afbb6384f10bd5a42dea43458273ed95d
Bug: Google b/273710181
14 files changed
tree: 3c3a3976d49b214cd134b01dd249e13ae8efbdd1
  1. java/
  2. javatests/
  3. proto/
  4. resources/
  5. web/
  6. .gitignore
  7. .gitreview
  8. BUILD
  9. LICENSE
  10. README.md
README.md

Gerrit Code Review code-owners plugin

This plugin provides support for defining code owners for files in a repository.

If the code-owners plugin is enabled, changes can only be submitted if all touched files are covered by approvals from code owners.

For a detailed description of the plugin functionality please refer to the plugin documentation.

IMPORTANT: Before installing/enabling the plugin follow the instructions from the setup guide.

NOTE: The plugin documentation only renders correctly when the plugin is installed in Gerrit and the documentation is accessed via https:///plugins/code-owners/Documentation/index.html. If you want to read the documentation before installing the plugin, you can find it properly rendered here.

JavaScript Plugin

From the root of the gerrit repository.

bazel test //plugins/code-owners/web:karma_test

For testing the plugin with the Gerrit FE Dev Helper the command below builds

    bazel build //plugins/code-owners/web:code-owners
    ln -s bazel-bin/plugins/code-owners/web/code-owners.js polygerrit-ui/app/plugins/

and let the Dev Helper redirect from .+/plugins/code-owners/static/code-owners.js to http://localhost:8081/plugins/code-owners.js.