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