diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/AbstractDaemonTest.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/AbstractDaemonTest.java index 6118b2b77b..3e31aa64e6 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/AbstractDaemonTest.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/AbstractDaemonTest.java @@ -55,7 +55,6 @@ import com.google.gerrit.server.query.change.InternalChangeQuery; import com.google.gerrit.testutil.ConfigSuite; import com.google.gerrit.testutil.TempFileUtil; import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import com.google.gwtorm.server.SchemaFactory; import com.google.inject.Inject; import com.google.inject.Provider; @@ -455,11 +454,10 @@ public abstract class AbstractDaemonTest { .review(ReviewInput.approve()); } - protected Map getActions(String changeId) throws Exception { - return newGson().fromJson( - adminSession.get("/changes/" - + changeId - + "/revisions/1/actions").getReader(), - new TypeToken>() {}.getType()); + protected Map getActions(String id) throws Exception { + return gApi.changes() + .id(id) + .revision(1) + .actions(); } } diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/RevisionApi.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/RevisionApi.java index b940cc9963..3e7a207b6f 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/RevisionApi.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/RevisionApi.java @@ -14,6 +14,7 @@ package com.google.gerrit.extensions.api.changes; +import com.google.gerrit.extensions.common.ActionInfo; import com.google.gerrit.extensions.common.CommentInfo; import com.google.gerrit.extensions.common.FileInfo; import com.google.gerrit.extensions.common.MergeableInfo; @@ -54,6 +55,8 @@ public interface RevisionApi { CommentApi comment(String id) throws RestApiException; + Map actions() throws RestApiException; + /** * A default implementation which allows source compatibility * when adding new methods to the interface. @@ -163,5 +166,10 @@ public interface RevisionApi { public CommentApi comment(String id) throws RestApiException { throw new NotImplementedException(); } + + @Override + public Map actions() throws RestApiException { + throw new NotImplementedException(); + } } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/RevisionApiImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/RevisionApiImpl.java index e4dc0cd941..63d09028a2 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/RevisionApiImpl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/RevisionApiImpl.java @@ -27,6 +27,7 @@ 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.changes.SubmitInput; +import com.google.gerrit.extensions.common.ActionInfo; import com.google.gerrit.extensions.common.CommentInfo; import com.google.gerrit.extensions.common.FileInfo; import com.google.gerrit.extensions.common.MergeableInfo; @@ -40,6 +41,7 @@ import com.google.gerrit.server.change.DeleteDraftPatchSet; import com.google.gerrit.server.change.DraftComments; import com.google.gerrit.server.change.FileResource; import com.google.gerrit.server.change.Files; +import com.google.gerrit.server.change.GetRevisionActions; import com.google.gerrit.server.change.ListComments; import com.google.gerrit.server.change.ListDraftComments; import com.google.gerrit.server.change.Mergeable; @@ -87,6 +89,7 @@ class RevisionApiImpl implements RevisionApi { private final DraftApiImpl.Factory draftFactory; private final Comments comments; private final CommentApiImpl.Factory commentFactory; + private final GetRevisionActions revisionActions; @Inject RevisionApiImpl(Changes changes, @@ -110,6 +113,7 @@ class RevisionApiImpl implements RevisionApi { DraftApiImpl.Factory draftFactory, Comments comments, CommentApiImpl.Factory commentFactory, + GetRevisionActions revisionActions, @Assisted RevisionResource r) { this.changes = changes; this.cherryPick = cherryPick; @@ -132,6 +136,7 @@ class RevisionApiImpl implements RevisionApi { this.draftFactory = draftFactory; this.comments = comments; this.commentFactory = commentFactory; + this.revisionActions = revisionActions; this.revision = r; } @@ -329,4 +334,9 @@ class RevisionApiImpl implements RevisionApi { throw new RestApiException("Cannot retrieve comment", e); } } + + @Override + public Map actions() throws RestApiException { + return revisionActions.apply(revision).value(); + } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/GetRevisionActions.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/GetRevisionActions.java index b21bee227b..cd57a3ef75 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/GetRevisionActions.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/GetRevisionActions.java @@ -17,6 +17,7 @@ package com.google.gerrit.server.change; import com.google.common.base.Strings; import com.google.common.hash.Hasher; import com.google.common.hash.Hashing; +import com.google.gerrit.extensions.common.ActionInfo; import com.google.gerrit.extensions.restapi.ETagView; import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.server.CurrentUser; @@ -31,6 +32,8 @@ import com.google.inject.Singleton; import org.eclipse.jgit.lib.Config; +import java.util.Map; + @Singleton public class GetRevisionActions implements ETagView { private final ActionJson delegate; @@ -47,7 +50,7 @@ public class GetRevisionActions implements ETagView { } @Override - public Object apply(RevisionResource rsrc) { + public Response> apply(RevisionResource rsrc) { return Response.withMustRevalidate(delegate.format(rsrc)); }