Search in sources :

Example 1 with TestSubmitRuleInfo

use of com.google.gerrit.extensions.common.TestSubmitRuleInfo in project gerrit by GerritCodeReview.

the class TestSubmitRule method apply.

@Override
public Response<TestSubmitRuleInfo> apply(RevisionResource rsrc, TestSubmitRuleInput input) throws AuthException, PermissionBackendException, BadRequestException {
    if (input == null) {
        input = new TestSubmitRuleInput();
    }
    if (input.rule == null) {
        throw new BadRequestException("rule is required");
    }
    if (!rules.isProjectRulesEnabled()) {
        throw new AuthException("project rules are disabled");
    }
    input.filters = MoreObjects.firstNonNull(input.filters, filters);
    Project.NameKey name = rsrc.getProject();
    Optional<ProjectState> project = projectCache.get(name);
    if (!project.isPresent()) {
        throw new BadRequestException("project not found " + name);
    }
    ChangeData cd = changeDataFactory.create(rsrc.getNotes());
    SubmitRecord record = prologRule.evaluate(cd, PrologOptions.dryRunOptions(input.rule, input.filters == Filters.SKIP));
    AccountLoader accounts = accountInfoFactory.create(true);
    TestSubmitRuleInfo out = newSubmitRuleInfo(record, accounts);
    accounts.fill();
    return Response.ok(out);
}
Also used : Project(com.google.gerrit.entities.Project) SubmitRecord(com.google.gerrit.entities.SubmitRecord) TestSubmitRuleInput(com.google.gerrit.extensions.common.TestSubmitRuleInput) AccountLoader(com.google.gerrit.server.account.AccountLoader) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AuthException(com.google.gerrit.extensions.restapi.AuthException) ProjectState(com.google.gerrit.server.project.ProjectState) ChangeData(com.google.gerrit.server.query.change.ChangeData) TestSubmitRuleInfo(com.google.gerrit.extensions.common.TestSubmitRuleInfo)

Example 2 with TestSubmitRuleInfo

use of com.google.gerrit.extensions.common.TestSubmitRuleInfo in project gerrit by GerritCodeReview.

the class TestSubmitRule method newSubmitRuleInfo.

private static TestSubmitRuleInfo newSubmitRuleInfo(SubmitRecord r, AccountLoader accounts) {
    TestSubmitRuleInfo info = new TestSubmitRuleInfo();
    info.status = r.status.name();
    info.errorMessage = r.errorMessage;
    if (r.labels != null) {
        for (SubmitRecord.Label n : r.labels) {
            AccountInfo who = n.appliedBy != null ? accounts.get(n.appliedBy) : new AccountInfo(null);
            label(info, n, who);
        }
    }
    return info;
}
Also used : SubmitRecord(com.google.gerrit.entities.SubmitRecord) TestSubmitRuleInfo(com.google.gerrit.extensions.common.TestSubmitRuleInfo) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 3 with TestSubmitRuleInfo

use of com.google.gerrit.extensions.common.TestSubmitRuleInfo in project gerrit by GerritCodeReview.

the class SubmitTypeRuleIT method invalidPrologRuleInfo.

private static TestSubmitRuleInfo invalidPrologRuleInfo() {
    TestSubmitRuleInfo info = new TestSubmitRuleInfo();
    info.status = "RULE_ERROR";
    info.errorMessage = "operator expected after expression at: invalid prolog rule end_of_file.";
    return info;
}
Also used : TestSubmitRuleInfo(com.google.gerrit.extensions.common.TestSubmitRuleInfo)

Example 4 with TestSubmitRuleInfo

use of com.google.gerrit.extensions.common.TestSubmitRuleInfo in project gerrit by GerritCodeReview.

the class SubmitTypeRuleIT method invalidSubmitRuleWithRulesInProject.

@Test
public void invalidSubmitRuleWithRulesInProject() throws Exception {
    setRulesPl(SUBMIT_TYPE_FROM_SUBJECT);
    String changeId = createChange("master", "change 1").getChangeId();
    TestSubmitRuleInput in = new TestSubmitRuleInput();
    in.rule = "invalid prolog rule";
    TestSubmitRuleInfo response = gApi.changes().id(changeId).current().testSubmitRule(in);
    assertThat(response).isEqualTo(invalidPrologRuleInfo());
}
Also used : TestSubmitRuleInput(com.google.gerrit.extensions.common.TestSubmitRuleInput) TestSubmitRuleInfo(com.google.gerrit.extensions.common.TestSubmitRuleInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with TestSubmitRuleInfo

use of com.google.gerrit.extensions.common.TestSubmitRuleInfo in project gerrit by GerritCodeReview.

the class SubmitTypeRuleIT method invalidSubmitRuleWithNoRulesInProject.

@Test
public void invalidSubmitRuleWithNoRulesInProject() throws Exception {
    String changeId = createChange("master", "change 1").getChangeId();
    TestSubmitRuleInput in = new TestSubmitRuleInput();
    in.rule = "invalid prolog rule";
    // We have no rules.pl by default. The fact that the default rules are showing up here is a bug.
    TestSubmitRuleInfo response = gApi.changes().id(changeId).current().testSubmitRule(in);
    assertThat(response).isEqualTo(invalidPrologRuleInfo());
}
Also used : TestSubmitRuleInput(com.google.gerrit.extensions.common.TestSubmitRuleInput) TestSubmitRuleInfo(com.google.gerrit.extensions.common.TestSubmitRuleInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

TestSubmitRuleInfo (com.google.gerrit.extensions.common.TestSubmitRuleInfo)5 TestSubmitRuleInput (com.google.gerrit.extensions.common.TestSubmitRuleInput)3 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 SubmitRecord (com.google.gerrit.entities.SubmitRecord)2 Test (org.junit.Test)2 Project (com.google.gerrit.entities.Project)1 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 AccountLoader (com.google.gerrit.server.account.AccountLoader)1 ProjectState (com.google.gerrit.server.project.ProjectState)1 ChangeData (com.google.gerrit.server.query.change.ChangeData)1