Drop "Patch Set: <num>" prefix from change message that lists owned paths This prefix triggers special logic in the web frontend. If this prefix is present the frontend parses approvals from the message and shows approval chips for them. Due to this it looks like approvals have been applied twice. If a code-owners approval is applied and the message to inform about the owned paths is posted asynchronously there are 2 change messages and the web frontend shows an approval chip for both of them: 1. "Patch Set X: Code-Owner+1" posted by Gerrit core 2. "Patch Set X: By voting Code-Review+1 the following files are now code-owner approved by YYY: ..." posted by the code-owners plugin By dropping the "Patch Set: <num>" prefix from the second change message, the approval chip will only be shown for the first message. Dropping the patch set information from the second change message is fine, since the patch set to which the message relates is still available from the change message meta data. This problem started happening after the code-owners plugin has been changed to post the code-owner approved paths asynchronously in a separate change message, rather then extending the change message that Gerrit core posts about the approval (see change I129e611af). Bug: Google b/276276203 Signed-off-by: Edwin Kempin <ekempin@google.com> Change-Id: I97a9bf0f8818abf31a071f88260359fbe677b30e
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerApproval.java b/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerApproval.java index 3977521..b3417dc 100644 --- a/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerApproval.java +++ b/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerApproval.java
@@ -509,10 +509,7 @@ return false; } - changeMessageUtil.setChangeMessage( - ctx, - String.format("Patch Set %s: %s", patchSet.id().get(), message.get()), - TAG_ADD_CODE_OWNER_APPROVAL); + changeMessageUtil.setChangeMessage(ctx, message.get(), TAG_ADD_CODE_OWNER_APPROVAL); return true; } }
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 3875eb9..ea3b6ae 100644 --- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerApprovalIT.java +++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerApprovalIT.java
@@ -1183,8 +1183,7 @@ assertAsyncChangeMessage( changeId, String.format( - "Patch Set 1: " - + "By voting Code-Review+1 the following files are now code-owner approved by" + "By voting Code-Review+1 the following files are now code-owner approved by" + " %s:\n" + "* %s\n", AccountTemplateUtil.getAccountTemplate(admin.id()), path),