Fix transitive import of global owners via per-file rule that ignores global owners

Example:

OWNERS:
per-file *.md=set noparent
per-file *.md=file:/foo/OWNERS

/foo/OWNERS:
file:/bar/OWNERS

/bar/OWNERS:
code-owner@example.com

For a file that matches the per-file rule in 'OWNERS' we would expect
that 'code-owner@example.com' is a code owner. 'code-owner@example.com'
is a global code owner in '/bar/OWNERS' but since it's imported for a
per-file rule it becomes a per-file code owner. However what happens is
that we wrongly treat 'code-owner@example.com' as a global code owner
and then it gets ignored due to the "set noparent" on the matching
per-file rule.

In PathCodeOwners.resolveImports we already had logic to treat global
code owners that are imported via a per-file rule as per-file code
owners, however this worked only for global code owners that were
directly imported by a per-file rule, but not for global code owners
that were transitively imported by a per-file rule.

This got broken by the refactoring that was done in change I6f7723c0a,
but we didn't notice the breakage because we only tested this case
without transitive imports (see
PathCodeOwnersTest.perFileRuleThatIgnoresGlobalCodeOwnersCanImportGlobalCodeOwnersFromOtherFile).

To fix this we need to know for an import if any previous import in the
import chain was a per-file import. If yes, we should treat the imported
global code owners as per-file code owners.

The check whether an import imports code owners as global code owners or
as per-file code owners is done by
PathCodeOwners.CodeOwnerImport#isGlobal. So far it was only looking at
the current import but not at the previous imports. By passing in the
previous import (if there is one) we can fix this.

Bug: Google b/363000012
Change-Id: I7c872175fb198603f24a95819877ee1ff98651ec
Signed-off-by: Edwin Kempin <ekempin@google.com>
2 files changed
tree: 6a8d544798040b619d074d68d009d47541073908
  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.