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);
}
}
}
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);
}
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();
}
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;
}
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;
}
Aggregations