Check Code Owner REST endpoint: Fix formatting of OWNERS file in debug log
There was a debug log that didn't format the OWNERS file correctly. The
debug log was:
"resolve code owners for /foo/bar/baz.md from code owner config
Key{branchNameKey=com.google.gerrit.plugins.codeowners.acceptance.api.CheckCodeOwnerIT_checkCodeOwner_byAdmindefault_project,refs/heads/master,
folderPath=/foo, fileName=Optional.empty}"
Now it is:
"resolve code owners for /foo/bar/baz.md from code owner config
com.google.gerrit.plugins.codeowners.acceptance.api.CheckCodeOwnerIT_checkCodeOwner_byAdmindefault_project:master:/foo/OWNERS"
Bug: Google b/345161989
Change-Id: I1180962ae50791d6f81ee996a892c42a18baf491
Signed-off-by: Edwin Kempin <ekempin@google.com>
Reviewed-on: https://gerrit-review.googlesource.com/c/plugins/code-owners/+/434357
Reviewed-by: Kamil Musin <kamilm@google.com>
Tested-by: Zuul <zuul-63@gerritcodereview-ci.iam.gserviceaccount.com>
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/PathCodeOwners.java b/java/com/google/gerrit/plugins/codeowners/backend/PathCodeOwners.java
index ac4f4eb..40eaa21 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/PathCodeOwners.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/PathCodeOwners.java
@@ -218,13 +218,22 @@
}
try (Timer0.Context ctx = codeOwnerMetrics.resolveCodeOwnerConfig.start()) {
+ Path codeOwnerConfigFilePath = codeOwners.getFilePath(codeOwnerConfig.key());
logger.atFine().log(
- "resolve code owners for %s from code owner config %s", path, codeOwnerConfig.key());
+ "resolve code owners for %s from code owner config %s:%s:%s",
+ path,
+ codeOwnerConfig.key().project(),
+ codeOwnerConfig.key().shortBranchName(),
+ codeOwnerConfigFilePath);
List<String> messages = new ArrayList<>();
messages.add(
String.format(
- "resolve code owners for %s from code owner config %s", path, codeOwnerConfig.key()));
+ "resolve code owners for %s from code owner config %s:%s:%s",
+ path,
+ codeOwnerConfig.key().project(),
+ codeOwnerConfig.key().shortBranchName(),
+ codeOwnerConfigFilePath));
// Create a code owner config builder to create the resolved code owner config (= code owner
// config that is scoped to the path and which has imports resolved)
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
index 2568906..708cb5d 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
@@ -59,6 +59,7 @@
import com.google.gerrit.plugins.codeowners.restapi.CheckCodeOwnerCapability;
import com.google.gerrit.plugins.codeowners.restapi.GetCodeOwnersForPathInBranch;
import com.google.inject.Inject;
+import java.nio.file.Paths;
import java.util.List;
import java.util.Random;
import org.junit.Before;
@@ -1704,7 +1705,12 @@
.inOrder();
assertThat(codeOwnersInfo)
.hasDebugLogsThatContainAllOf(
- String.format("resolve code owners for %s from code owner config %s", path, fooBarKey),
+ String.format(
+ "resolve code owners for %s from code owner config %s:%s:%s",
+ path,
+ fooBarKey.project(),
+ fooBarKey.shortBranchName(),
+ Paths.get(fooBarKey.folderPath().toString(), getCodeOwnerConfigFileName())),
"per-file code owner set with path expressions [*.md] matches",
String.format(
"The import of %s:master:/%s in %s:master:/foo/bar/%s cannot be resolved:"
@@ -1715,11 +1721,21 @@
getCodeOwnerConfigFileName(),
nonExistingProject.get()),
String.format("resolved email %s to account %d", user.email(), user.id().get()),
- String.format("resolve code owners for %s from code owner config %s", path, fooKey),
+ String.format(
+ "resolve code owners for %s from code owner config %s:%s:%s",
+ path,
+ fooKey.project(),
+ fooKey.shortBranchName(),
+ Paths.get(fooKey.folderPath().toString(), getCodeOwnerConfigFileName())),
String.format(
"cannot resolve code owner email %s: no account with this email exists",
nonExistingEmail),
- String.format("resolve code owners for %s from code owner config %s", path, rootKey),
+ String.format(
+ "resolve code owners for %s from code owner config %s:%s:%s",
+ path,
+ rootKey.project(),
+ rootKey.shortBranchName(),
+ Paths.get(rootKey.folderPath().toString(), getCodeOwnerConfigFileName())),
String.format("resolved email %s to account %d", admin.email(), admin.id().get()),
"resolve global code owners",
String.format("resolved email %s to account %d", admin.email(), admin.id().get()));
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerIT.java
index 8c5ce92..2166eb4 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerIT.java
@@ -174,6 +174,9 @@
assertThat(checkCodeOwnerInfo)
.hasDebugLogsThatContainAllOf(
String.format(
+ "resolve code owners for %s from code owner config %s:master:%s",
+ path, project, getCodeOwnerConfigFilePath("/foo/")),
+ String.format(
"found email %s as a code owner in %s",
codeOwner.email(), getCodeOwnerConfigFilePath("/foo/")),
String.format("resolved email %s to account %s", codeOwner.email(), codeOwner.id()));
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnersTest.java b/javatests/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnersTest.java
index 8c67161..064d8f6 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnersTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnersTest.java
@@ -44,6 +44,7 @@
import com.google.inject.Provider;
import com.google.inject.util.Providers;
import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Optional;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -2886,7 +2887,7 @@
@Override
public Path getFilePath(CodeOwnerConfig.Key codeOwnerConfigKey) {
- throw new UnsupportedOperationException("not implemented");
+ return Paths.get(codeOwnerConfigKey.folderPath().toString(), "OWNERS");
}
}
}