Search in sources :

Example 1 with CommitValidators

use of com.google.gerrit.server.git.validators.CommitValidators in project gerrit by GerritCodeReview.

the class ReceiveCommits method validCommit.

private boolean validCommit(RevWalk rw, RefControl ctl, ReceiveCommand cmd, ObjectId id) throws IOException {
    if (validCommits.contains(id)) {
        return true;
    }
    RevCommit c = rw.parseCommit(id);
    rw.parseBody(c);
    try (CommitReceivedEvent receiveEvent = new CommitReceivedEvent(cmd, project, ctl.getRefName(), rw.getObjectReader(), c, user)) {
        boolean isMerged = magicBranch != null && cmd.getRefName().equals(magicBranch.cmd.getRefName()) && magicBranch.merged;
        CommitValidators validators = isMerged ? commitValidatorsFactory.forMergedCommits(ctl) : commitValidatorsFactory.forReceiveCommits(ctl, sshInfo, repo, rw);
        messages.addAll(validators.validate(receiveEvent));
    } catch (CommitValidationException e) {
        logDebug("Commit validation failed on {}", c.name());
        messages.addAll(e.getMessages());
        reject(cmd, e.getMessage());
        return false;
    }
    validCommits.add(c.copy());
    return true;
}
Also used : CommitValidators(com.google.gerrit.server.git.validators.CommitValidators) CommitValidationException(com.google.gerrit.server.git.validators.CommitValidationException) CommitReceivedEvent(com.google.gerrit.server.events.CommitReceivedEvent) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

CommitReceivedEvent (com.google.gerrit.server.events.CommitReceivedEvent)1 CommitValidationException (com.google.gerrit.server.git.validators.CommitValidationException)1 CommitValidators (com.google.gerrit.server.git.validators.CommitValidators)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1