InlineEdit: Allow to list files in change edit
Add --list and --base option to GET edit REST endpoint to list files in change edit: GET /changes/<id>/edit?list Change-Id: Idfb6278c67750c09b41653dda050b560d05695f8
This commit is contained in:
@@ -37,11 +37,13 @@ import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
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.edit.ChangeEdit;
|
||||
import com.google.gerrit.server.edit.ChangeEditJson;
|
||||
import com.google.gerrit.server.edit.ChangeEditModifier;
|
||||
import com.google.gerrit.server.edit.ChangeEditUtil;
|
||||
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;
|
||||
@@ -50,6 +52,8 @@ import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
import org.kohsuke.args4j.Option;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Singleton
|
||||
@@ -61,14 +65,14 @@ public class ChangeEdits implements
|
||||
private final DynamicMap<RestView<ChangeEditResource>> views;
|
||||
private final Create.Factory createFactory;
|
||||
private final DeleteEdit.Factory deleteEditFactory;
|
||||
private final Detail detail;
|
||||
private final Provider<Detail> detail;
|
||||
private final ChangeEditUtil editUtil;
|
||||
private final Post post;
|
||||
|
||||
@Inject
|
||||
ChangeEdits(DynamicMap<RestView<ChangeEditResource>> views,
|
||||
Create.Factory createFactory,
|
||||
Detail detail,
|
||||
Provider<Detail> detail,
|
||||
ChangeEditUtil editUtil,
|
||||
Post post,
|
||||
DeleteEdit.Factory deleteEditFactory) {
|
||||
@@ -87,7 +91,7 @@ public class ChangeEdits implements
|
||||
|
||||
@Override
|
||||
public RestView<ChangeResource> list() {
|
||||
return detail;
|
||||
return detail.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -236,27 +240,57 @@ public class ChangeEdits implements
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
static class Detail implements RestReadView<ChangeResource> {
|
||||
private final ChangeEditUtil editUtil;
|
||||
private final ChangeEditJson editJson;
|
||||
private final FileInfoJson fileInfoJson;
|
||||
private final Revisions revisions;
|
||||
|
||||
@Option(name = "--base", metaVar = "revision-id")
|
||||
String base;
|
||||
|
||||
@Option(name = "--list", metaVar = "LIST")
|
||||
boolean list;
|
||||
|
||||
@Inject
|
||||
Detail(ChangeEditJson editJson,
|
||||
ChangeEditUtil editUtil) {
|
||||
Detail(ChangeEditUtil editUtil,
|
||||
ChangeEditJson editJson,
|
||||
FileInfoJson fileInfoJson,
|
||||
Revisions revisions) {
|
||||
this.editJson = editJson;
|
||||
this.editUtil = editUtil;
|
||||
this.fileInfoJson = fileInfoJson;
|
||||
this.revisions = revisions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<EditInfo> apply(ChangeResource rsrc) throws AuthException,
|
||||
IOException, NoSuchChangeException, InvalidChangeOperationException,
|
||||
ResourceNotFoundException {
|
||||
IOException, InvalidChangeOperationException,
|
||||
ResourceNotFoundException, OrmException {
|
||||
Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getChange());
|
||||
if (edit.isPresent()) {
|
||||
return Response.ok(editJson.toEditInfo(edit.get()));
|
||||
if (!edit.isPresent()) {
|
||||
return Response.none();
|
||||
}
|
||||
return Response.none();
|
||||
|
||||
EditInfo editInfo = editJson.toEditInfo(edit.get());
|
||||
if (list) {
|
||||
PatchSet basePatchSet = null;
|
||||
if (base != null) {
|
||||
RevisionResource baseResource = revisions.parse(
|
||||
rsrc, IdString.fromDecoded(base));
|
||||
basePatchSet = baseResource.getPatchSet();
|
||||
}
|
||||
try {
|
||||
editInfo.files =
|
||||
fileInfoJson.toFileInfoMap(
|
||||
rsrc.getChange(),
|
||||
edit.get().getRevision(),
|
||||
basePatchSet);
|
||||
} catch (PatchListNotAvailableException e) {
|
||||
throw new ResourceNotFoundException(e.getMessage());
|
||||
}
|
||||
}
|
||||
return Response.ok(editInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.RevId;
|
||||
import com.google.gerrit.server.patch.PatchList;
|
||||
import com.google.gerrit.server.patch.PatchListCache;
|
||||
import com.google.gerrit.server.patch.PatchListEntry;
|
||||
@@ -44,15 +45,15 @@ public class FileInfoJson {
|
||||
|
||||
Map<String, FileInfo> toFileInfoMap(Change change, PatchSet patchSet)
|
||||
throws PatchListNotAvailableException {
|
||||
return toFileInfoMap(change, patchSet, null);
|
||||
return toFileInfoMap(change, patchSet.getRevision(), null);
|
||||
}
|
||||
|
||||
Map<String, FileInfo> toFileInfoMap(Change change, PatchSet patchSet, @Nullable PatchSet base)
|
||||
Map<String, FileInfo> toFileInfoMap(Change change, RevId revision, @Nullable PatchSet base)
|
||||
throws PatchListNotAvailableException {
|
||||
ObjectId a = (base == null)
|
||||
? null
|
||||
: ObjectId.fromString(base.getRevision().get());
|
||||
ObjectId b = ObjectId.fromString(patchSet.getRevision().get());
|
||||
ObjectId b = ObjectId.fromString(revision.get());
|
||||
PatchList list = patchListCache.get(
|
||||
new PatchListKey(change.getProject(), a, b, Whitespace.IGNORE_NONE));
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
|
||||
try {
|
||||
Response<Map<String, FileInfo>> r = Response.ok(fileInfoJson.toFileInfoMap(
|
||||
resource.getChange(),
|
||||
resource.getPatchSet(),
|
||||
resource.getPatchSet().getRevision(),
|
||||
basePatchSet));
|
||||
if (resource.isCacheable()) {
|
||||
r.caching(CacheControl.PRIVATE(7, TimeUnit.DAYS));
|
||||
|
||||
Reference in New Issue
Block a user