Adjust to Gerrit core change Ide1b122b The core changes make PostReview no longer ignore when a vote is reapplied. Some tests needed to be fixed as we assumed that Gerrit core does ignore such behaviour. Change-Id: I8b378c75c312c30cee41cb1a6144be0ddf6c0d20
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersOnPostReview.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersOnPostReview.java index 68573a4..f53d831 100644 --- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersOnPostReview.java +++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersOnPostReview.java
@@ -83,8 +83,7 @@ if (oldApprovals.get(requiredApproval.labelType().getName()) == null) { // If oldApprovals doesn't contain the label or if the labels value in it is null, the label // was not changed. - // This either means that the user only voted on unrelated labels, or that the user applied - // the exact same code owner approval again, that was already present. + // This means that the user only voted on unrelated labels. return Optional.empty(); }
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnersOnPostReviewIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnersOnPostReviewIT.java index 761472b..5c3f509 100644 --- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnersOnPostReviewIT.java +++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnersOnPostReviewIT.java
@@ -90,7 +90,7 @@ } @Test - public void changeMessageNotExtended_sameCodeOwnerApprovalAppliedAgain() throws Exception { + public void changeMessageExtended_sameCodeOwnerApprovalAppliedAgain() throws Exception { codeOwnerConfigOperations .newCodeOwnerConfig() .project(project) @@ -109,13 +109,22 @@ // Apply the Code-Review+1 approval again recommend(changeId); - // Check that no new change message was added. - // Gerrit core omits the change message if no vote was changed. - assertThat(gApi.changes().id(changeId).get().messages.size()).isEqualTo(messageCount); + Collection<ChangeMessageInfo> messages = gApi.changes().id(changeId).get().messages; + // Check that a new change message was added. + assertThat(messages.size()).isEqualTo(messageCount + 1); + + assertThat(Iterables.getLast(messages).message) + .isEqualTo( + String.format( + "Patch Set 1: Code-Review+1\n\n" + + "By voting Code-Review+1 the following files are still code-owner approved by" + + " %s:\n" + + "* %s\n", + admin.fullName(), path)); } @Test - public void changeMessageNotExtended_sameCodeOwnerApprovalAppliedAgainTogetherWithOtherLabel() + public void changeMessageExtended_sameCodeOwnerApprovalAppliedAgainTogetherWithOtherLabel() throws Exception { LabelDefinitionInput input = new LabelDefinitionInput(); input.values = ImmutableMap.of("+1", "Other", " 0", "Approved"); @@ -153,11 +162,18 @@ // The message is unchanged, since reapplying the same code owner approval is ignored by Gerrit // core (the change message only mentions the new vote, but not the reapplied vote). Collection<ChangeMessageInfo> messages = gApi.changes().id(changeId).get().messages; - assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 1: Other+1"); + assertThat(Iterables.getLast(messages).message) + .isEqualTo( + String.format( + "Patch Set 1: Code-Review+1 Other+1\n\n" + + "By voting Code-Review+1 the following files are still code-owner approved by" + + " %s:\n" + + "* %s\n", + admin.fullName(), path)); } @Test - public void changeMessageNotExtended_sameCodeOwnerApprovalAppliedAgainTogetherWithComment() + public void changeMessageExtended_sameCodeOwnerApprovalAppliedAgainTogetherWithComment() throws Exception { LabelDefinitionInput input = new LabelDefinitionInput(); input.values = ImmutableMap.of("+1", "Other", " 0", "Approved"); @@ -193,14 +209,21 @@ commentInput.message = "some comment"; commentInput.path = path; ReviewInput reviewInput = ReviewInput.recommend(); - reviewInput.comments = reviewInput.comments = new HashMap<>(); + reviewInput.comments = new HashMap<>(); reviewInput.comments.put(commentInput.path, Lists.newArrayList(commentInput)); gApi.changes().id(changeId).current().review(reviewInput); // The message is unchanged, since reapplying the same code owner approval is ignored by Gerrit // core (the change message only mentions the comment, but not the reapplied vote). Collection<ChangeMessageInfo> messages = gApi.changes().id(changeId).get().messages; - assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 1:\n\n" + "(1 comment)"); + assertThat(Iterables.getLast(messages).message) + .isEqualTo( + String.format( + "Patch Set 1: Code-Review+1\n\n(1 comment)\n\n" + + "By voting Code-Review+1 the following files are still code-owner approved by" + + " %s:\n" + + "* %s\n", + admin.fullName(), path)); } @Test @@ -864,7 +887,7 @@ commentInput.message = "some comment"; commentInput.path = path; ReviewInput reviewInput = ReviewInput.recommend(); - reviewInput.comments = reviewInput.comments = new HashMap<>(); + reviewInput.comments = new HashMap<>(); reviewInput.comments.put(commentInput.path, Lists.newArrayList(commentInput)); gApi.changes().id(changeId).current().review(reviewInput);