use of com.google.gerrit.entities.SubmitRequirementResult in project gerrit by GerritCodeReview.
the class MergeOp method checkSubmitRequirements.
public static void checkSubmitRequirements(ChangeData cd) throws ResourceConflictException {
PatchSet patchSet = cd.currentPatchSet();
if (patchSet == null) {
throw new ResourceConflictException("missing current patch set for change " + cd.getId());
}
Map<SubmitRequirement, SubmitRequirementResult> srResults = cd.submitRequirementsIncludingLegacy();
if (srResults.values().stream().allMatch(SubmitRequirementResult::fulfilled)) {
return;
} else if (srResults.isEmpty()) {
throw new IllegalStateException(String.format("Submit requirement results for change '%s' and patchset '%s' " + "are empty in project '%s'", cd.getId(), patchSet.id(), cd.change().getProject().get()));
}
for (SubmitRequirementResult srResult : srResults.values()) {
switch(srResult.status()) {
case SATISFIED:
case NOT_APPLICABLE:
case OVERRIDDEN:
case FORCED:
break;
case ERROR:
throw new ResourceConflictException(String.format("submit requirement '%s' has an error: %s", srResult.submitRequirement().name(), srResult.errorMessage().orElse("")));
case UNSATISFIED:
throw new ResourceConflictException(String.format("submit requirement '%s' is unsatisfied.", srResult.submitRequirement().name()));
default:
throw new IllegalStateException(String.format("Unexpected submit requirement status %s for %s in %s", srResult.status().name(), patchSet.id().getId(), cd.change().getProject().get()));
}
}
throw new IllegalStateException();
}
use of com.google.gerrit.entities.SubmitRequirementResult in project gerrit by GerritCodeReview.
the class ChangeField method formatSubmitRequirementValues.
/**
* Generate submit requirement result formats that are compatible with the legacy submit record
* statuses.
*/
@VisibleForTesting
static List<String> formatSubmitRequirementValues(Collection<SubmitRequirementResult> srResults) {
List<String> result = new ArrayList<>();
for (SubmitRequirementResult srResult : srResults) {
switch(srResult.status()) {
case SATISFIED:
case OVERRIDDEN:
case FORCED:
result.add(SubmitRecord.Label.Status.OK.name() + "," + srResult.submitRequirement().name().toLowerCase());
result.add(SubmitRecord.Label.Status.MAY.name() + "," + srResult.submitRequirement().name().toLowerCase());
break;
case UNSATISFIED:
result.add(SubmitRecord.Label.Status.NEED.name() + "," + srResult.submitRequirement().name().toLowerCase());
result.add(SubmitRecord.Label.Status.REJECT.name() + "," + srResult.submitRequirement().name().toLowerCase());
break;
case NOT_APPLICABLE:
case ERROR:
result.add(SubmitRecord.Label.Status.IMPOSSIBLE.name() + "," + srResult.submitRequirement().name().toLowerCase());
}
}
return result;
}
use of com.google.gerrit.entities.SubmitRequirementResult in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirement_storedForClosedChanges.
@Test
public void submitRequirement_storedForClosedChanges() throws Exception {
for (SubmitType submitType : SubmitType.values()) {
Project.NameKey project = createProjectForPush(submitType);
TestRepository<InMemoryRepository> repo = cloneProject(project);
configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(false).build());
PushOneCommit.Result r = createChange(repo, "master", "Add a file", "foo", "content", "topic");
String changeId = r.getChangeId();
voteLabel(changeId, "Code-Review", 2);
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
false);
RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
revision.review(ReviewInput.approve());
revision.submit();
ChangeNotes notes = notesFactory.create(project, r.getChange().getId());
SubmitRequirementResult result = notes.getSubmitRequirementsResult().stream().collect(MoreCollectors.onlyElement());
assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
assertThat(result.submittabilityExpressionResult().get().status()).isEqualTo(SubmitRequirementExpressionResult.Status.PASS);
assertThat(result.submittabilityExpressionResult().get().expression().expressionString()).isEqualTo("label:Code-Review=MAX");
}
}
use of com.google.gerrit.entities.SubmitRequirementResult in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirement_storedForAbandonedChanges.
@Test
public void submitRequirement_storedForAbandonedChanges() throws Exception {
for (SubmitType submitType : SubmitType.values()) {
Project.NameKey project = createProjectForPush(submitType);
TestRepository<InMemoryRepository> repo = cloneProject(project);
configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(false).build());
PushOneCommit.Result r = createChange(repo, "master", "Add a file", "foo", "content", "topic");
String changeId = r.getChangeId();
voteLabel(changeId, "Code-Review", 2);
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
false);
gApi.changes().id(r.getChangeId()).abandon();
ChangeNotes notes = notesFactory.create(project, r.getChange().getId());
SubmitRequirementResult result = notes.getSubmitRequirementsResult().stream().collect(MoreCollectors.onlyElement());
assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
assertThat(result.submittabilityExpressionResult().get().status()).isEqualTo(SubmitRequirementExpressionResult.Status.PASS);
assertThat(result.submittabilityExpressionResult().get().expression().expressionString()).isEqualTo("label:Code-Review=MAX");
}
}
use of com.google.gerrit.entities.SubmitRequirementResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method submitRequirement_alwaysApplicable.
@Test
public void submitRequirement_alwaysApplicable() {
SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
"is:true", /* submittabilityExpr= */
"is:true", /* overrideExpr= */
"");
SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
}
Aggregations