submitted_together: Add option to count non-visible changes
Instead of giving up with a 403 when some of the changes to be
submitted together are not visible to the current user,
/changes/{change}/submitted_together?o=NON_VISIBLE_CHANGES adds an
extra non_visible_changes integer field to the response counting those
changes they can't see.
A later change can expose this count in the UI so the user can decide
whether to change the topic or try to make progress toward being able
to see all the changes to be submitted together. In the latter case,
the user can use that count to see how close they are to done.
Change-Id: I085e8029038c4e86bcc9529cf60d50f6d44d2f00
This commit is contained in:
@@ -16,12 +16,15 @@ package com.google.gerrit.acceptance.server.change;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.acceptance.GitUtil.pushHead;
|
||||
import static com.google.gerrit.extensions.api.changes.SubmittedTogetherOption.NON_VISIBLE_CHANGES;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.GitUtil;
|
||||
import com.google.gerrit.acceptance.TestProjectInput;
|
||||
import com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo;
|
||||
import com.google.gerrit.extensions.client.ChangeStatus;
|
||||
import com.google.gerrit.extensions.client.SubmitType;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.testutil.ConfigSuite;
|
||||
@@ -33,6 +36,9 @@ import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
public class SubmittedTogetherIT extends AbstractDaemonTest {
|
||||
@ConfigSuite.Config
|
||||
public static Config submitWholeTopicEnabled() {
|
||||
@@ -130,6 +136,33 @@ public class SubmittedTogetherIT extends AbstractDaemonTest {
|
||||
commitBuilder().add("b", "2").message("invisible change").create();
|
||||
pushHead(testRepo, "refs/drafts/master/" + name("topic"), false);
|
||||
|
||||
setApiUser(user);
|
||||
SubmittedTogetherInfo result = gApi.changes()
|
||||
.id(id1)
|
||||
.submittedTogether(EnumSet.of(NON_VISIBLE_CHANGES));
|
||||
|
||||
if (isSubmitWholeTopicEnabled()) {
|
||||
assertThat(result.changes).hasSize(1);
|
||||
assertThat(result.changes.get(0).changeId).isEqualTo(id1);
|
||||
assertThat(result.nonVisibleChanges).isEqualTo(1);
|
||||
} else {
|
||||
assertThat(result.changes).hasSize(0);
|
||||
assertThat(result.nonVisibleChanges).isEqualTo(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hiddenDraftInTopicOldApi() throws Exception {
|
||||
RevCommit initialHead = getRemoteHead();
|
||||
RevCommit a = commitBuilder().add("a", "1").message("change 1").create();
|
||||
pushHead(testRepo, "refs/for/master/" + name("topic"), false);
|
||||
String id1 = getChangeId(a);
|
||||
|
||||
testRepo.reset(initialHead);
|
||||
RevCommit b =
|
||||
commitBuilder().add("b", "2").message("invisible change").create();
|
||||
pushHead(testRepo, "refs/drafts/master/" + name("topic"), false);
|
||||
|
||||
setApiUser(user);
|
||||
if (isSubmitWholeTopicEnabled()) {
|
||||
exception.expect(AuthException.class);
|
||||
@@ -137,7 +170,36 @@ public class SubmittedTogetherIT extends AbstractDaemonTest {
|
||||
"change would be submitted with a change that you cannot see");
|
||||
gApi.changes().id(id1).submittedTogether();
|
||||
} else {
|
||||
assertSubmittedTogether(id1);
|
||||
List<ChangeInfo> result = gApi.changes().id(id1).submittedTogether();
|
||||
assertThat(result).hasSize(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doNotRevealVisibleAncestorOfHiddenDraft() throws Exception {
|
||||
RevCommit initialHead = getRemoteHead();
|
||||
commitBuilder().message("parent").create();
|
||||
pushHead(testRepo, "refs/for/master", false);
|
||||
|
||||
commitBuilder().message("draft").create();
|
||||
pushHead(testRepo, "refs/drafts/master/" + name("topic"), false);
|
||||
|
||||
testRepo.reset(initialHead);
|
||||
RevCommit change = commitBuilder().message("same topic").create();
|
||||
pushHead(testRepo, "refs/for/master/" + name("topic"), false);
|
||||
String id = getChangeId(change);
|
||||
|
||||
setApiUser(user);
|
||||
SubmittedTogetherInfo result = gApi.changes()
|
||||
.id(id)
|
||||
.submittedTogether(EnumSet.of(NON_VISIBLE_CHANGES));
|
||||
if (isSubmitWholeTopicEnabled()) {
|
||||
assertThat(result.changes).hasSize(1);
|
||||
assertThat(result.changes.get(0).changeId).isEqualTo(id);
|
||||
assertThat(result.nonVisibleChanges).isEqualTo(2);
|
||||
} else {
|
||||
assertThat(result.changes).isEmpty();
|
||||
assertThat(result.nonVisibleChanges).isEqualTo(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user