Add the comment context to the ListChangeComments RestReadView

Comment context lines are returned from the comments API if the
parameter "enable-context" is set. Each CommentInfo will include an
additional contextLines field, which is a list of {line_number,
line_text}, which are some lines of the source file where the comment
was written.

In this change, the context lines are exactly the lines highlighted by
the user when the comment was written. In a later change, the
"enable-context" parameter will be changed to an integer parameter. The
caller will decide how many lines to retrieve.

Change-Id: I76928de54818fa63b5b49b8e89244c5289361af4
This commit is contained in:
Youssef Elghareeb
2020-07-10 19:14:57 +02:00
parent 4a59255147
commit 5c4fffb18e
11 changed files with 505 additions and 33 deletions

View File

@@ -158,7 +158,7 @@ class ChangeApiImpl implements ChangeApi {
private final GetAssignee getAssignee;
private final GetPastAssignees getPastAssignees;
private final DeleteAssignee deleteAssignee;
private final ListChangeComments listComments;
private final Provider<ListChangeComments> listCommentsProvider;
private final ListChangeRobotComments listChangeRobotComments;
private final ListChangeDrafts listDrafts;
private final ChangeEditApiImpl.Factory changeEditApi;
@@ -211,7 +211,7 @@ class ChangeApiImpl implements ChangeApi {
GetAssignee getAssignee,
GetPastAssignees getPastAssignees,
DeleteAssignee deleteAssignee,
ListChangeComments listComments,
Provider<ListChangeComments> listCommentsProvider,
ListChangeRobotComments listChangeRobotComments,
ListChangeDrafts listDrafts,
ChangeEditApiImpl.Factory changeEditApi,
@@ -262,7 +262,7 @@ class ChangeApiImpl implements ChangeApi {
this.getAssignee = getAssignee;
this.getPastAssignees = getPastAssignees;
this.deleteAssignee = deleteAssignee;
this.listComments = listComments;
this.listCommentsProvider = listCommentsProvider;
this.listChangeRobotComments = listChangeRobotComments;
this.listDrafts = listDrafts;
this.changeEditApi = changeEditApi;
@@ -599,21 +599,30 @@ class ChangeApiImpl implements ChangeApi {
}
@Override
public Map<String, List<CommentInfo>> comments() throws RestApiException {
try {
return listComments.apply(change).value();
} catch (Exception e) {
throw asRestApiException("Cannot get comments", e);
}
}
public CommentsRequest commentsRequest() throws RestApiException {
return new CommentsRequest() {
@Override
public Map<String, List<CommentInfo>> get() throws RestApiException {
try {
ListChangeComments listComments = listCommentsProvider.get();
listComments.setContext(this.getContext());
return listComments.apply(change).value();
} catch (Exception e) {
throw asRestApiException("Cannot get comments", e);
}
}
@Override
public List<CommentInfo> commentsAsList() throws RestApiException {
try {
return listComments.getComments(change);
} catch (Exception e) {
throw asRestApiException("Cannot get comments", e);
}
@Override
public List<CommentInfo> getAsList() throws RestApiException {
try {
ListChangeComments listComments = listCommentsProvider.get();
listComments.setContext(this.getContext());
return listComments.getComments(change);
} catch (Exception e) {
throw asRestApiException("Cannot get comments", e);
}
}
};
}
@Override