ChangesCollection: Return different text on multiple changes

Users are often confused when looking up a change just says "Not
found" when they are sure a change exists, but weren't aware that a
search returned multiple changes. Distinguish between these two cases
by changing the human-readable text in the response.

Change-Id: I87f6cd231be026e2bb48f26e18f11a5485aeb0e9
This commit is contained in:
Dave Borowitz
2015-12-07 15:49:04 -05:00
parent d42efe72a2
commit f78de90f37
2 changed files with 30 additions and 1 deletions

View File

@@ -39,6 +39,7 @@ import com.google.gerrit.extensions.api.changes.AddReviewerInput;
import com.google.gerrit.extensions.api.changes.RebaseInput;
import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.api.changes.RevisionApi;
import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.common.AccountInfo;
@@ -50,6 +51,7 @@ import com.google.gerrit.extensions.common.LabelInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Change;
@@ -94,6 +96,30 @@ public class ChangeIT extends AbstractDaemonTest {
assertThat(c.owner.avatars).isNull();
}
@Test
public void getAmbiguous() throws Exception {
PushOneCommit.Result r1 = createChange();
String changeId = r1.getChangeId();
gApi.changes().id(changeId).get();
BranchInput b = new BranchInput();
b.revision = repo().getRef("HEAD").getObjectId().name();
gApi.projects()
.name(project.get())
.branch("other")
.create(b);
PushOneCommit push2 = pushFactory.create(db, admin.getIdent(), testRepo,
PushOneCommit.SUBJECT, PushOneCommit.FILE_NAME,
PushOneCommit.FILE_CONTENT, changeId);
PushOneCommit.Result r2 = push2.to("refs/for/other");
assertThat(r2.getChangeId()).isEqualTo(changeId);
exception.expect(ResourceNotFoundException.class);
exception.expectMessage("Multiple changes found for " + changeId);
gApi.changes().id(changeId).get();
}
@Test
public void abandon() throws Exception {
PushOneCommit.Result r = createChange();