Use dedicated endpoint for commit message retrieval for revisions

Instead of using GET /changes/<number>/edit:message for both edits and
normal revisions, differentiate on the client side and use dedicated
endpoints.

Change-Id: I7e9786c0b828cca9b0aa76bab43f10d223334d86
This commit is contained in:
David Ostrovsky
2014-12-15 21:18:59 +01:00
committed by David Pursehouse
parent 8ffdfc1243
commit 25ad15e451
4 changed files with 25 additions and 29 deletions

View File

@@ -1462,8 +1462,7 @@ Retrieves content MIME type of a file from a change edit.
'GET /changes/link:#change-id[\{change-id\}]/edit:message 'GET /changes/link:#change-id[\{change-id\}]/edit:message
-- --
Retrieves commit message from change edit or from current patch set when Retrieves commit message from change edit.
change edit doesn't exist.
.Request .Request
---- ----

View File

@@ -275,11 +275,19 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test @Test
public void updateMessageRest() throws Exception { public void updateMessageRest() throws Exception {
assertThat(adminSession.get(urlEditMessage()).getStatusCode())
.isEqualTo(SC_NOT_FOUND);
EditMessage.Input in = new EditMessage.Input(); EditMessage.Input in = new EditMessage.Input();
in.message = String.format("New commit message\n\nChange-Id: %s", in.message = String.format("New commit message\n\nChange-Id: %s",
change.getKey()); change.getKey());
assertThat(adminSession.put(urlEditMessage(), in).getStatusCode()) assertThat(adminSession.put(urlEditMessage(), in).getStatusCode())
.isEqualTo(SC_NO_CONTENT); .isEqualTo(SC_NO_CONTENT);
RestResponse r = adminSession.get(urlEditMessage());
assertThat(adminSession.get(urlEditMessage()).getStatusCode())
.isEqualTo(SC_OK);
String content = r.getEntityContent();
assertThat(StringUtils.newStringUtf8(Base64.decodeBase64(content)))
.isEqualTo(in.message);
Optional<ChangeEdit> edit = editUtil.byChange(change); Optional<ChangeEdit> edit = editUtil.byChange(change);
assertThat(edit.get().getEditCommit().getFullMessage()) assertThat(edit.get().getEditCommit().getFullMessage())
.isEqualTo(in.message); .isEqualTo(in.message);

View File

@@ -77,23 +77,16 @@ public class ChangeFileApi {
}); });
} }
/** Get commit message in a PatchSet or change edit. */
public static void getMessage(PatchSet.Id id, AsyncCallback<String> cb) {
ChangeApi.change(id.getParentKey().get()).view("edit:message").get(
wrapper(cb));
}
/** /**
* Get the contents of a file or commit message in a PatchSet or change * Get the contents of a file or commit message in a PatchSet or change
* edit. * edit.
**/ **/
public static void getContentOrMessage(PatchSet.Id id, String path, public static void getContentOrMessage(PatchSet.Id id, String path,
AsyncCallback<String> cb) { AsyncCallback<String> cb) {
if (Patch.COMMIT_MSG.equals(path)) { RestApi api = (Patch.COMMIT_MSG.equals(path) && id.get() == 0)
getMessage(id, cb); ? messageEdit(id)
} else { : contentEditOrPs(id, path);
contentEditOrPs(id, path).get(wrapper(cb)); api.get(wrapper(cb));
}
} }
/** Put contents into a File in a change edit. */ /** Put contents into a File in a change edit. */
@@ -145,6 +138,10 @@ public class ChangeFileApi {
: ChangeApi.revision(id).view("files").id(filename).view("content"); : ChangeApi.revision(id).view("files").id(filename).view("content");
} }
private static RestApi messageEdit(PatchSet.Id id) {
return ChangeApi.change(id.getParentKey().get()).view("edit:message");
}
private static RestApi contentTypeEditOrPs(PatchSet.Id id, String filename) { private static RestApi contentTypeEditOrPs(PatchSet.Id id, String filename) {
return id.get() == 0 return id.get() == 0
? contentEdit(id.getParentKey(), filename).view("type") ? contentEdit(id.getParentKey(), filename).view("type")

View File

@@ -39,7 +39,6 @@ import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.edit.ChangeEdit; import com.google.gerrit.server.edit.ChangeEdit;
import com.google.gerrit.server.edit.ChangeEditJson; import com.google.gerrit.server.edit.ChangeEditJson;
import com.google.gerrit.server.edit.ChangeEditModifier; import com.google.gerrit.server.edit.ChangeEditModifier;
@@ -47,7 +46,6 @@ import com.google.gerrit.server.edit.ChangeEditUtil;
import com.google.gerrit.server.edit.UnchangedCommitMessageException; import com.google.gerrit.server.edit.UnchangedCommitMessageException;
import com.google.gerrit.server.patch.PatchListNotAvailableException; import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.project.InvalidChangeOperationException; import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
@@ -492,28 +490,22 @@ public class ChangeEdits implements
@Singleton @Singleton
public static class GetMessage implements RestReadView<ChangeResource> { public static class GetMessage implements RestReadView<ChangeResource> {
private final ChangeUtil changeUtil;
private final ChangeEditUtil editUtil; private final ChangeEditUtil editUtil;
@Inject @Inject
GetMessage(ChangeUtil changeUtil, GetMessage(ChangeEditUtil editUtil) {
ChangeEditUtil editUtil) {
this.changeUtil = changeUtil;
this.editUtil = editUtil; this.editUtil = editUtil;
} }
@Override @Override
public BinaryResult apply(ChangeResource rsrc) throws AuthException, IOException, public BinaryResult apply(ChangeResource rsrc) throws AuthException,
OrmException, NoSuchChangeException { IOException, ResourceNotFoundException {
Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getChange()); Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getChange());
// TODO(davido): Clean this up by returning 404 when edit doesn't exist. if (edit.isPresent()) {
// Client should call GET /changes/{id}/revisions/current/commit in this return BinaryResult.create(
// case; or, to be consistent with GET content logic, the client could edit.get().getEditCommit().getFullMessage()).base64();
// call directly the right endpoint. }
String m = edit.isPresent() throw new ResourceNotFoundException();
? edit.get().getEditCommit().getFullMessage()
: changeUtil.getMessage(rsrc.getChange());
return BinaryResult.create(m).base64();
} }
} }