use of com.google.gerrit.entities.Patch.PATCHSET_LEVEL in project gerrit by GerritCodeReview.
the class CommentSender method getGroupedInlineComments.
/**
* Returns a list of FileCommentGroup objects representing the inline comments grouped by the
* file.
*/
private List<CommentSender.FileCommentGroup> getGroupedInlineComments(Repository repo) {
List<CommentSender.FileCommentGroup> groups = new ArrayList<>();
// Loop over the comments and collect them into groups based on the file
// location of the comment.
FileCommentGroup currentGroup = null;
for (Comment c : inlineComments) {
// If it's a new group:
if (currentGroup == null || !c.key.filename.equals(currentGroup.filename) || c.key.patchSetId != currentGroup.patchSetId) {
currentGroup = new FileCommentGroup();
currentGroup.filename = c.key.filename;
currentGroup.patchSetId = c.key.patchSetId;
// Get the modified files:
Map<String, FileDiffOutput> modifiedFiles = null;
try {
modifiedFiles = listModifiedFiles(c.key.patchSetId);
} catch (DiffNotAvailableException e) {
logger.atSevere().withCause(e).log("Failed to get modified files");
}
groups.add(currentGroup);
if (modifiedFiles != null && !modifiedFiles.isEmpty()) {
try {
currentGroup.fileData = new PatchFile(repo, modifiedFiles, c.key.filename);
} catch (IOException e) {
logger.atWarning().withCause(e).log("Cannot load %s from %s in %s", c.key.filename, modifiedFiles.values().iterator().next().newCommitId().name(), projectState.getName());
currentGroup.fileData = null;
}
}
}
if (currentGroup.filename.equals(PATCHSET_LEVEL) || currentGroup.fileData != null) {
currentGroup.comments.add(c);
}
}
groups.sort(Comparator.comparing(g -> g.filename, FilenameComparator.INSTANCE));
return groups;
}
Aggregations