Merge "Replace user details with templates in change messages"
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersOnAddReviewer.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersOnAddReviewer.java
index 1aa9660..f8e5be7 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersOnAddReviewer.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersOnAddReviewer.java
@@ -20,7 +20,6 @@
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Change;
-import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.events.ReviewerAddedListener;
@@ -149,9 +148,7 @@
return false;
}
- ChangeMessage changeMessage = ChangeMessagesUtil.newMessage(ctx, message, TAG_ADD_REVIEWER);
- changeMessageUtil.addChangeMessage(
- ctx.getUpdate(ctx.getChange().currentPatchSetId()), changeMessage);
+ changeMessageUtil.setChangeMessage(ctx, message, TAG_ADD_REVIEWER);
return true;
}
@@ -181,13 +178,11 @@
return Optional.empty();
}
- Account reviewerAccount = accountCache.getEvenIfMissing(reviewerAccountId).account();
-
StringBuilder message = new StringBuilder();
message.append(
String.format(
"%s who was added as reviewer owns the following files:\n",
- reviewerAccount.getName()));
+ ChangeMessagesUtil.getAccountTemplate(reviewerAccountId)));
if (ownedPaths.size() <= limit) {
appendPaths(message, ownedPaths.stream());
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerApproval.java b/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerApproval.java
index d6beb5f..4fbc365 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerApproval.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerApproval.java
@@ -26,6 +26,7 @@
import com.google.gerrit.plugins.codeowners.backend.config.RequiredApproval;
import com.google.gerrit.plugins.codeowners.metrics.CodeOwnerMetrics;
import com.google.gerrit.plugins.codeowners.util.JgitPath;
+import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.restapi.change.OnPostReview;
@@ -166,12 +167,12 @@
message.append(
String.format(
"By voting %s the following files are now explicitly code-owner approved by %s:\n",
- newVote, user.getName()));
+ newVote, ChangeMessagesUtil.getAccountTemplate(user.getAccountId())));
} else {
message.append(
String.format(
"By voting %s the following files are now code-owner approved by %s:\n",
- newVote, user.getName()));
+ newVote, ChangeMessagesUtil.getAccountTemplate(user.getAccountId())));
}
} else if (isCodeOwnerApprovalRemoved(requiredApproval, oldApprovals, newVote)) {
if (newVote.value() == 0) {
@@ -181,13 +182,13 @@
String.format(
"By removing the %s vote the following files are no longer explicitly code-owner"
+ " approved by %s:\n",
- newVote.label(), user.getName()));
+ newVote.label(), ChangeMessagesUtil.getAccountTemplate(user.getAccountId())));
} else {
message.append(
String.format(
"By removing the %s vote the following files are no longer code-owner approved"
+ " by %s:\n",
- newVote.label(), user.getName()));
+ newVote.label(), ChangeMessagesUtil.getAccountTemplate(user.getAccountId())));
}
} else {
if (hasImplicitApprovalByUser) {
@@ -196,12 +197,12 @@
String.format(
"By voting %s the following files are no longer explicitly code-owner approved by"
+ " %s:\n",
- newVote, user.getName()));
+ newVote, ChangeMessagesUtil.getAccountTemplate(user.getAccountId())));
} else {
message.append(
String.format(
"By voting %s the following files are no longer code-owner approved by %s:\n",
- newVote, user.getName()));
+ newVote, ChangeMessagesUtil.getAccountTemplate(user.getAccountId())));
}
}
} else if (isCodeOwnerApprovalUpOrDowngraded(requiredApproval, oldApprovals, newVote)) {
@@ -210,12 +211,12 @@
String.format(
"By voting %s the following files are still explicitly code-owner approved by"
+ " %s:\n",
- newVote, user.getName()));
+ newVote, ChangeMessagesUtil.getAccountTemplate(user.getAccountId())));
} else {
message.append(
String.format(
"By voting %s the following files are still code-owner approved by %s:\n",
- newVote, user.getName()));
+ newVote, ChangeMessagesUtil.getAccountTemplate(user.getAccountId())));
}
} else {
// non-approval was downgraded (e.g. -1 to -2)
@@ -232,7 +233,8 @@
if (hasImplicitApprovalByUser && noLongerExplicitlyApproved) {
message.append(
String.format(
- "\nThe listed files are still implicitly approved by %s.\n", user.getName()));
+ "\nThe listed files are still implicitly approved by %s.\n",
+ ChangeMessagesUtil.getAccountTemplate(user.getAccountId())));
}
return Optional.of(message.toString());
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerOverride.java b/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerOverride.java
index 09e3624..d936fea 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerOverride.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerOverride.java
@@ -26,6 +26,7 @@
import com.google.gerrit.plugins.codeowners.backend.config.CodeOwnersPluginProjectConfigSnapshot;
import com.google.gerrit.plugins.codeowners.backend.config.RequiredApproval;
import com.google.gerrit.plugins.codeowners.metrics.CodeOwnerMetrics;
+import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.restapi.change.OnPostReview;
@@ -127,24 +128,24 @@
return Optional.of(
String.format(
"By voting %s the code-owners submit requirement is overridden by %s",
- newVote, user.getName()));
+ newVote, ChangeMessagesUtil.getAccountTemplate(user.getAccountId())));
} else if (isCodeOwnerOverrideRemoved(overrideApproval, oldApprovals, newVote)) {
if (newVote.value() == 0) {
return Optional.of(
String.format(
"By removing the %s vote the code-owners submit requirement is no longer overridden"
+ " by %s",
- newVote.label(), user.getName()));
+ newVote.label(), ChangeMessagesUtil.getAccountTemplate(user.getAccountId())));
}
return Optional.of(
String.format(
"By voting %s the code-owners submit requirement is no longer overridden by %s",
- newVote, user.getName()));
+ newVote, ChangeMessagesUtil.getAccountTemplate(user.getAccountId())));
} else if (isCodeOwnerOverrideUpOrDowngraded(overrideApproval, oldApprovals, newVote)) {
return Optional.of(
String.format(
"By voting %s the code-owners submit requirement is still overridden by %s",
- newVote, user.getName()));
+ newVote, ChangeMessagesUtil.getAccountTemplate(user.getAccountId())));
}
// non-approval was downgraded (e.g. -1 to -2)
return Optional.empty();
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnersOnAddReviewerIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnersOnAddReviewerIT.java
index 91c40db..5d60df9 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnersOnAddReviewerIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnersOnAddReviewerIT.java
@@ -25,6 +25,7 @@
import com.google.gerrit.extensions.api.projects.DeleteBranchesInput;
import com.google.gerrit.extensions.common.ChangeMessageInfo;
import com.google.gerrit.plugins.codeowners.acceptance.AbstractCodeOwnersIT;
+import com.google.gerrit.server.ChangeMessagesUtil;
import java.util.Collection;
import org.junit.Test;
@@ -89,7 +90,7 @@
.isEqualTo(
String.format(
"%s who was added as reviewer owns the following files:\n* %s\n",
- user.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(user.id()), path));
}
@Test
@@ -125,7 +126,7 @@
.isEqualTo(
String.format(
"%s who was added as reviewer owns the following files:\n* %s\n* %s\n",
- user.fullName(), path1, path2));
+ ChangeMessagesUtil.getAccountTemplate(user.id()), path1, path2));
}
@Test
@@ -192,7 +193,7 @@
+ "* %s\n"
+ "* %s\n"
+ "* %s\n",
- user.fullName(), path4, path3, path1, path2));
+ ChangeMessagesUtil.getAccountTemplate(user.id()), path4, path3, path1, path2));
}
@Test
@@ -238,7 +239,7 @@
+ "* %s\n"
+ "* %s\n"
+ "(more files)\n",
- user.fullName(), path4, path3, path5));
+ ChangeMessagesUtil.getAccountTemplate(user.id()), path4, path3, path5));
}
@Test
@@ -321,7 +322,7 @@
.isEqualTo(
String.format(
"%s who was added as reviewer owns the following files:\n* %s\n",
- user.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(user.id()), path));
}
@Test
@@ -352,11 +353,11 @@
+ "By voting Code-Review+1 the following files are now code-owner approved by"
+ " %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
assertThat(Iterables.getLast(messages).message)
.isEqualTo(
String.format(
"%s who was added as reviewer owns the following files:\n* %s\n",
- user.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(user.id()), path));
}
}
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerApprovalIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerApprovalIT.java
index 8a8b9c4..7943ce9 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerApprovalIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerApprovalIT.java
@@ -31,6 +31,7 @@
import com.google.gerrit.extensions.common.ChangeMessageInfo;
import com.google.gerrit.extensions.common.LabelDefinitionInput;
import com.google.gerrit.plugins.codeowners.acceptance.AbstractCodeOwnersIT;
+import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.inject.Inject;
import java.util.Collection;
import java.util.HashMap;
@@ -84,7 +85,7 @@
+ "By voting Code-Review+1 the following files are now code-owner approved by"
+ " %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
}
@Test
@@ -118,7 +119,7 @@
+ "By voting Code-Review+1 the following files are now code-owner approved by"
+ " %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
}
@Test
@@ -160,7 +161,7 @@
+ "By voting Code-Review+1 the following files are now code-owner approved by"
+ " %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
// Apply the Code-Review+1 approval again and add an unrelated vote (Code-Review+1 is ignored).
ReviewInput reviewInput = ReviewInput.recommend();
@@ -210,7 +211,7 @@
+ "By voting Code-Review+1 the following files are now code-owner approved by"
+ " %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
// Apply the Code-Review+1 approval again and add a comment (Code-Review +1 is ignored)
ReviewInput.CommentInput commentInput = new ReviewInput.CommentInput();
@@ -251,7 +252,7 @@
+ "By voting Code-Review+1 the following files are now code-owner approved by"
+ " %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
// Apply the Code-Review+1 by another code owner
requestScopeOperations.setApiUser(user.id());
@@ -265,7 +266,7 @@
+ "By voting Code-Review+1 the following files are now code-owner approved by"
+ " %s:\n"
+ "* %s\n",
- user.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(user.id()), path));
}
@Test
@@ -294,7 +295,7 @@
+ "By voting Code-Review+2 the following files are still code-owner approved by"
+ " %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
}
@Test
@@ -326,7 +327,7 @@
+ "By voting Code-Review+1 the following files are still explicitly code-owner"
+ " approved by %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
}
@Test
@@ -358,7 +359,7 @@
+ "By voting Code-Review+2 the following files are still explicitly code-owner"
+ " approved by %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
}
@Test
@@ -387,7 +388,7 @@
+ "By voting Code-Review+1 the following files are still code-owner approved by"
+ " %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
}
@Test
@@ -416,7 +417,7 @@
+ "By removing the Code-Review vote the following files are no longer"
+ " code-owner approved by %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
}
@Test
@@ -446,7 +447,7 @@
+ "By voting Code-Review-1 the following files are no longer code-owner"
+ " approved by %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
}
@Test
@@ -486,7 +487,7 @@
+ " %s:\n"
+ "* %s\n"
+ "* %s\n",
- admin.fullName(), path1, path2));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path1, path2));
}
@Test
@@ -514,7 +515,7 @@
+ "By voting Code-Review+1 the following files are now code-owner approved by"
+ " %s:\n"
+ "* %s\n",
- admin.fullName(), oldPath));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), oldPath));
}
@Test
@@ -587,7 +588,7 @@
+ "By voting Code-Review+1 the following files are now explicitly code-owner"
+ " approved by %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
}
@Test
@@ -620,7 +621,9 @@
+ "* %s\n"
+ "\n"
+ "The listed files are still implicitly approved by %s.\n",
- admin.fullName(), path, admin.fullName()));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()),
+ path,
+ ChangeMessagesUtil.getAccountTemplate(admin.id())));
}
@Test
@@ -653,7 +656,9 @@
+ "* %s\n"
+ "\n"
+ "The listed files are still implicitly approved by %s.\n",
- admin.fullName(), path, admin.fullName()));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()),
+ path,
+ ChangeMessagesUtil.getAccountTemplate(admin.id())));
}
@Test
@@ -681,7 +686,7 @@
+ "By voting Code-Review+1 the following files are now code-owner approved by"
+ " %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
}
@Test
@@ -713,7 +718,7 @@
+ "By removing the Code-Review vote the following files are no longer"
+ " code-owner approved by %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
}
@Test
@@ -745,7 +750,7 @@
+ "By voting Code-Review-1 the following files are no longer code-owner"
+ " approved by %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
}
@Test
@@ -790,7 +795,7 @@
+ "* %s\n"
+ "* %s\n"
+ "* %s\n",
- admin.fullName(), path4, path3, path1, path2));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path4, path3, path1, path2));
}
@Test
@@ -838,7 +843,7 @@
+ "* %s\n"
+ "* %s\n"
+ "(more files)\n",
- admin.fullName(), path4, path3, path5));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path4, path3, path5));
}
@Test
@@ -904,7 +909,7 @@
+ "By voting Code-Review+1 the following files are now code-owner approved by"
+ " %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
}
@Test
@@ -1063,7 +1068,7 @@
+ "By voting Code-Review+1 the following files are now code-owner approved by"
+ " %s:\n"
+ "* %s\n",
- user.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(user.id()), path));
}
@Test
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerOverrrideIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerOverrrideIT.java
index 1265466..b95cf42 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerOverrrideIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerOverrrideIT.java
@@ -31,6 +31,7 @@
import com.google.gerrit.extensions.common.ChangeMessageInfo;
import com.google.gerrit.extensions.common.LabelDefinitionInput;
import com.google.gerrit.plugins.codeowners.acceptance.AbstractCodeOwnersIT;
+import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.inject.Inject;
import java.util.Collection;
import java.util.HashMap;
@@ -71,7 +72,7 @@
String.format(
"Patch Set 1: Owners-Override+1\n\n"
+ "By voting Owners-Override+1 the code-owners submit requirement is overridden by %s\n",
- admin.fullName()));
+ ChangeMessagesUtil.getAccountTemplate(admin.id())));
}
@Test
@@ -108,7 +109,7 @@
String.format(
"Patch Set 1: Owners-Override+1\n\n"
+ "By voting Owners-Override+1 the code-owners submit requirement is overridden by %s\n",
- admin.fullName()));
+ ChangeMessagesUtil.getAccountTemplate(admin.id())));
// Apply the Owners-Override+1 approval by another user
requestScopeOperations.setApiUser(user.id());
@@ -120,7 +121,7 @@
String.format(
"Patch Set 1: Owners-Override+1\n\n"
+ "By voting Owners-Override+1 the code-owners submit requirement is overridden by %s\n",
- user.fullName()));
+ ChangeMessagesUtil.getAccountTemplate(user.id())));
}
@Test
@@ -156,7 +157,7 @@
"Patch Set 1: Owners-Override+2\n\n"
+ "By voting Owners-Override+2 the code-owners submit requirement is still"
+ " overridden by %s\n",
- admin.fullName()));
+ ChangeMessagesUtil.getAccountTemplate(admin.id())));
}
@Test
@@ -192,7 +193,7 @@
"Patch Set 1: Owners-Override+1\n\n"
+ "By voting Owners-Override+1 the code-owners submit requirement is still"
+ " overridden by %s\n",
- admin.fullName()));
+ ChangeMessagesUtil.getAccountTemplate(admin.id())));
}
@Test
@@ -214,7 +215,7 @@
"Patch Set 1: -Owners-Override\n\n"
+ "By removing the Owners-Override vote the code-owners submit requirement is"
+ " no longer overridden by %s\n",
- admin.fullName()));
+ ChangeMessagesUtil.getAccountTemplate(admin.id())));
}
@Test
@@ -250,7 +251,7 @@
"Patch Set 1: Owners-Override-1\n\n"
+ "By voting Owners-Override-1 the code-owners submit requirement is no longer"
+ " overridden by %s\n",
- admin.fullName()));
+ ChangeMessagesUtil.getAccountTemplate(admin.id())));
}
@Test
@@ -308,7 +309,7 @@
+ "(1 comment)\n\n"
+ "By voting Owners-Override+1 the code-owners submit requirement is"
+ " overridden by %s\n",
- admin.fullName()));
+ ChangeMessagesUtil.getAccountTemplate(admin.id())));
}
@Test
@@ -351,7 +352,7 @@
String.format(
"Patch Set 1: Owners-Override+1\n\n"
+ "By voting Owners-Override+1 the code-owners submit requirement is overridden by %s\n",
- admin.fullName()));
+ ChangeMessagesUtil.getAccountTemplate(admin.id())));
}
@Test
@@ -386,7 +387,8 @@
+ " overridden by %s\n\n"
+ "By voting Owners-Override+1 the code-owners submit requirement is"
+ " overridden by %s\n",
- admin.fullName(), admin.fullName())));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()),
+ ChangeMessagesUtil.getAccountTemplate(admin.id()))));
}
@Test
@@ -420,14 +422,14 @@
String.format(
"By voting Owners-Override+1 the code-owners submit requirement is"
+ " overridden by %s\n",
- admin.fullName()));
+ ChangeMessagesUtil.getAccountTemplate(admin.id())));
assertThat(Iterables.getLast(messages).message)
.contains(
String.format(
"By voting Code-Review+1 the following files are now code-owner approved by"
+ " %s:\n"
+ "* %s\n",
- admin.fullName(), path));
+ ChangeMessagesUtil.getAccountTemplate(admin.id()), path));
}
@Test
@@ -597,7 +599,7 @@
String.format(
"Patch Set 1: Owners-Override+1\n\n"
+ "By voting Owners-Override+1 the code-owners submit requirement is overridden by %s\n",
- user.fullName()));
+ ChangeMessagesUtil.getAccountTemplate(user.id())));
}
@Test