Search in sources :

Example 6 with Diff

use of com.google.startupos.tools.reviewer.local_server.service.Protos.Diff 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 7 with Diff

use of com.google.startupos.tools.reviewer.local_server.service.Protos.Diff 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)

Example 8 with Diff

use of com.google.startupos.tools.reviewer.local_server.service.Protos.Diff in project startup-os by google.

the class DiffCommand method createDiff.

private Diff createDiff() {
    DiffNumberResponse response = codeReviewBlockingStub.getAvailableDiffNumber(Empty.getDefaultInstance());
    String branchName = String.format("D%s", response.getLastDiffId());
    System.out.println("Creating " + branchName);
    Long currentTime = new Long(System.currentTimeMillis());
    Diff.Builder diffBuilder = Diff.newBuilder().setWorkspace(workspaceName).setDescription(description.get()).addAllIssue(getIssues(buglink.get())).addAllReviewer(getReviewers(reviewers.get())).setId(response.getLastDiffId()).setCreatedTimestamp(currentTime).setModifiedTimestamp(currentTime);
    Map<GitRepo, String> repoToInitialBranch = new HashMap<>();
    try {
        fileUtils.listContents(workspacePath).stream().map(path -> fileUtils.joinToAbsolutePath(workspacePath, path)).filter(fileUtils::folderExists).forEach(path -> {
            String repoName = Paths.get(path).getFileName().toString();
            GitRepo repo = this.gitRepoFactory.create(path);
            repoToInitialBranch.put(repo, repo.currentBranch());
            System.out.println(String.format("[%s/%s]: switching to diff branch", workspaceName, repoName));
            repo.switchBranch(branchName);
        });
        addGithubRepos(diffBuilder);
    } catch (Exception e) {
        repoToInitialBranch.forEach((repo, initialBranch) -> {
            if (!repo.currentBranch().equals(initialBranch)) {
                repo.switchBranch(initialBranch);
            }
        });
        e.printStackTrace();
    }
    return diffBuilder.build();
}
Also used : Arrays(java.util.Arrays) Empty(com.google.startupos.tools.reviewer.local_server.service.Protos.Empty) ManagedChannel(io.grpc.ManagedChannel) FileUtils(com.google.startupos.common.FileUtils) HashMap(java.util.HashMap) Inject(javax.inject.Inject) GitRepoFactory(com.google.startupos.common.repo.GitRepoFactory) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) GitRepo(com.google.startupos.common.repo.GitRepo) Named(javax.inject.Named) FlagDesc(com.google.startupos.common.flags.FlagDesc) Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff) CodeReviewServiceGrpc(com.google.startupos.tools.reviewer.local_server.service.CodeReviewServiceGrpc) Flags(com.google.startupos.common.flags.Flags) Reviewer(com.google.startupos.tools.reviewer.local_server.service.Protos.Reviewer) Collectors(java.util.stream.Collectors) CreateDiffRequest(com.google.startupos.tools.reviewer.local_server.service.Protos.CreateDiffRequest) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) List(java.util.List) DiffRequest(com.google.startupos.tools.reviewer.local_server.service.Protos.DiffRequest) Paths(java.nio.file.Paths) GithubPr(com.google.startupos.tools.reviewer.local_server.service.Protos.GithubPr) DiffNumberResponse(com.google.startupos.tools.reviewer.local_server.service.Protos.DiffNumberResponse) Flag(com.google.startupos.common.flags.Flag) GitRepo(com.google.startupos.common.repo.GitRepo) Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff) HashMap(java.util.HashMap) DiffNumberResponse(com.google.startupos.tools.reviewer.local_server.service.Protos.DiffNumberResponse)

Example 9 with Diff

use of com.google.startupos.tools.reviewer.local_server.service.Protos.Diff in project startup-os by google.

the class DiffCommand method run.

