CodeOwnerResolver: Include email into "resolved to account" message

Currently the "resolved to account" message looks like this:

  resolved to account <account-id>

Since it doesn't contain the email it is only useful in combination with
the preceeding "resolving code owner reference <code-owner-reference>"
message that contains the email.

Going forward we want to refactor CodeOwnerResolver to process all
emails at once rather than each email one by one. If we do this the
connection between the two messages gets lost:

  resolving code owner reference <code-owner-reference-1>
  resolving code owner reference <code-owner-reference-2>
  ...
  resolving code owner reference <code-owner-reference-n>
  ...
  resolved to account <account-id-1>
  resolved to account <account-id-2>
  ...
  resolved to account <account-id-n>

Note, the number of "resolved to account" messages may not match the
number of "resolving code owner reference" message if not all code owner
references can be resolved to accounts.

To enable the refactoring, this change includes the email into the
"resolved to account" message:

  resolved email <email> to account <account-id>

The "resolving code owner reference" message is dropped as it's no
longer needed (since now all messages contain the email).

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I5ee6dfcbe6c96a1f8b11c59437f1630cdce8f9ff
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerResolver.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerResolver.java
index e0e160b..e19bb36 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerResolver.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerResolver.java
@@ -349,8 +349,6 @@
       ImmutableList.Builder<String> messages, CodeOwnerReference codeOwnerReference) {
     String email = requireNonNull(codeOwnerReference, "codeOwnerReference").email();
 
-    messages.add(String.format("resolving code owner reference %s", codeOwnerReference));
-
     if (!isEmailDomainAllowed(messages, email)) {
       return Optional.empty();
     }
@@ -370,7 +368,7 @@
     }
 
     CodeOwner codeOwner = CodeOwner.create(accountState.account().id());
-    messages.add(String.format("resolved to account %s", codeOwner.accountId()));
+    messages.add(String.format("resolved email %s to account %s", email, codeOwner.accountId()));
     return Optional.of(codeOwner);
   }
 
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 2688b07..b7f856a 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
@@ -49,7 +49,6 @@
 import com.google.gerrit.plugins.codeowners.backend.CodeOwnerConfig;
 import com.google.gerrit.plugins.codeowners.backend.CodeOwnerConfigImportMode;
 import com.google.gerrit.plugins.codeowners.backend.CodeOwnerConfigReference;
-import com.google.gerrit.plugins.codeowners.backend.CodeOwnerReference;
 import com.google.gerrit.plugins.codeowners.backend.CodeOwnerResolver;
 import com.google.gerrit.plugins.codeowners.backend.CodeOwnerSet;
 import com.google.gerrit.plugins.codeowners.restapi.CheckCodeOwnerCapability;
@@ -1581,23 +1580,14 @@
                 project.get(),
                 getCodeOwnerConfigFileName(),
                 nonExistingProject.get()),
-            String.format(
-                "resolving code owner reference %s", CodeOwnerReference.create(user.email())),
-            String.format("resolved to account %d", user.id().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(
-                "resolving code owner reference %s", CodeOwnerReference.create(nonExistingEmail)),
-            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(
-                "resolving code owner reference %s", CodeOwnerReference.create(admin.email())),
-            String.format("resolved to account %d", admin.id().get()),
+            String.format("resolved email %s to account %d", admin.email(), admin.id().get()),
             "resolve global code owners",
-            String.format(
-                "resolving code owner reference %s",
-                CodeOwnerReference.create(globalOwner.email())),
-            String.format("resolved to account %d", globalOwner.id().get()));
+            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 0db2388..d1fa577 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerIT.java
@@ -149,7 +149,7 @@
             String.format(
                 "found email %s as code owner in %s",
                 codeOwner.email(), getCodeOwnerConfigFilePath("/foo/")),
-            String.format("resolved to account %s", codeOwner.id()));
+            String.format("resolved email %s to account %s", codeOwner.email(), codeOwner.id()));
   }
 
   @Test
@@ -186,7 +186,7 @@
             String.format(
                 "found email %s as code owner in %s",
                 codeOwner.email(), getCodeOwnerConfigFilePath(ROOT_PATH)),
-            String.format("resolved to account %s", codeOwner.id()));
+            String.format("resolved email %s to account %s", codeOwner.email(), codeOwner.id()));
   }
 
   @Test
@@ -228,7 +228,7 @@
                 "found email %s as code owner in %s",
                 codeOwner.email(), getCodeOwnerConfigFilePath("/foo/")),
             "parent code owners are ignored",
-            String.format("resolved to account %s", codeOwner.id()));
+            String.format("resolved email %s to account %s", codeOwner.email(), codeOwner.id()));
   }
 
   @Test
@@ -259,7 +259,7 @@
             String.format(
                 "found email %s as code owner in %s",
                 secondaryEmail, getCodeOwnerConfigFilePath(ROOT_PATH)),
-            String.format("resolved to account %s", codeOwner.id()));
+            String.format("resolved email %s to account %s", secondaryEmail, codeOwner.id()));
   }
 
   @Test
@@ -323,7 +323,8 @@
     assertThat(checkCodeOwnerInfo).isNotGlobalCodeOwner();
     assertThat(checkCodeOwnerInfo).isNotOwnedByAllUsers();
     assertThat(checkCodeOwnerInfo)
