| commit | 038bd71842b98fc46b11cc3e906f4db52256db6f | [log] [tgz] |
|---|---|---|
| author | Edwin Kempin <ekempin@google.com> | Mon Aug 12 09:08:58 2024 +0000 |
| committer | Edwin Kempin <ekempin@google.com> | Mon Aug 12 13:51:22 2024 +0000 |
| tree | f73e1eacf59afdf0b3336eb1b0b36236f46a8e28 | |
| parent | 7088891e07d8b4f7c1977ed9c9f5d00338ade31e [diff] |
Simplify path code owners computation Global code owners (aka folder code owners) should be ignored if there is any matching per-file code owner set (in the code owner config that is being resolved or in any imported code owner config) that ignores global and parent code owners (i.e. that has "set noparent" set). To achieve this we did 2 things: 1. For the code owner config that is being evaluated we skipped global imports that only import global code owners (importMode = GLOBAL_CODE_OWNER_SETS_ONLY) if the code owner config contained any matching per-file code owner set that ignores global and parent code owners (as those global code owners would be dropped by 2.). 2. We droped global code owners sets that we had already collected when we found any matching per-file code owner set that ignores global and parent code owners. Since we use a builder to collect the result it's not straight-forward to drop global code owner sets that have already been added. For this we need to build the PathCodeOwnerResult and then create a new builder that copies all the fields except global code owner sets. This adds quite some boilerplate code. While we have good test coverage for PathCodeOwners I cannot shake off the feeling that there is also some edge case where dropping global code owners is wrongly dropping too much, but I can’t pinpoint this. In any case the existing logic is confusing and hard to read, which is why we want to simplify this. With this change the logic is easier to grasp now: 1. Differentiate between global and per-file code owner sets in PathCodeOwnersResult. 2. Collect all relevant global code owner sets in PathCodeOwnersResult regardless of whether they are possibly ignored. 3. Have an ignoreGlobalCodeOwners flag in PathCodeOwnersResult that is set when there is any matching per-file code owner set that ignores global and parent code owners. 4. When looking at code owner sets in PathCodeOwnerResult we simply ignore global code owner set when ignoreGlobalCodeOwners has been set to true. This way we no longer need to recreate the PathCodeOwnersResult.Builder to drop already collected global code owner sets and the code gets easier to read. In addition, since the ignored global code owners are now present in PathCodeOwnerResult we may inform about them when code ownership is being checked via the CheckCodeOwner REST endpoint (possible follow-up change). Bug: Google b/345161989 Change-Id: I6f7723c0ad49a216c5118ffd047216a9648c438a Signed-off-by: Edwin Kempin <ekempin@google.com>
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.
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.