use of com.google.startupos.tools.reviewer.ReviewerProtos.CiResponse.TargetResult.Status in project startup-os by google.
the class CiTask method processRequest.
private void processRequest(CiRequest request) {
log.atInfo().log("Processing request:\n%s", request);
CiResponse.Builder responseBuilder = CiResponse.newBuilder().setRequest(request);
if (!fileUtils.folderExists("ci")) {
fileUtils.mkdirs("ci");
}
for (CiRequest.Target target : request.getTargetList()) {
log.atInfo().log("Processing target:\n%s", target);
Repo repo = target.getRepo();
String repoPath = fileUtils.joinPaths(fileUtils.getCurrentWorkingDirectory(), "ci", repo.getId());
GitRepo gitRepo = this.gitRepoFactory.create(repoPath);
try {
if (fileUtils.folderEmptyOrNotExists(repoPath)) {
gitRepo.cloneRepo(repo.getUrl(), repoPath);
} else {
gitRepo.switchBranch("master");
gitRepo.pull();
}
} catch (Exception e) {
log.atSevere().withCause(e).log("Failed to process target");
responseBuilder = responseBuilder.addResult(CiResponse.TargetResult.newBuilder().setTarget(target).setStatus(Status.FAIL).setLog(e.toString()).build());
saveCiResponse(responseBuilder.build(), request.getDiffId());
return;
}
gitRepo.switchBranch(target.getCommitId());
log.atInfo().log("Running reviewer-ci.sh in %s", repoPath);
CommandLine.CommandResult result = CommandLine.runCommandForError("/usr/bin/env bash " + fileUtils.joinPaths(repoPath, "reviewer-ci.sh"), repoPath);
log.atInfo().log("Done running reviewer-ci.sh");
String ciLog = result.stderr;
if (ciLog.length() > MAX_LOG_LENGTH) {
ciLog = ciLog.substring(0, MAX_LOG_LENGTH) + "[log truncated from length " + ciLog.length() + "]\n";
}
Status status = result.exitValue == 0 ? Status.SUCCESS : Status.FAIL;
responseBuilder.addResult(CiResponse.TargetResult.newBuilder().setTarget(target).setStatus(status).setLog(ciLog).build());
saveCiResponse(responseBuilder.build(), request.getDiffId());
firestoreClient.deleteDocument(ReviewerConstants.CI_REQUESTS_PATH, Long.toString(request.getDiffId()));
log.atInfo().log("Done processing CiRequest. Status=" + status);
}
}
Aggregations