CodeOwnerApprovalCheck: Factor out computation of input data

The CodeOwnerApprovalCheck class is quite large which makes the class
difficult to read. To make it smaller we factor out the computation of
all input data that this required for checking the code owner approvals
of a change. The input data is now represented by the new
CodeOwnerApprovalCheckInput class which is an immutable AutoValue class.
The loading of the input is done by the
CodeOwnerApprovalCheckInput.Loader class (e.g. this class computes the
relevant reviewers and approvers, loads the global code owners and
fallback code owners from the config etc.). The Loader class needs to
get some classes injected which is why we have a Factory to create it.

Having a class that represents all inputs, make it easier for
CodeOwnerApprovalCheck to pass down the input through the methods that
do the computation (just pass 1 parameter instead of n parameters).

In addition to checking code owner approvals on a change
CodeOwnerApprovalCheck also computes owned paths for a set of users.
This is achieved by using the same algorithm, but with specially
constructed inputs. By having the CodeOwnerApprovalCheckInput class we
can make the creation of the input for this purpose more explicit.

In future we need additional inputs for the code owner approval check
(e.g. approvals on previous patch sets for making code owner approvals
sticky on file level). Adding these additional inputs is easier now that
we have CodeOwnerApprovalCheckInput, otherwise we would need to add even
more logic to the already large CodeOwnerApprovalCheck class.

This change is a pure refactoring. This means no behavior is changed.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I298f8e3b6acd7afdec900e1c1fde6d1f26ed1a06
5 files changed
tree: 4f572b61bba0e5c80adec531eef7a9bb4ebc2339
  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.