Accept /changes/*/revisions/current to mean current patch set
This makes it easier for REST API clients to access the current revision of a change if they don't care about a specific one but do need to select a specific revision in order to use a view. Change-Id: If8ab835d70bd552d83d833fd2790455489c52352
This commit is contained in:
@@ -55,11 +55,18 @@ class Revisions implements ChildCollection<ChangeResource, RevisionResource> {
|
||||
@Override
|
||||
public RevisionResource parse(ChangeResource change, IdString id)
|
||||
throws ResourceNotFoundException, OrmException {
|
||||
if (id.equals("current")) {
|
||||
PatchSet.Id p = change.getChange().currentPatchSetId();
|
||||
PatchSet ps = p != null ? dbProvider.get().patchSets().get(p) : null;
|
||||
if (ps != null && visible(change, ps)) {
|
||||
return new RevisionResource(change, ps);
|
||||
}
|
||||
throw new ResourceNotFoundException(id);
|
||||
}
|
||||
List<PatchSet> match = Lists.newArrayListWithExpectedSize(2);
|
||||
for (PatchSet ps : find(change, id.get())) {
|
||||
Change.Id changeId = ps.getId().getParentKey();
|
||||
if (changeId.equals(change.getChange().getId())
|
||||
&& change.getControl().isPatchVisible(ps, dbProvider.get())) {
|
||||
if (changeId.equals(change.getChange().getId()) && visible(change, ps)) {
|
||||
match.add(ps);
|
||||
}
|
||||
}
|
||||
@@ -69,6 +76,11 @@ class Revisions implements ChildCollection<ChangeResource, RevisionResource> {
|
||||
return new RevisionResource(change, match.get(0));
|
||||
}
|
||||
|
||||
private boolean visible(ChangeResource change, PatchSet ps)
|
||||
throws OrmException {
|
||||
return change.getControl().isPatchVisible(ps, dbProvider.get());
|
||||
}
|
||||
|
||||
private List<PatchSet> find(ChangeResource change, String id)
|
||||
throws OrmException {
|
||||
ReviewDb db = dbProvider.get();
|
||||
|
||||
Reference in New Issue
Block a user