use of com.google.gerrit.extensions.common.TestSubmitRuleInput in project gerrit by GerritCodeReview.
the class TestSubmitType method apply.
@Override
public SubmitType apply(RevisionResource rsrc, TestSubmitRuleInput input) throws AuthException, BadRequestException, OrmException {
if (input == null) {
input = new TestSubmitRuleInput();
}
if (input.rule != null && !rules.isProjectRulesEnabled()) {
throw new AuthException("project rules are disabled");
}
input.filters = MoreObjects.firstNonNull(input.filters, filters);
SubmitRuleEvaluator evaluator = new SubmitRuleEvaluator(changeDataFactory.create(db.get(), rsrc.getControl()));
SubmitTypeRecord rec = evaluator.setPatchSet(rsrc.getPatchSet()).setLogErrors(false).setSkipSubmitFilters(input.filters == Filters.SKIP).setRule(input.rule).getSubmitType();
if (rec.status != SubmitTypeRecord.Status.OK) {
throw new BadRequestException(String.format("rule %s produced invalid result: %s", evaluator.getSubmitRuleName(), rec));
}
return rec.type;
}
use of com.google.gerrit.extensions.common.TestSubmitRuleInput 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.TestSubmitRuleInput in project gerrit by GerritCodeReview.
the class TestSubmitType method apply.
@Override
public Response<SubmitType> apply(RevisionResource rsrc, TestSubmitRuleInput input) throws AuthException, 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);
ChangeData cd = changeDataFactory.create(rsrc.getNotes());
SubmitTypeRecord rec = prologRule.getSubmitType(cd, PrologOptions.dryRunOptions(input.rule, input.filters == Filters.SKIP));
if (rec.status != SubmitTypeRecord.Status.OK) {
throw new BadRequestException(String.format("rule produced invalid result: %s", rec));
}
return Response.ok(rec.type);
}
use of com.google.gerrit.extensions.common.TestSubmitRuleInput in project gerrit by GerritCodeReview.
the class TestSubmitRule method apply.
@Override
public List<Record> apply(RevisionResource rsrc, TestSubmitRuleInput input) throws AuthException, OrmException {
if (input == null) {
input = new TestSubmitRuleInput();
}
if (input.rule != null && !rules.isProjectRulesEnabled()) {
throw new AuthException("project rules are disabled");
}
input.filters = MoreObjects.firstNonNull(input.filters, filters);
SubmitRuleEvaluator evaluator = new SubmitRuleEvaluator(changeDataFactory.create(db.get(), rsrc.getControl()));
List<SubmitRecord> records = evaluator.setPatchSet(rsrc.getPatchSet()).setLogErrors(false).setSkipSubmitFilters(input.filters == Filters.SKIP).setRule(input.rule).evaluate();
List<Record> out = Lists.newArrayListWithCapacity(records.size());
AccountLoader accounts = accountInfoFactory.create(true);
for (SubmitRecord r : records) {
out.add(new Record(r, accounts));
}
if (!out.isEmpty()) {
out.get(0).prologReductionCount = evaluator.getReductionsConsumed();
}
accounts.fill();
return out;
}
use of com.google.gerrit.extensions.common.TestSubmitRuleInput 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());
}
Aggregations