-        .hasDebugLogsThatContainAllOf(String.format("resolved to account %s", user.id()));
+        .hasDebugLogsThatContainAllOf(
+            String.format("resolved email %s to account %s", user.email(), user.id()));
   }
 
   @Test
@@ -569,7 +570,9 @@
             String.format(
                 "found email %s as code owner in default code owner config",
                 defaultCodeOwner.email()),
-            String.format("resolved to account %s", defaultCodeOwner.id()));
+            String.format(
+                "resolved email %s to account %s",
+                defaultCodeOwner.email(), defaultCodeOwner.id()));
   }
 
   @Test
@@ -595,7 +598,9 @@
             String.format(
                 "found email %s as code owner in default code owner config",
                 CodeOwnerResolver.ALL_USERS_WILDCARD),
-            String.format("resolved to account %s", defaultCodeOwner.id()));
+            String.format(
+                "resolved email %s to account %s",
+                defaultCodeOwner.email(), defaultCodeOwner.id()));
   }
 
   @Test
@@ -619,7 +624,8 @@
     assertThat(checkCodeOwnerInfo)
         .hasDebugLogsThatContainAllOf(
             String.format("found email %s as global code owner", globalCodeOwner.email()),
-            String.format("resolved to account %s", globalCodeOwner.id()));
+            String.format(
+                "resolved email %s to account %s", globalCodeOwner.email(), globalCodeOwner.id()));
   }
 
   @Test
@@ -646,7 +652,8 @@
         .hasDebugLogsThatContainAllOf(
             String.format(
                 "found email %s as global code owner", CodeOwnerResolver.ALL_USERS_WILDCARD),
-            String.format("resolved to account %s", globalCodeOwner.id()));
+            String.format(
+                "resolved email %s to account %s", globalCodeOwner.email(), globalCodeOwner.id()));
   }
 
   @Test
@@ -672,7 +679,7 @@
                 "found email %s as code owner in %s",
                 codeOwner.email(), getCodeOwnerConfigFilePath("/foo/")),
             String.format("account %s is visible to user %s", codeOwner.id(), user.username()),
-            String.format("resolved to account %s", codeOwner.id()));
+            String.format("resolved email %s to account %s", codeOwner.email(), codeOwner.id()));
   }
 
   @Test
@@ -929,7 +936,7 @@
             String.format(
                 "found email %s as code owner in %s",
                 mdOwner.email(), getCodeOwnerConfigFilePath("/foo/")),
-            String.format("resolved to account %s", mdOwner.id()));
+            String.format("resolved email %s to account %s", mdOwner.email(), mdOwner.id()));
     assertThat(checkCodeOwnerInfo)
         .hasDebugLogsThatDoNotContainAnyOf(
             String.format(
@@ -1000,7 +1007,8 @@
             String.format(
                 "found email %s as code owner in %s",
                 fileCodeOwner.email(), getCodeOwnerConfigFilePath("/foo/")),
-            String.format("resolved to account %s", fileCodeOwner.id()));
+            String.format(
+                "resolved email %s to account %s", fileCodeOwner.email(), fileCodeOwner.id()));
   }
 
   @Test
@@ -1054,7 +1062,7 @@
             String.format(
                 "found email %s as code owner in %s",
                 codeOwner.email(), getCodeOwnerConfigFilePath("/foo/")),
-            String.format("resolved to account %s", codeOwner.id()));
+            String.format("resolved email %s to account %s", codeOwner.email(), codeOwner.id()));
   }
 
   @Test
@@ -1118,7 +1126,8 @@
             String.format(
                 "found email %s as code owner in %s",
                 mdCodeOwner.email(), getCodeOwnerConfigFilePath("/foo/")),
-            String.format("resolved to account %s", mdCodeOwner.id()));
+            String.format(
+                "resolved email %s to account %s", mdCodeOwner.email(), mdCodeOwner.id()));
 
     // 2. check for user and path of an md file
     checkCodeOwnerInfo = checkCodeOwner(path, user.email());
@@ -1140,7 +1149,7 @@
                 testPathExpressions.matchFileType("md"),
                 getCodeOwnerConfigFileName(),
                 testPathExpressions.matchFileType("md")),
-            String.format("resolved to account %s", user.id()));
+            String.format("resolved email %s to account %s", user.email(), user.id()));
     assertThat(checkCodeOwnerInfo)
         .hasDebugLogsThatDoNotContainAnyOf(String.format("email %s", user.email()));
 
@@ -1156,7 +1165,8 @@
                 "Code owner config %s:%s:/foo/%s imports:\n"
                     + "* /bar/%s (global import, import mode = ALL)",
                 project, "master", getCodeOwnerConfigFileName(), getCodeOwnerConfigFileName()),
-            String.format("resolved to account %s", mdCodeOwner.id()));
+            String.format(
+                "resolved email %s to account %s", mdCodeOwner.email(), mdCodeOwner.id()));
     assertThat(checkCodeOwnerInfo)
         .hasDebugLogsThatDoNotContainAnyOf(String.format("email %s", mdCodeOwner.email()));
   }