use of com.google.gerrit.extensions.common.SubmitRequirementResultInfo in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirements_eliminatesMultipleDuplicatesForLegacyMatchingSRs.
@Test
public void submitRequirements_eliminatesMultipleDuplicatesForLegacyMatchingSRs() throws Exception {
// If a custom/prolog submit rule emits the same label name multiple times, we merge these into
// a single submit requirement result: in this test, we have five different submit rules that
// return the same label name, all with an "OK" status. The submit requirements API returns
// a single SR result with status=SATISFIED.
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
try (Registration registration = extensionRegistry.newRegistration()) {
IntStream.range(0, 5).forEach(i -> registration.add(createSubmitRule("r" + i, SubmitRecord.Status.OK, "CR", SubmitRecord.Label.Status.OK)));
ChangeInfo change = gApi.changes().id(changeId).get();
Collection<SubmitRequirementResultInfo> submitRequirements = change.submitRequirements;
assertThat(submitRequirements).hasSize(2);
assertSubmitRequirementStatus(submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
true);
assertSubmitRequirementStatus(submitRequirements, "CR", Status.SATISFIED, /* isLegacy= */
true);
}
}
use of com.google.gerrit.extensions.common.SubmitRequirementResultInfo in project gerrit by GerritCodeReview.
the class SubmitRequirementsJson method toInfo.
public static SubmitRequirementResultInfo toInfo(SubmitRequirement req, SubmitRequirementResult result) {
SubmitRequirementResultInfo info = new SubmitRequirementResultInfo();
info.name = req.name();
info.description = req.description().orElse(null);
if (req.applicabilityExpression().isPresent()) {
info.applicabilityExpressionResult = submitRequirementExpressionToInfo(req.applicabilityExpression().get(), result.applicabilityExpressionResult().get(), /* hide= */
true);
// Always hide applicability expressions on the API
}
if (req.overrideExpression().isPresent() && result.overrideExpressionResult().isPresent()) {
info.overrideExpressionResult = submitRequirementExpressionToInfo(req.overrideExpression().get(), result.overrideExpressionResult().get(), /* hide= */
false);
}
if (result.submittabilityExpressionResult().isPresent()) {
info.submittabilityExpressionResult = submitRequirementExpressionToInfo(req.submittabilityExpression(), result.submittabilityExpressionResult().get(), /* hide= */
false);
}
info.status = SubmitRequirementResultInfo.Status.valueOf(result.status().toString());
info.isLegacy = result.isLegacy();
return info;
}
use of com.google.gerrit.extensions.common.SubmitRequirementResultInfo in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirements_disallowsTheIsSubmittableOperator.
@Test
public void submitRequirements_disallowsTheIsSubmittableOperator() throws Exception {
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
configSubmitRequirement(project, SubmitRequirement.builder().setName("Wrong-Req").setSubmittabilityExpression(SubmitRequirementExpression.create("is:submittable")).setAllowOverrideInChildProjects(false).build());
ChangeInfo change = gApi.changes().id(changeId).get();
SubmitRequirementResultInfo srResult = change.submitRequirements.stream().filter(sr -> sr.name.equals("Wrong-Req")).collect(MoreCollectors.onlyElement());
assertThat(srResult.status).isEqualTo(Status.ERROR);
assertThat(srResult.submittabilityExpressionResult.errorMessage).isEqualTo("Operator 'is:submittable' cannot be used in submit requirement expressions.");
}
use of com.google.gerrit.extensions.common.SubmitRequirementResultInfo in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirement_emptyApplicable_submittabilityAndOverrideEvaluated.
@Test
public void submitRequirement_emptyApplicable_submittabilityAndOverrideEvaluated() throws Exception {
configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setApplicabilityExpression(Optional.empty()).setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setOverrideExpression(SubmitRequirementExpression.of("project:non-existent")).setAllowOverrideInChildProjects(false).build());
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
voteLabel(changeId, "Code-Review", 2);
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
assertSubmitRequirementStatus(changeInfo.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
false);
SubmitRequirementResultInfo requirement = changeInfo.submitRequirements.stream().collect(MoreCollectors.onlyElement());
assertThat(requirement.applicabilityExpressionResult).isNull();
assertSubmitRequirementExpression(requirement.submittabilityExpressionResult, /* expression= */
SubmitRequirementExpression.maxCodeReview().expressionString(), /* passingAtoms= */
ImmutableList.of(SubmitRequirementExpression.maxCodeReview().expressionString()), /* failingAtoms= */
ImmutableList.of(), /* fulfilled= */
true);
assertSubmitRequirementExpression(requirement.overrideExpressionResult, /* expression= */
"project:non-existent", /* passingAtoms= */
ImmutableList.of(), /* failingAtoms= */
ImmutableList.of("project:non-existent"), /* fulfilled= */
false);
}
use of com.google.gerrit.extensions.common.SubmitRequirementResultInfo in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method checkSubmitRequirement_notApplicable.
@Test
public void checkSubmitRequirement_notApplicable() throws Exception {
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
SubmitRequirementInput in = createSubmitRequirementInput("Code-Review", /* applicableIf= */
"branch:non-existent", /* submittableIf= */
"label:Code-Review=+2", /* overrideIf= */
null);
SubmitRequirementResultInfo result = gApi.changes().id(changeId).checkSubmitRequirement(in);
assertThat(result.status).isEqualTo(SubmitRequirementResultInfo.Status.NOT_APPLICABLE);
voteLabel(changeId, "Code-Review", 2);
result = gApi.changes().id(changeId).checkSubmitRequirement(in);
assertThat(result.status).isEqualTo(SubmitRequirementResultInfo.Status.NOT_APPLICABLE);
}
Aggregations