Search in sources :

Example 1 with Diff

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

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

the class CiTask method saveCiResponse.

public void saveCiResponse(CiResponse ciResponse, long diffId) {
    Diff diff = (Diff) firestoreClient.getProtoDocument(ReviewerConstants.DIFF_COLLECTION, String.valueOf(diffId), Diff.newBuilder());
    firestoreClient.setProtoDocument(ReviewerConstants.DIFF_COLLECTION, String.valueOf(diffId), diff.toBuilder().addCiResponse(ciResponse).build());
    firestoreClient.addProtoDocumentToCollection(String.format(ReviewerConstants.CI_RESPONSES_PATH, diffId), ciResponse);
}
Also used : Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff)

Example 3 with Diff

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

the class CodeReviewService method createDiff.

@Override
public void createDiff(CreateDiffRequest req, StreamObserver<Empty> responseObserver) {
    checkAuth();
    FirestoreProtoClient client = new FirestoreProtoClient(authService.getProjectId(), authService.getToken());
    String diffPath = fileUtils.joinToAbsolutePath(ReviewerConstants.DIFF_COLLECTION);
    Diff diff = req.getDiff().toBuilder().setAuthor(Author.newBuilder().setEmail(authService.getUserEmail()).build()).build();
    client.setProtoDocument(diffPath, String.valueOf(diff.getId()), diff);
    responseObserver.onNext(Empty.getDefaultInstance());
    responseObserver.onCompleted();
}
Also used : Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff) TextDiff(com.google.startupos.common.Protos.TextDiff) FirestoreProtoClient(com.google.startupos.common.firestore.FirestoreProtoClient)

Example 4 with Diff

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

the class ReviewCommand method run.

@Override
public boolean run(String[] args) {
    if (diffNumber == -1) {
        System.out.println(RED_ERROR + "Workspace has no diff to review (git branch has no D# branch)");
        return false;
    }
    String branchName = String.format("D%d", diffNumber);
    Diff.Builder diffBuilder = codeReviewBlockingStub.getDiff(DiffRequest.newBuilder().setDiffId(diffNumber).build()).toBuilder();
    if (diffBuilder.getReviewerCount() == 0) {
        System.out.println(String.format("D%d has no reviewers", diffNumber));
        return false;
    }
    // TODO: Fail if SUBMITTING, SUBMITTED, REVERTING or REVERTED.
    for (int i = 0; i < diffBuilder.getReviewerCount(); i++) {
        diffBuilder.setReviewer(i, diffBuilder.getReviewer(i).toBuilder().setNeedsAttention(true));
    }
    diffBuilder.setAuthor(diffBuilder.getAuthor().toBuilder().setNeedsAttention(false));
    diffBuilder.setStatus(Status.UNDER_REVIEW).build();
    try {
        fileUtils.listContents(workspacePath).stream().map(path -> fileUtils.joinToAbsolutePath(workspacePath, path)).filter(fileUtils::folderExists).forEach(path -> {
            GitRepo repo = this.gitRepoFactory.create(path);
            repo.push(branchName);
        });
    } catch (IOException e) {
        e.printStackTrace();
    }
    codeReviewBlockingStub.createDiff(CreateDiffRequest.newBuilder().setDiff(diffBuilder.build()).build());
    return true;
}
Also used : GitRepo(com.google.startupos.common.repo.GitRepo) Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff) IOException(java.io.IOException)

Example 5 with Diff

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

the class SubmitCommand method run.

@Override
public boolean run(String[] args) {
    if (diffNumber == -1) {
        System.out.println(RED_ERROR + "Workspace has no diff to submit (git branch has no D# branch)");
        return false;
    }
    final Diff.Builder diffBuilder = codeReviewBlockingStub.getDiff(DiffRequest.newBuilder().setDiffId(diffNumber).build()).toBuilder();
    boolean hasApprovedReviews = diffBuilder.getReviewerList().stream().anyMatch(Reviewer::getApproved);
    if (!hasApprovedReviews) {
        System.out.println(RED_ERROR + String.format("D%d is not approved yet", diffNumber));
        return false;
    }
    System.out.println("Updating diff status: SUBMITTING");
    codeReviewBlockingStub.createDiff(CreateDiffRequest.newBuilder().setDiff(diffBuilder.setStatus(Status.SUBMITTING)).build());
    final String diffBranchName = String.format("D%s", diffBuilder.getId());
    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);
            boolean hasDiffBranch = repo.listBranches().stream().anyMatch(branchName -> branchName.equals(diffBranchName));
            if (!hasDiffBranch) {
                System.out.println(String.format("Repo %s has no branch named %s, skipping", repoName, diffBranchName));
                return;
            }
            System.out.println(String.format("[%s]: committing changes", repoName));
            repo.commit(repo.getUncommittedFiles(), String.format("%s: %s", diffBranchName, diffBuilder.getDescription()));
            System.out.println(String.format("[%s]: removing branch", repoName));
            repo.removeBranch(diffBranchName);
            System.out.println(String.format("[%s]: pushing to remote", repoName));
            repo.push(diffBranchName);
        });
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("Updating diff status: SUBMITTED");
    codeReviewBlockingStub.createDiff(CreateDiffRequest.newBuilder().setDiff(diffBuilder.setStatus(Status.SUBMITTED)).build());
    return true;
}
Also used : GitRepo(com.google.startupos.common.repo.GitRepo) Diff(com.google.startupos.tools.reviewer.local_server.service.Protos.Diff) IOException(java.io.IOException) Reviewer(com.google.startupos.tools.reviewer.local_server.service.Protos.Reviewer)

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