ReceiveCommits: Include approvals from magic branch in change message

I52a6799395 extended magic branch options with approvals, but missed
to include the approvals in the change message.

Render the approvals for new change and for new patch set.

* Uploaded patch set 1: Code-Review-1 Verified+1.
* Uploaded patch set 2: Code-Review+1 Verified-1: Commit message was
  updated.

Label votes are only included in the change message, when they differ
from the current votes from the same user. This is the same logic as
implemented in PostReview.

Unit test is extended to verify that the approvals included in change
message. To prevent the test to be flaky and make chronological sorting
order stable (createdOn attribute of message) clock step is bumped to 1
second in AbstractPushForReview.

Reported-By: Khai Do <zaro0508@gmail.com>
Change-Id: I60a5f1447f084dfd3967ee335652df4a75354a71
This commit is contained in:
David Ostrovsky
2015-10-11 10:47:21 +02:00
parent d79ac58829
commit 44a935eb0a
3 changed files with 99 additions and 8 deletions

View File

@@ -17,8 +17,11 @@ package com.google.gerrit.acceptance.git;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.TruthJUnit.assume;
import static com.google.gerrit.acceptance.GitUtil.cloneProject;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.GitUtil;
import com.google.gerrit.acceptance.PushOneCommit;
@@ -41,12 +44,18 @@ import com.jcraft.jsch.JSchException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.transport.PushResult;
import org.joda.time.DateTime;
import org.joda.time.DateTimeUtils;
import org.joda.time.DateTimeUtils.MillisProvider;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
public abstract class AbstractPushForReview extends AbstractDaemonTest {
@ConfigSuite.Config
@@ -63,6 +72,24 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
private String sshUrl;
@BeforeClass
public static void setTimeForTesting() {
final long clockStepMs = MILLISECONDS.convert(1, SECONDS);
final AtomicLong clockMs = new AtomicLong(
new DateTime(2009, 9, 30, 17, 0, 0).getMillis());
DateTimeUtils.setCurrentMillisProvider(new MillisProvider() {
@Override
public long getMillis() {
return clockMs.getAndAdd(clockStepMs);
}
});
}
@AfterClass
public static void restoreTime() {
DateTimeUtils.setCurrentMillisSystem();
}
@Before
public void setUp() throws Exception {
sshUrl = sshSession.getUrl();
@@ -194,6 +221,8 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
assertThat(cr.all).hasSize(1);
assertThat(cr.all.get(0).name).isEqualTo("Administrator");
assertThat(cr.all.get(0).value.intValue()).is(1);
assertThat(Iterables.getLast(ci.messages).message).isEqualTo(
"Uploaded patch set 1: Code-Review+1.");
PushOneCommit push =
pushFactory.create(db, admin.getIdent(), PushOneCommit.SUBJECT,
@@ -202,9 +231,20 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
ci = get(r.getChangeId());
cr = ci.labels.get("Code-Review");
assertThat(Iterables.getLast(ci.messages).message).isEqualTo(
"Uploaded patch set 2: Code-Review+2.");
assertThat(cr.all).hasSize(1);
assertThat(cr.all.get(0).name).isEqualTo("Administrator");
assertThat(cr.all.get(0).value.intValue()).is(2);
push =
pushFactory.create(db, admin.getIdent(), PushOneCommit.SUBJECT,
"c.txt", "moreContent", r.getChangeId());
r = push.to(git, "refs/for/master/%l=Code-Review+2");
ci = get(r.getChangeId());
assertThat(Iterables.getLast(ci.messages).message).isEqualTo(
"Uploaded patch set 3.");
}
@Test