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);
}
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;
}
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;
}
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());
}
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());
}
Aggregations