Provide ported draft comments via a separate REST endpoint
All other REST endpoints for comments have a clear separation between published comments and draft comments. We follow the same approach for ported comments and hence introduce a dedicated REST endpoint for ported draft comments. The existing tests for ported comments also cover most code paths for ported draft comments as a large amount of the code is shared. We only add additional tests for varying aspects or those which are outside of the shared code. Change-Id: If8802a4f94540284cc1303b278f7f38d120593eb
This commit is contained in:
@@ -108,6 +108,8 @@ public interface RevisionApi {
|
||||
|
||||
Map<String, List<CommentInfo>> portedComments() throws RestApiException;
|
||||
|
||||
Map<String, List<CommentInfo>> portedDrafts() throws RestApiException;
|
||||
|
||||
/**
|
||||
* Applies the indicated fix by creating a new change edit or integrating the fix with the
|
||||
* existing change edit. If no change edit exists before this call, the fix must refer to the
|
||||
@@ -300,6 +302,11 @@ public interface RevisionApi {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> portedDrafts() throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditInfo applyFix(String fixId) throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
|
||||
@@ -80,6 +80,7 @@ import com.google.gerrit.server.restapi.change.GetPatch;
|
||||
import com.google.gerrit.server.restapi.change.GetRelated;
|
||||
import com.google.gerrit.server.restapi.change.GetRevisionActions;
|
||||
import com.google.gerrit.server.restapi.change.ListPortedComments;
|
||||
import com.google.gerrit.server.restapi.change.ListPortedDrafts;
|
||||
import com.google.gerrit.server.restapi.change.ListRevisionComments;
|
||||
import com.google.gerrit.server.restapi.change.ListRevisionDrafts;
|
||||
import com.google.gerrit.server.restapi.change.ListRobotComments;
|
||||
@@ -132,6 +133,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
private final ListRevisionComments listComments;
|
||||
private final ListRobotComments listRobotComments;
|
||||
private final ListPortedComments listPortedComments;
|
||||
private final ListPortedDrafts listPortedDrafts;
|
||||
private final ApplyFix applyFix;
|
||||
private final GetFixPreview getFixPreview;
|
||||
private final Fixes fixes;
|
||||
@@ -178,6 +180,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
ListRevisionComments listComments,
|
||||
ListRobotComments listRobotComments,
|
||||
ListPortedComments listPortedComments,
|
||||
ListPortedDrafts listPortedDrafts,
|
||||
ApplyFix applyFix,
|
||||
GetFixPreview getFixPreview,
|
||||
Fixes fixes,
|
||||
@@ -223,6 +226,7 @@ class RevisionApiImpl implements RevisionApi {
|
||||
this.robotComments = robotComments;
|
||||
this.listRobotComments = listRobotComments;
|
||||
this.listPortedComments = listPortedComments;
|
||||
this.listPortedDrafts = listPortedDrafts;
|
||||
this.applyFix = applyFix;
|
||||
this.getFixPreview = getFixPreview;
|
||||
this.fixes = fixes;
|
||||
@@ -466,6 +470,15 @@ class RevisionApiImpl implements RevisionApi {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> portedDrafts() throws RestApiException {
|
||||
try {
|
||||
return listPortedDrafts.apply(revision).value();
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot retrieve ported draft comments", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditInfo applyFix(String fixId) throws RestApiException {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
// Copyright (C) 2020 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.restapi.change;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.entities.HumanComment;
|
||||
import com.google.gerrit.entities.PatchSet;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.CommentsUtil;
|
||||
import com.google.gerrit.server.change.RevisionResource;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Singleton
|
||||
public class ListPortedDrafts implements RestReadView<RevisionResource> {
|
||||
|
||||
private final CommentsUtil commentsUtil;
|
||||
private final CommentPorter commentPorter;
|
||||
private final Provider<CommentJson> commentJson;
|
||||
|
||||
@Inject
|
||||
public ListPortedDrafts(
|
||||
Provider<CommentJson> commentJson, CommentsUtil commentsUtil, CommentPorter commentPorter) {
|
||||
this.commentJson = commentJson;
|
||||
this.commentsUtil = commentsUtil;
|
||||
this.commentPorter = commentPorter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Map<String, List<CommentInfo>>> apply(RevisionResource revisionResource)
|
||||
throws PermissionBackendException, PatchListNotAvailableException {
|
||||
PatchSet targetPatchset = revisionResource.getPatchSet();
|
||||
|
||||
List<HumanComment> draftComments =
|
||||
commentsUtil.draftByChangeAuthor(
|
||||
revisionResource.getNotes(), revisionResource.getAccountId());
|
||||
ImmutableList<HumanComment> portedDraftComments =
|
||||
commentPorter.portComments(revisionResource.getNotes(), targetPatchset, draftComments);
|
||||
return Response.ok(format(portedDraftComments));
|
||||
}
|
||||
|
||||
private Map<String, List<CommentInfo>> format(List<HumanComment> comments)
|
||||
throws PermissionBackendException {
|
||||
return commentJson
|
||||
.get()
|
||||
// Always unset for draft comments as only draft comments of the requesting user are
|
||||
// returned.
|
||||
.setFillAccounts(false)
|
||||
.setFillPatchSet(true)
|
||||
.newHumanCommentFormatter()
|
||||
.format(comments);
|
||||
}
|
||||
}
|
||||
@@ -173,6 +173,7 @@ public class Module extends RestApiModule {
|
||||
get(FIX_KIND, "preview").to(GetFixPreview.class);
|
||||
|
||||
get(REVISION_KIND, "ported_comments").to(ListPortedComments.class);
|
||||
get(REVISION_KIND, "ported_drafts").to(ListPortedDrafts.class);
|
||||
|
||||
child(REVISION_KIND, "files").to(Files.class);
|
||||
put(FILE_KIND, "reviewed").to(PutReviewed.class);
|
||||
|
||||
Reference in New Issue
Block a user