Merge "Add a REST API endpoint to support retrieve the robot comment list of a change."
This commit is contained in:
commit
80f054f8b8
@ -1895,6 +1895,62 @@ the `patch_set` and `author` fields set.
|
||||
}
|
||||
----
|
||||
|
||||
[[list-change-robot-comments]]
|
||||
=== List Change Robot Comments
|
||||
--
|
||||
'GET /changes/link:#change-id[\{change-id\}]/robotcomments'
|
||||
--
|
||||
|
||||
Lists the robot comments of all revisions of the change.
|
||||
|
||||
Return a map that maps the file path to a list of
|
||||
link:#robot-comment-info[RobotCommentInfo] entries. The entries in the
|
||||
map are sorted by file path.
|
||||
|
||||
.Request
|
||||
----
|
||||
GET /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/robotcomments/ HTTP/1.0
|
||||
----
|
||||
|
||||
.Response
|
||||
----
|
||||
HTTP/1.1 200 OK
|
||||
Content-Disposition: attachment
|
||||
Content-Type: application/json; charset=UTF-8
|
||||
|
||||
)]}'
|
||||
{
|
||||
"gerrit-server/src/main/java/com/google/gerrit/server/project/RefControl.java": [
|
||||
{
|
||||
"id": "TvcXrmjM",
|
||||
"line": 23,
|
||||
"message": "unused import",
|
||||
"updated": "2016-02-26 15:40:43.986000000",
|
||||
"author": {
|
||||
"_account_id": 1000110,
|
||||
"name": "Code Analyzer",
|
||||
"email": "code.analyzer@example.com"
|
||||
},
|
||||
"robotId": "importChecker",
|
||||
"robotRunId": "76b1375aa8626ea7149792831fe2ed85e80d9e04"
|
||||
},
|
||||
{
|
||||
"id": "TveXwFiA",
|
||||
"line": 49,
|
||||
"message": "wrong indention",
|
||||
"updated": "2016-02-26 15:40:45.328000000",
|
||||
"author": {
|
||||
"_account_id": 1000110,
|
||||
"name": "Code Analyzer",
|
||||
"email": "code.analyzer@example.com"
|
||||
},
|
||||
"robotId": "styleChecker",
|
||||
"robotRunId": "5c606c425dd45184484f9d0a2ffd725a7607839b"
|
||||
}
|
||||
]
|
||||
}
|
||||
----
|
||||
|
||||
[[list-change-drafts]]
|
||||
=== List Change Drafts
|
||||
--
|
||||
|
@ -88,6 +88,31 @@ public class RobotCommentsIT extends AbstractDaemonTest {
|
||||
assertRobotComment(comment, in, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addedRobotCommentsCanBeRetrievedByChange() throws Exception {
|
||||
assume().that(notesMigration.enabled()).isTrue();
|
||||
|
||||
RobotCommentInput in = createRobotCommentInput();
|
||||
addRobotComment(changeId, in);
|
||||
|
||||
pushFactory.create(db, admin.getIdent(), testRepo, changeId)
|
||||
.to("refs/for/master");
|
||||
|
||||
RobotCommentInput in2 = createRobotCommentInput();
|
||||
addRobotComment(changeId, in2);
|
||||
|
||||
Map<String, List<RobotCommentInfo>> out =
|
||||
gApi.changes().id(changeId).robotComments();
|
||||
|
||||
assertThat(out).hasSize(1);
|
||||
assertThat(out.get(in.path)).hasSize(2);
|
||||
|
||||
RobotCommentInfo comment1 = out.get(in.path).get(0);
|
||||
assertRobotComment(comment1, in, false);
|
||||
RobotCommentInfo comment2 = out.get(in.path).get(1);
|
||||
assertRobotComment(comment2, in2, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void robotCommentsCanBeRetrievedAsList() throws Exception {
|
||||
assume().that(notesMigration.enabled()).isTrue();
|
||||
|
@ -20,6 +20,7 @@ import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.common.EditInfo;
|
||||
import com.google.gerrit.extensions.common.MergePatchSetInput;
|
||||
import com.google.gerrit.extensions.common.RobotCommentInfo;
|
||||
import com.google.gerrit.extensions.common.SuggestedReviewerInfo;
|
||||
import com.google.gerrit.extensions.restapi.NotImplementedException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
@ -177,6 +178,16 @@ public interface ChangeApi {
|
||||
*/
|
||||
Map<String, List<CommentInfo>> comments() throws RestApiException;
|
||||
|
||||
/**
|
||||
* Get all robot comments on a change.
|
||||
*
|
||||
* @return robot comments in a map keyed by path; robot comments have the
|
||||
* {@code revision} field set to indicate their patch set.
|
||||
*
|
||||
* @throws RestApiException
|
||||
*/
|
||||
Map<String, List<RobotCommentInfo>> robotComments() throws RestApiException;
|
||||
|
||||
/**
|
||||
* Get all draft comments for the current user on a change.
|
||||
*
|
||||
@ -381,6 +392,12 @@ public interface ChangeApi {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<RobotCommentInfo>> robotComments()
|
||||
throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> drafts() throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
|
@ -34,6 +34,7 @@ import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.common.EditInfo;
|
||||
import com.google.gerrit.extensions.common.MergePatchSetInput;
|
||||
import com.google.gerrit.extensions.common.RobotCommentInfo;
|
||||
import com.google.gerrit.extensions.common.SuggestedReviewerInfo;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
@ -53,6 +54,7 @@ import com.google.gerrit.server.change.GetTopic;
|
||||
import com.google.gerrit.server.change.Index;
|
||||
import com.google.gerrit.server.change.ListChangeComments;
|
||||
import com.google.gerrit.server.change.ListChangeDrafts;
|
||||
import com.google.gerrit.server.change.ListChangeRobotComments;
|
||||
import com.google.gerrit.server.change.Move;
|
||||
import com.google.gerrit.server.change.PostHashtags;
|
||||
import com.google.gerrit.server.change.PostReviewers;
|
||||
@ -109,6 +111,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
private final GetPastAssignees getPastAssignees;
|
||||
private final DeleteAssignee deleteAssignee;
|
||||
private final ListChangeComments listComments;
|
||||
private final ListChangeRobotComments listChangeRobotComments;
|
||||
private final ListChangeDrafts listDrafts;
|
||||
private final Check check;
|
||||
private final Index index;
|
||||
@ -140,6 +143,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
GetPastAssignees getPastAssignees,
|
||||
DeleteAssignee deleteAssignee,
|
||||
ListChangeComments listComments,
|
||||
ListChangeRobotComments listChangeRobotComments,
|
||||
ListChangeDrafts listDrafts,
|
||||
Check check,
|
||||
Index index,
|
||||
@ -170,6 +174,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
this.getPastAssignees = getPastAssignees;
|
||||
this.deleteAssignee = deleteAssignee;
|
||||
this.listComments = listComments;
|
||||
this.listChangeRobotComments = listChangeRobotComments;
|
||||
this.listDrafts = listDrafts;
|
||||
this.check = check;
|
||||
this.index = index;
|
||||
@ -483,6 +488,16 @@ class ChangeApiImpl implements ChangeApi {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<RobotCommentInfo>> robotComments()
|
||||
throws RestApiException {
|
||||
try {
|
||||
return listChangeRobotComments.apply(change);
|
||||
} catch (OrmException e) {
|
||||
throw new RestApiException("Cannot get robot comments", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<CommentInfo>> drafts() throws RestApiException {
|
||||
try {
|
||||
|
@ -0,0 +1,58 @@
|
||||
// Copyright (C) 2016 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.change;
|
||||
|
||||
import com.google.gerrit.extensions.common.RobotCommentInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CommentsUtil;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ListChangeRobotComments implements RestReadView<ChangeResource> {
|
||||
private final Provider<ReviewDb> db;
|
||||
private final ChangeData.Factory changeDataFactory;
|
||||
private final Provider<CommentJson> commentJson;
|
||||
private final CommentsUtil commentsUtil;
|
||||
|
||||
@Inject
|
||||
ListChangeRobotComments(Provider<ReviewDb> db,
|
||||
ChangeData.Factory changeDataFactory,
|
||||
Provider<CommentJson> commentJson,
|
||||
CommentsUtil commentsUtil) {
|
||||
this.db = db;
|
||||
this.changeDataFactory = changeDataFactory;
|
||||
this.commentJson = commentJson;
|
||||
this.commentsUtil = commentsUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<RobotCommentInfo>> apply(
|
||||
ChangeResource rsrc) throws AuthException, OrmException {
|
||||
ChangeData cd = changeDataFactory.create(db.get(), rsrc.getControl());
|
||||
return commentJson.get()
|
||||
.setFillAccounts(true)
|
||||
.setFillPatchSet(true)
|
||||
.newRobotCommentFormatter()
|
||||
.format(commentsUtil.robotCommentsByChange(cd.notes()));
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ public class Module extends RestApiModule {
|
||||
delete(CHANGE_KIND, "assignee").to(DeleteAssignee.class);
|
||||
get(CHANGE_KIND, "hashtags").to(GetHashtags.class);
|
||||
get(CHANGE_KIND, "comments").to(ListChangeComments.class);
|
||||
get(CHANGE_KIND, "robotcomments").to(ListChangeRobotComments.class);
|
||||
get(CHANGE_KIND, "drafts").to(ListChangeDrafts.class);
|
||||
get(CHANGE_KIND, "check").to(Check.class);
|
||||
post(CHANGE_KIND, "check").to(Check.class);
|
||||
|
Loading…
x
Reference in New Issue
Block a user