Search in sources :

Example 1 with Status

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);
    }
}
Also used : Status(com.google.startupos.tools.reviewer.ReviewerProtos.CiResponse.TargetResult.Status) CiRequest(com.google.startupos.tools.reviewer.ReviewerProtos.CiRequest) CommandLine(com.google.startupos.common.CommandLine) Repo(com.google.startupos.tools.reviewer.ReviewerProtos.Repo) GitRepo(com.google.startupos.common.repo.GitRepo) GitRepo(com.google.startupos.common.repo.GitRepo) CiResponse(com.google.startupos.tools.reviewer.ReviewerProtos.CiResponse)

Aggregations

CommandLine (com.google.startupos.common.CommandLine)1 GitRepo (com.google.startupos.common.repo.GitRepo)1 CiRequest (com.google.startupos.tools.reviewer.ReviewerProtos.CiRequest)1 CiResponse (com.google.startupos.tools.reviewer.ReviewerProtos.CiResponse)1 Status (com.google.startupos.tools.reviewer.ReviewerProtos.CiResponse.TargetResult.Status)1 Repo (com.google.startupos.tools.reviewer.ReviewerProtos.Repo)1