Fix transitive imports of code owner configs

If an OWNERS file imports another OWNERS file without specifying a
project for the imported OWNERS file, the imported OWNERS file should
be loaded from the same project that contains the importing OWNERS file.
E.g. if

  foo-project:/OWNERS imports /sub/OWNERS

then

  /sub/OWNERS should be loaded from the foo-project project.

The same is true when imports are done transitively. E.g. if

  foo-project:/OWNERS imports bar-project:/OWNERS which imports
  /sub/OWNERS

then

  /sub/OWNERS should be loaded from the bar-project project (because
  bar-project is the project that contains the OWNERS file that imports
  /sub/OWNERS).

Now the resolution of the project for transitive imports was always
wrongly using the project of the first OWNERS file in the import chain,
so that in the example above it wrongly tried to load /sub/OWNERS from
foo-project:/sub/OWNERS.

Similarly when an OWNERS file imports another OWNERS file with a
relative path, the path should be resolved relative to the path that
contains the importing OWNERS file. E.g. if

  /foo/OWNERS imports sub/OWNERS

then

  sub/OWNERS should be loaded from /foo/sub/OWNERS.

The same is true when imports are done transitively. E.g. if

  /foo/OWNERS imports /bar/OWNERS which imports sub/OWNERS

then

  sub/OWNERS should be loaded from /bar/sub/OWNERS (because /bar is the
  folder that contains the OWNERS file that imports sub/OWNERS).

Also here the resolution of the relative path always wrongly used the
path of the first OWNERS file in the import chain as a base so that in
the example above it wrongly tried to load sub/OWNERS from
/foo/sub/OWNERS.

Due to fixing the issue with the relative path resolution we need to
adapt a test in CheckCodeOwnerIT that expected the wrong path in the
debug logs (to make the assertion work we simply use an absolute path
for the test now).

Bug: Google b/193664436
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Idc04977f05ed907e73b8c54b89c12c8375691759
3 files changed
tree: 3f18de7ef69891c6bfaa19408b3842a7f6b52492
  1. java/
  2. javatests/
  3. proto/
  4. resources/
  5. test/
  6. ui/
  7. .eslintrc.json
  8. .gitignore
  9. .gitreview
  10. bower.json
  11. BUILD
  12. LICENSE
  13. package-lock.json
  14. package.json
  15. 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.

Also see resources/Documentation/about.md.

IMPORTANT: Before installing/enabling the plugin follow the instructions from the setup guide, see resources/Documentation/setup-guide.md.