Search in sources :

Example 6 with CommitValidationMessage

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

the class SubmitRequirementExpressionsValidator method onCommitReceived.

@Override
public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent event) throws CommitValidationException {
    try {
        if (!event.refName.equals(RefNames.REFS_CONFIG) || !isFileChanged(event, ProjectConfig.PROJECT_CONFIG)) {
            // validate the submit requirements in it
            return ImmutableList.of();
        }
        ProjectConfig projectConfig = getProjectConfig(event);
        ImmutableList<CommitValidationMessage> validationMessages = validateSubmitRequirementExpressions(projectConfig.getSubmitRequirementSections().values());
        if (!validationMessages.isEmpty()) {
            throw new CommitValidationException(String.format("invalid submit requirement expressions in %s (revision = %s)", ProjectConfig.PROJECT_CONFIG, projectConfig.getRevision()), validationMessages);
        }
        return ImmutableList.of();
    } catch (IOException | DiffNotAvailableException | ConfigInvalidException e) {
        throw new CommitValidationException(String.format("failed to validate submit requirement expressions in %s for revision %s in ref %s" + " of project %s", ProjectConfig.PROJECT_CONFIG, event.commit.getName(), RefNames.REFS_CONFIG, event.project.getNameKey()), e);
    }
}
Also used : DiffNotAvailableException(com.google.gerrit.server.patch.DiffNotAvailableException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) CommitValidationException(com.google.gerrit.server.git.validators.CommitValidationException) IOException(java.io.IOException) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage)

Example 7 with CommitValidationMessage

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

the class CancellationIT method handleWrappedRequestCancelledExceptionForPush.

@Test
public void handleWrappedRequestCancelledExceptionForPush() throws Exception {
    CommitValidationListener commitValidationListener = new CommitValidationListener() {

        @Override
        public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent) throws CommitValidationException {
            // Simulate an exceeded deadline by throwing RequestCancelledException.
            throw new RuntimeException(new RequestCancelledException(RequestStateProvider.Reason.SERVER_DEADLINE_EXCEEDED, "deadline = 10m"));
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(commitValidationListener)) {
        PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
        PushOneCommit.Result r = push.to("refs/heads/master");
        r.assertErrorStatus("Server Deadline Exceeded (deadline = 10m)");
    }
}
Also used : CommitValidationListener(com.google.gerrit.server.git.validators.CommitValidationListener) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) CommitReceivedEvent(com.google.gerrit.server.events.CommitReceivedEvent) RequestCancelledException(com.google.gerrit.server.cancellation.RequestCancelledException) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 8 with CommitValidationMessage

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

the class CancellationIT method handleClientDeadlineExceededForPush.

@Test
public void handleClientDeadlineExceededForPush() throws Exception {
    CommitValidationListener commitValidationListener = new CommitValidationListener() {

        @Override
        public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent) throws CommitValidationException {
            // Simulate an exceeded deadline by throwing RequestCancelledException.
            throw new RequestCancelledException(RequestStateProvider.Reason.CLIENT_PROVIDED_DEADLINE_EXCEEDED, /* cancellationMessage= */
            null);
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(commitValidationListener)) {
        PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
        PushOneCommit.Result r = push.to("refs/heads/master");
        r.assertErrorStatus("Client Provided Deadline Exceeded");
    }
}
Also used : CommitValidationListener(com.google.gerrit.server.git.validators.CommitValidationListener) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) CommitReceivedEvent(com.google.gerrit.server.events.CommitReceivedEvent) RequestCancelledException(com.google.gerrit.server.cancellation.RequestCancelledException) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 9 with CommitValidationMessage

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

the class CancellationIT method handleRequestCancellationWithMessageForPush.

@Test
public void handleRequestCancellationWithMessageForPush() throws Exception {
    CommitValidationListener commitValidationListener = new CommitValidationListener() {

        @Override
        public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent) throws CommitValidationException {
            // Simulate an exceeded deadline by throwing RequestCancelledException.
            throw new RequestCancelledException(RequestStateProvider.Reason.SERVER_DEADLINE_EXCEEDED, "deadline = 10m");
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(commitValidationListener)) {
        PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
        PushOneCommit.Result r = push.to("refs/heads/master");
        r.assertErrorStatus("Server Deadline Exceeded (deadline = 10m)");
    }
}
Also used : CommitValidationListener(com.google.gerrit.server.git.validators.CommitValidationListener) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) CommitReceivedEvent(com.google.gerrit.server.events.CommitReceivedEvent) RequestCancelledException(com.google.gerrit.server.cancellation.RequestCancelledException) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

CommitValidationMessage (com.google.gerrit.server.git.validators.CommitValidationMessage)9 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)5 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)5 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)5 RequestCancelledException (com.google.gerrit.server.cancellation.RequestCancelledException)5 CommitReceivedEvent (com.google.gerrit.server.events.CommitReceivedEvent)5 CommitValidationListener (com.google.gerrit.server.git.validators.CommitValidationListener)5 Test (org.junit.Test)5 Ref (org.eclipse.jgit.lib.Ref)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 RefNames.isConfigRef (com.google.gerrit.entities.RefNames.isConfigRef)1 SubmitRequirement (com.google.gerrit.entities.SubmitRequirement)1 CommitValidationException (com.google.gerrit.server.git.validators.CommitValidationException)1 TraceTimer (com.google.gerrit.server.logging.TraceContext.TraceTimer)1 DiffNotAvailableException (com.google.gerrit.server.patch.DiffNotAvailableException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1