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