use of com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.IssueComment in project startup-os by google.
the class GithubSync method syncWithGithub.
public void syncWithGithub(long diffNumber, ImmutableMap<String, GitRepo> repoNameToGitRepos) throws IOException {
Diff diff = reviewerClient.getDiff(diffNumber);
ImmutableList<PullRequest> reviewerPullRequests = new DiffConverter(reviewerClient).toPullRequests(diff, repoNameToGitRepos);
for (PullRequest reviewerPullRequest : reviewerPullRequests) {
boolean isFirstSync = reviewerPullRequest.getNumber() == 0;
if (isFirstSync) {
long githubPullRequestNumber = createPullRequest(reviewerPullRequest, diffNumber);
for (ReviewComment reviewComment : reviewerPullRequest.getReviewCommentList()) {
createReviewCommentOnGithub(reviewerPullRequest, githubPullRequestNumber, reviewComment, diffNumber);
}
for (IssueComment issueComment : reviewerPullRequest.getIssueCommentList()) {
createIssueCommentOnGithub(reviewerPullRequest, githubPullRequestNumber, issueComment, diffNumber);
}
} else {
PullRequest githubPullRequest = githubReader.getPullRequest(reviewerPullRequest.getOwner(), reviewerPullRequest.getRepo(), reviewerPullRequest.getNumber());
ImmutableList<ReviewCommentCorrelation> reviewCommentCorrelations = getReviewCommentCorrelations(reviewerPullRequest.getReviewCommentList(), githubPullRequest.getReviewCommentList());
syncReviewComments(diffNumber, reviewerPullRequest, githubPullRequest, reviewCommentCorrelations);
ImmutableList<IssueCommentCorrelation> issueCommentCorrelations = getIssueCommentCorrelations(reviewerPullRequest.getIssueCommentList(), githubPullRequest.getIssueCommentList());
syncIssueComments(diffNumber, reviewerPullRequest, githubPullRequest, issueCommentCorrelations);
}
}
}
use of com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.IssueComment in project startup-os by google.
the class DiffConverter method getIssueComments.
private ImmutableList<IssueComment> getIssueComments(List<Thread> diffThreads, String repoName) {
ImmutableList.Builder<IssueComment> result = ImmutableList.builder();
ImmutableList<Thread> diffThreadsByRepo = ImmutableList.copyOf(diffThreads.stream().filter(thread -> thread.getRepoId().equals(repoName)).collect(Collectors.toList()));
for (Thread thread : diffThreadsByRepo) {
thread.getCommentList().forEach(comment -> result.add(IssueComment.newBuilder().setId(comment.getGithubCommentId()).setBody(comment.getContent()).setCreatedAt(Instant.ofEpochMilli(comment.getTimestamp()).toString()).setUser(GithubPullRequestProtos.User.newBuilder().setEmail(comment.getCreatedBy()).build()).setReviewerThreadId(thread.getId()).setReviewerCommentId(comment.getId()).build()));
}
return result.build();
}
use of com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.IssueComment in project startup-os by google.
the class GithubSync method getIssueCommentCorrelations.
private ImmutableList<IssueCommentCorrelation> getIssueCommentCorrelations(List<IssueComment> reviewerIssueComments, List<IssueComment> githubIssueComments) {
List<IssueCommentCorrelation> result = new ArrayList<>();
for (IssueComment reviewerComment : reviewerIssueComments) {
IssueCommentCorrelation issueCommentCorrelation = new IssueCommentCorrelation();
issueCommentCorrelation.reviewerComment = reviewerComment;
issueCommentCorrelation.githubComment = getAssociatedComment(githubIssueComments, reviewerComment);
result.add(issueCommentCorrelation);
}
for (IssueComment githubComment : githubIssueComments) {
int existingCommentCorrelationIndex = -1;
for (IssueCommentCorrelation correlation : result) {
if (correlation.reviewerComment.getId() == githubComment.getId()) {
existingCommentCorrelationIndex = result.indexOf(correlation);
}
}
if (existingCommentCorrelationIndex == -1) {
IssueCommentCorrelation issueCommentCorrelation = new IssueCommentCorrelation();
issueCommentCorrelation.reviewerComment = getAssociatedComment(reviewerIssueComments, githubComment);
issueCommentCorrelation.githubComment = githubComment;
result.add(issueCommentCorrelation);
} else {
result.get(existingCommentCorrelationIndex).githubComment = githubComment;
}
}
return ImmutableList.copyOf(result);
}
use of com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.IssueComment in project startup-os by google.
the class GithubSync method syncIssueComments.
private void syncIssueComments(long diffNumber, PullRequest reviewerPullRequest, PullRequest githubPullRequest, ImmutableList<IssueCommentCorrelation> issueCommentCorrelations) {
for (IssueCommentCorrelation issueCommentCorrelation : issueCommentCorrelations) {
IssueComment githubComment = issueCommentCorrelation.githubComment;
IssueComment reviewerComment = issueCommentCorrelation.reviewerComment;
if (reviewerComment.getCreatedAt().isEmpty() && !githubComment.getCreatedAt().isEmpty()) {
// The comment was deleted by Reviewer
if (isCreatedByReviewerBot(githubComment.getBody())) {
githubWriter.deleteIssueComment(githubPullRequest.getOwner(), githubPullRequest.getRepo(), githubComment.getId());
}
// The comment was created by GitHub
reviewerClient.addDiffComment(diffNumber, githubComment);
continue;
}
if (githubComment.getCreatedAt().isEmpty() && !reviewerComment.getCreatedAt().isEmpty()) {
// The comment was created by Reviewer
if (reviewerComment.getId() == 0) {
createIssueCommentOnGithub(reviewerPullRequest, githubPullRequest.getNumber(), issueCommentCorrelation.reviewerComment, diffNumber);
} else {
// The comment was deleted by GitHub
reviewerClient.deleteThreadComment(diffNumber, reviewerComment.getReviewerThreadId(), reviewerComment.getReviewerCommentId(), reviewerComment.getId());
}
continue;
}
// The comment exists on Reviewer and GitHub
updateExistingIssueComments(githubPullRequest.getOwner(), githubPullRequest.getRepo(), diffNumber, reviewerComment, githubComment);
}
}
use of com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.IssueComment in project startup-os by google.
the class GithubWriter method createIssueComment.
public IssueComment createIssueComment(String repoOwner, String repoName, long pullRequestNumber, IssueComment issueComment, long diffId) {
final String reviewerLink = reviewerUrl + diffId;
IssueComment comment = githubClient.createIssueComment(CreateIssueCommentRequest.newBuilder().setOwner(repoOwner).setRepo(repoName).setNumber(pullRequestNumber).setRequestData(CreateIssueCommentRequest.CreateIssueCommentRequestData.newBuilder().setBody(addReviewerBotInfo(issueComment.getUser().getEmail(), issueComment.getCreatedAt(), issueComment.getBody(), reviewerLink)).build()).build()).getIssueComment();
log.atInfo().log("Issue comment with id *%s* was CREATED on GitHub(owner: %s, name: %s, PR number: %s): %s", comment.getId(), repoOwner, repoName, pullRequestNumber, issueComment);
return comment;
}
Aggregations