Revert change: Fix change messages

When a change is reverted, there should be a change message on this
change that says that the change was reverted. This change message
should includes a link to the revert change. So far this message was
wrongly added to the revert change, but not to the change that was
reverted. The change message on the revert change should simply say
"Uploaded patch set 1.", as message-wise there should be no difference
whether a revert change was created by the revert REST endpoint or by
upload.

Change-Id: I342f55e9523a84ca63c27e266a21395e8c3f6f2e
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2015-10-29 17:00:30 +01:00
parent e8a5608a67
commit 1304ceec70
2 changed files with 43 additions and 5 deletions

View File

@@ -38,6 +38,7 @@ import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.common.ApprovalInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.ChangeMessageInfo;
import com.google.gerrit.extensions.common.LabelInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
@@ -125,9 +126,28 @@ public class ChangeIT extends AbstractDaemonTest {
.id(r.getChangeId())
.revision(r.getCommit().name())
.submit();
gApi.changes()
.id(r.getChangeId())
.revert();
ChangeInfo revertChange =
gApi.changes()
.id(r.getChangeId())
.revert().get();
// expected messages on source change:
// 1. Uploaded patch set 1.
// 2. Patch Set 1: Code-Review+2
// 3. Change has been successfully merged by Administrator
// 4. Patch Set 1: Reverted
List<ChangeMessageInfo> sourceMessages = new ArrayList<>(
gApi.changes().id(r.getChangeId()).get().messages);
assertThat(sourceMessages).hasSize(4);
String expectedMessage = String.format(
"Patch Set 1: Reverted\n\n" +
"This patchset was reverted in change: %s",
revertChange.changeId);
assertThat(sourceMessages.get(3).message).isEqualTo(expectedMessage);
assertThat(revertChange.messages).hasSize(1);
assertThat(revertChange.messages.iterator().next().message)
.isEqualTo("Uploaded patch set 1.");
}
// Change is already up to date