@Override
public boolean run(String[] args) {
    Flags.parseCurrentPackage(args);
    Diff diff = (diffNumber == -1) ? createDiff() : updateDiff(diffNumber);
    CreateDiffRequest request = CreateDiffRequest.newBuilder().setDiff(diff).build();
    // TODO: Check if we changed diff, update only if changed. Write to output if no change.
    // TODO: Rename createDiff to createOrUpdateDiff
    codeReviewBlockingStub.createDiff(request);
    return true;
}
Also used : Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff) CreateDiffRequest(com.google.startupos.tools.reviewer.local_server.service.Protos.CreateDiffRequest)

Example 10 with Diff

use of com.google.startupos.tools.reviewer.local_server.service.Protos.Diff in project startup-os by google.

the class SubmitterTask method tryRegisterListener.

public void tryRegisterListener() {
    if (!listenerRegistered) {
        firestoreClient.addCollectionListener(ReviewerConstants.DIFF_COLLECTION, Diff.newBuilder(), new ProtoEventListener<ProtoQuerySnapshot<Diff>>() {

            @Override
            public void onEvent(@Nullable ProtoQuerySnapshot<Diff> snapshot, @Nullable RuntimeException e) {
                if (e != null) {
                    System.err.println("Listen failed: " + e);
                    return;
                }
                ArrayList<Diff> updatedDiffs = new ArrayList(diffs);
                log.atInfo().log("Received %d changes", snapshot.getProtoChanges().size());
                for (ProtoChange<Diff> protoChange : snapshot.getProtoChanges()) {
                    switch(protoChange.getType()) {
                        case ADDED:
                            updatedDiffs.add(protoChange.getProto());
                            break;
                        case MODIFIED:
                            // The indices are made so that this type of sequential remove & add works, see:
                            // https://googleapis.github.io/google-cloud-java/google-cloud-clients/apidocs/com/google/cloud/firestore/DocumentChange.html#getNewIndex--
                            updatedDiffs.remove(protoChange.getOldIndex());
                            updatedDiffs.add(protoChange.getNewIndex(), protoChange.getProto());
                            break;
                        case REMOVED:
                            updatedDiffs.remove(protoChange.getOldIndex());
                            break;
                        default:
                            throw new IllegalStateException("Unknown enum " + protoChange.getType());
                    }
                }
                diffs = ImmutableList.copyOf(updatedDiffs);
                run();
            }
        });
        listenerRegistered = true;
    }
}
Also used : Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff) ProtoQuerySnapshot(com.google.startupos.common.firestore.ProtoQuerySnapshot) ArrayList(java.util.ArrayList) ProtoChange(com.google.startupos.common.firestore.ProtoChange)

Aggregations

Diff (com.google.startupos.tools.reviewer.local_server.service.Protos.Diff)11 GitRepo (com.google.startupos.common.repo.GitRepo)3 PullRequest (com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.PullRequest)3 TextDiff (com.google.startupos.common.Protos.TextDiff)2 FirestoreProtoClient (com.google.startupos.common.firestore.FirestoreProtoClient)2 CreateDiffRequest (com.google.startupos.tools.reviewer.local_server.service.Protos.CreateDiffRequest)2 Reviewer (com.google.startupos.tools.reviewer.local_server.service.Protos.Reviewer)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 FileUtils (com.google.startupos.common.FileUtils)1 ProtoChange (com.google.startupos.common.firestore.ProtoChange)1 ProtoQuerySnapshot (com.google.startupos.common.firestore.ProtoQuerySnapshot)1 Flag (com.google.startupos.common.flags.Flag)1 FlagDesc (com.google.startupos.common.flags.FlagDesc)1 Flags (com.google.startupos.common.flags.Flags)1 GitRepoFactory (com.google.startupos.common.repo.GitRepoFactory)1 IssueComment (com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.IssueComment)1 ReviewComment (com.google.startupos.tools.reviewer.job.sync.GithubPullRequestProtos.ReviewComment)1 CodeReviewServiceGrpc (com.google.startupos.tools.reviewer.local_server.service.CodeReviewServiceGrpc)1