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
--
Retrieves commit message from change edit or from current patch set when
change edit doesn't exist.
Retrieves commit message from change edit.
.Request
----

View File

@@ -275,11 +275,19 @@ public class ChangeEditIT extends AbstractDaemonTest {
@Test
public void updateMessageRest() throws Exception {
assertThat(adminSession.get(urlEditMessage()).getStatusCode())
.isEqualTo(SC_NOT_FOUND);
EditMessage.Input in = new EditMessage.Input();
in.message = String.format("New commit message\n\nChange-Id: %s",
change.getKey());
assertThat(adminSession.put(urlEditMessage(), in).getStatusCode())
.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);
assertThat(edit.get().getEditCommit().getFullMessage())
.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
* edit.
**/
public static void getContentOrMessage(PatchSet.Id id, String path,
AsyncCallback<String> cb) {
if (Patch.COMMIT_MSG.equals(path)) {
getMessage(id, cb);
} else {
contentEditOrPs(id, path).get(wrapper(cb));
}
RestApi api = (Patch.COMMIT_MSG.equals(path) && id.get() == 0)
? messageEdit(id)
: contentEditOrPs(id, path);
api.get(wrapper(cb));
}
/** 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");
}
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) {
return id.get() == 0
? 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.PatchSet;
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.ChangeEditJson;
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.patch.PatchListNotAvailableException;
import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -492,28 +490,22 @@ public class ChangeEdits implements
@Singleton
public static class GetMessage implements RestReadView<ChangeResource> {
private final ChangeUtil changeUtil;
private final ChangeEditUtil editUtil;
@Inject
GetMessage(ChangeUtil changeUtil,
ChangeEditUtil editUtil) {
this.changeUtil = changeUtil;
GetMessage(ChangeEditUtil editUtil) {
this.editUtil = editUtil;
}
@Override
public BinaryResult apply(ChangeResource rsrc) throws AuthException, IOException,
OrmException, NoSuchChangeException {
public BinaryResult apply(ChangeResource rsrc) throws AuthException,
IOException, ResourceNotFoundException {
Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getChange());
// TODO(davido): Clean this up by returning 404 when edit doesn't exist.
// Client should call GET /changes/{id}/revisions/current/commit in this
// case; or, to be consistent with GET content logic, the client could
// call directly the right endpoint.
String m = edit.isPresent()
? edit.get().getEditCommit().getFullMessage()
: changeUtil.getMessage(rsrc.getChange());
return BinaryResult.create(m).base64();
if (edit.isPresent()) {
return BinaryResult.create(
edit.get().getEditCommit().getFullMessage()).base64();
}
throw new ResourceNotFoundException();
}
}