use of com.google.startupos.tools.reviewer.local_server.service.Protos.Comment in project startup-os by google.
the class DiffConverter method getReviewCommentsByRepoName.
private ImmutableList<ReviewComment> getReviewCommentsByRepoName(List<Thread> codeThreads, String repoName, ImmutableMap<String, GitRepo> repoNameToGitRepos, long modifiedTimestamp, long diffId) {
ImmutableList.Builder<ReviewComment> result = ImmutableList.builder();
ImmutableList<Thread> codeThreadsByRepo = ImmutableList.copyOf(codeThreads.stream().filter(thread -> thread.getRepoId().equals(repoName)).collect(Collectors.toList()));
for (Thread thread : codeThreadsByRepo) {
for (Comment comment : thread.getCommentList()) {
GitRepo gitRepo = getGitRepo(thread.getFile().getRepoId(), repoNameToGitRepos);
int githubCommentPosition;
String commitId;
boolean isOutsideDiffComment = false;
// `0` value means the comment isn't synced with GitHub
if (thread.getGithubCommentPosition() == 0 && thread.getClosestGithubCommentPosition() == 0) {
String filename = thread.getFile().getFilename();
String baseBranchCommitId = gitRepo.getMostRecentCommitOfBranch("master");
String patch;
if (baseBranchCommitId.equals(thread.getFile().getCommitId())) {
// for the left file
commitId = gitRepo.getMostRecentCommitOfFile(filename);
patch = gitRepo.getPatch(baseBranchCommitId, commitId, filename);
} else {
// for the right file
commitId = thread.getFile().getCommitId();
patch = gitRepo.getPatch(baseBranchCommitId, commitId, filename);
}
LineNumberConverter.LineNumberToGithubPositionCorrelation correlation = getGithubReviewCommentPosition(baseBranchCommitId, thread, patch);
if (correlation.getExactGithubPosition() != 0) {
githubCommentPosition = correlation.getExactGithubPosition();
} else {
githubCommentPosition = correlation.getClosestGithubPosition();
isOutsideDiffComment = true;
}
reviewerClient.addGithubReviewCommentPosition(diffId, thread.getId(), githubCommentPosition, comment.getId());
} else {
if (thread.getGithubCommentPosition() != 0) {
githubCommentPosition = thread.getGithubCommentPosition();
} else {
githubCommentPosition = thread.getClosestGithubCommentPosition();
isOutsideDiffComment = true;
}
commitId = thread.getFile().getCommitId();
}
ReviewComment.Builder githubComment = ReviewComment.newBuilder();
githubComment.setPath(thread.getFile().getFilename()).setId(comment.getGithubCommentId()).setPosition(githubCommentPosition).setCommitId(commitId).setUser(User.newBuilder().setEmail(comment.getCreatedBy()).build()).setBody(comment.getContent()).setCreatedAt(String.valueOf(Instant.ofEpochMilli(comment.getTimestamp()))).setUpdatedAt(String.valueOf(Instant.ofEpochMilli(modifiedTimestamp))).setReviewerThreadId(thread.getId()).setReviewerCommentId(comment.getId()).setIsOutsideDiffComment(isOutsideDiffComment).setReviewerLineNumber(thread.getLineNumber()).build();
result.add(githubComment.build());
}
}
return result.build();
}
Aggregations