Search in sources :

Example 1 with PullRequest

use of com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.PullRequest 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);
        }
    }
}
Also used : Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff) ReviewComment(com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.ReviewComment) PullRequest(com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.PullRequest) IssueComment(com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.IssueComment)

Example 2 with PullRequest

use of com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.PullRequest in project startup-os by google.

the class DiffConverter method toPullRequests.

public ImmutableList<PullRequest> toPullRequests(Diff diff, ImmutableMap<String, GitRepo> repoNameToGitRepos) {
    ImmutableList.Builder<PullRequest> pullRequests = ImmutableList.builder();
    for (GithubPr githubPr : diff.getGithubPrList()) {
        PullRequest.Builder pullRequest = PullRequest.newBuilder();
        if (githubPr.getNumber() != 0) {
            pullRequest.setNumber(githubPr.getNumber());
        }
        pullRequest.setState(getPullRequestState(diff.getStatus())).setTitle("D" + diff.getId()).setUser(User.newBuilder().setEmail(diff.getAuthor().getEmail()).build()).setBody(diff.getDescription()).setCreatedAt(Instant.ofEpochMilli(diff.getCreatedTimestamp()).toString()).setUpdatedAt(Instant.ofEpochMilli(diff.getModifiedTimestamp()).toString()).setBaseBranchName("master").setHeadBranchName("D" + diff.getId()).setRepo(githubPr.getRepo()).addAllReviewComment(getReviewCommentsByRepoName(diff.getCodeThreadList(), githubPr.getRepo(), repoNameToGitRepos, diff.getModifiedTimestamp(), diff.getId())).addAllIssueComment(getIssueComments(diff.getDiffThreadList(), githubPr.getRepo())).setOwner(githubPr.getOwner()).setAssociatedReviewerDiff(diff.getId());
        pullRequests.add(pullRequest.build());
    }
    return pullRequests.build();
}
Also used : GithubPr(com.google.startupos.tools.reviewer.local_server.service.Protos.GithubPr) ImmutableList(com.google.common.collect.ImmutableList) PullRequest(com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.PullRequest)

Example 3 with PullRequest

use of com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.PullRequest in project startup-os by google.

the class DiffConverterTest method testCommentToFeatureBranchCommit.

@Test
public void testCommentToFeatureBranchCommit() {
    Diff diff = Diff.newBuilder().setId(1234).setAuthor(Author.newBuilder().setEmail("author@test.com").build()).setWorkspace("ws1").setCreatedTimestamp(1543989866559L).setModifiedTimestamp(1544008405696L).addCodeThread(Thread.newBuilder().setRepoId("test-repo").setCommitId(FEATURE_BRANCH_COMMIT_ID).setFile(Protos.File.newBuilder().setFilename("test_file.txt").setWorkspace("ws1").setRepoId("test-repo").setCommitId(FEATURE_BRANCH_COMMIT_ID).setFilenameWithRepo("test-repo/test_file.txt").build()).setLineNumber(5).addComment(Comment.newBuilder().setContent("R 5").setTimestamp(1544008385129L).setCreatedBy("reviewer@test.com").setId("DPwKo").build()).setId("KblmQG").build()).setModifiedBy("author@test.com").addGithubPr(GithubPr.newBuilder().setOwner("val-fed").setRepo("test-repo").build()).build();
    List<PullRequest> actualPullRequest = diffConverter.toPullRequests(diff, ImmutableMap.of("test-repo", gitRepo));
    PullRequest expectedPullRequest = PullRequest.newBuilder().setState("open").setTitle("D1234").setUser(User.newBuilder().setEmail("author@test.com").build()).setCreatedAt("2018-12-05T06:04:26.559Z").setUpdatedAt("2018-12-05T11:13:25.696Z").addReviewComment(ReviewComment.newBuilder().setPath("test_file.txt").setPosition(5).setCommitId(FEATURE_BRANCH_COMMIT_ID).setUser(User.newBuilder().setEmail("reviewer@test.com").build()).setBody("R 5").setCreatedAt("2018-12-05T11:13:05.129Z").setUpdatedAt("2018-12-05T11:13:25.696Z").setReviewerThreadId("KblmQG").setReviewerCommentId("DPwKo").setReviewerLineNumber(5).build()).setBaseBranchName("master").setHeadBranchName("D1234").setRepo("test-repo").setOwner("val-fed").setAssociatedReviewerDiff(1234).build();
    assertEquals(expectedPullRequest.toString(), actualPullRequest.get(0).toString());
}
Also used : Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff) PullRequest(com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.PullRequest) Test(org.junit.Test)

Example 4 with PullRequest

use of com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.PullRequest in project startup-os by google.

the class DiffConverterTest method testCommentToBaseBranchCommit.

@Test
public void testCommentToBaseBranchCommit() {
    Diff diff = Diff.newBuilder().setId(1234).setAuthor(Author.newBuilder().setEmail("author@test.com").build()).setWorkspace("ws1").setCreatedTimestamp(1543989866559L).setModifiedTimestamp(1544008405696L).addCodeThread(Thread.newBuilder().setRepoId("test-repo").setCommitId(BASE_BRANCH_COMMIT_ID).setFile(Protos.File.newBuilder().setFilename("test_file.txt").setWorkspace("ws1").setRepoId("test-repo").setCommitId(BASE_BRANCH_COMMIT_ID).setFilenameWithRepo("test-repo/test_file.txt").build()).setLineNumber(14).addComment(Comment.newBuilder().setContent("L 14").setTimestamp(1544008405695L).setCreatedBy("reviewer@test.com").setId("s47NL").build()).setId("ayAF7N").build()).setModifiedBy("author@test.com").addGithubPr(GithubPr.newBuilder().setOwner("val-fed").setRepo("test-repo").build()).build();
    List<PullRequest> actualPullRequest = diffConverter.toPullRequests(diff, ImmutableMap.of("test-repo", gitRepo));
    PullRequest expectedPullRequest = PullRequest.newBuilder().setState("open").setTitle("D1234").setUser(User.newBuilder().setEmail("author@test.com").build()).setCreatedAt("2018-12-05T06:04:26.559Z").setUpdatedAt("2018-12-05T11:13:25.696Z").addReviewComment(ReviewComment.newBuilder().setPath("test_file.txt").setPosition(12).setCommitId(BASE_BRANCH_COMMIT_ID).setUser(User.newBuilder().setEmail("reviewer@test.com").build()).setBody("L 14").setCreatedAt("2018-12-05T11:13:25.695Z").setUpdatedAt("2018-12-05T11:13:25.696Z").setReviewerThreadId("ayAF7N").setReviewerCommentId("s47NL").setReviewerLineNumber(14).build()).setBaseBranchName("master").setHeadBranchName("D1234").setRepo("test-repo").setOwner("val-fed").setAssociatedReviewerDiff(1234).build();
    assertEquals(expectedPullRequest.toString(), actualPullRequest.get(0).toString());
}
Also used : Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff) PullRequest(com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.PullRequest) Test(org.junit.Test)

Aggregations

PullRequest (com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.PullRequest)4 Diff (com.google.startupos.tools.reviewer.local_server.service.Protos.Diff)3 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 IssueComment (com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.IssueComment)1 ReviewComment (com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.ReviewComment)1 GithubPr (com.google.startupos.tools.reviewer.local_server.service.Protos.GithubPr)1