Search in sources :

Example 1 with DiffNumberResponse

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

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

the class CodeReviewService method getAvailableDiffNumber.

// TODO: fix concurrency issues (if two different call method at same time)
// could be done by wrapping in a transaction
@Override
public void getAvailableDiffNumber(Empty request, StreamObserver<DiffNumberResponse> responseObserver) {
    checkAuth();
    FirestoreProtoClient client = new FirestoreProtoClient(authService.getProjectId(), authService.getToken());
    try {
        DiffNumberResponse diffNumberResponse = (DiffNumberResponse) client.getProtoDocument(ReviewerConstants.LAST_DIFF_NUMBER_DOCUMENT, DiffNumberResponse.newBuilder());
        diffNumberResponse = diffNumberResponse.toBuilder().setLastDiffId(diffNumberResponse.getLastDiffId() + 1).build();
        client.setProtoDocument(ReviewerConstants.LAST_DIFF_NUMBER_DOCUMENT, diffNumberResponse);
        responseObserver.onNext(diffNumberResponse);
    } catch (Exception e) {
        StringWriter errors = new StringWriter();
        e.printStackTrace(new PrintWriter(errors));
        throw e;
    }
    responseObserver.onCompleted();
}
Also used : StringWriter(java.io.StringWriter) FirestoreProtoClient(com.google.startupos.common.firestore.FirestoreProtoClient) IOException(java.io.IOException) DiffNumberResponse(com.google.startupos.tools.reviewer.local_server.service.Protos.DiffNumberResponse) PrintWriter(java.io.PrintWriter)

Aggregations

DiffNumberResponse (com.google.startupos.tools.reviewer.local_server.service.Protos.DiffNumberResponse)2 ImmutableList (com.google.common.collect.ImmutableList)1 FileUtils (com.google.startupos.common.FileUtils)1 FirestoreProtoClient (com.google.startupos.common.firestore.FirestoreProtoClient)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 GitRepo (com.google.startupos.common.repo.GitRepo)1 GitRepoFactory (com.google.startupos.common.repo.GitRepoFactory)1 CodeReviewServiceGrpc (com.google.startupos.tools.reviewer.local_server.service.CodeReviewServiceGrpc)1 CreateDiffRequest (com.google.startupos.tools.reviewer.local_server.service.Protos.CreateDiffRequest)1 Diff (com.google.startupos.tools.reviewer.local_server.service.Protos.Diff)1 DiffRequest (com.google.startupos.tools.reviewer.local_server.service.Protos.DiffRequest)1 Empty (com.google.startupos.tools.reviewer.local_server.service.Protos.Empty)1 GithubPr (com.google.startupos.tools.reviewer.local_server.service.Protos.GithubPr)1 Reviewer (com.google.startupos.tools.reviewer.local_server.service.Protos.Reviewer)1 ManagedChannel (io.grpc.ManagedChannel)1 ManagedChannelBuilder (io.grpc.ManagedChannelBuilder)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1