use of com.google.gerrit.entities.SubmitRequirement in project gerrit by GerritCodeReview.
the class ProjectConfig method loadSubmitRequirementSections.
private void loadSubmitRequirementSections(Config rc) {
checkForUnsupportedSubmitRequirementParams(rc);
Map<String, String> lowerNames = new HashMap<>();
submitRequirementSections = new LinkedHashMap<>();
for (String name : rc.getSubsections(SUBMIT_REQUIREMENT)) {
String lower = name.toLowerCase();
if (lowerNames.containsKey(lower)) {
error(String.format("Submit requirement '%s' conflicts with '%s'.", name, lowerNames.get(lower)));
continue;
}
lowerNames.put(lower, name);
String description = rc.getString(SUBMIT_REQUIREMENT, name, KEY_SR_DESCRIPTION);
String applicabilityExpr = rc.getString(SUBMIT_REQUIREMENT, name, KEY_SR_APPLICABILITY_EXPRESSION);
String submittabilityExpr = rc.getString(SUBMIT_REQUIREMENT, name, KEY_SR_SUBMITTABILITY_EXPRESSION);
String overrideExpr = rc.getString(SUBMIT_REQUIREMENT, name, KEY_SR_OVERRIDE_EXPRESSION);
boolean canInherit;
try {
canInherit = rc.getBoolean(SUBMIT_REQUIREMENT, name, KEY_SR_OVERRIDE_IN_CHILD_PROJECTS, false);
} catch (IllegalArgumentException e) {
String canInheritValue = rc.getString(SUBMIT_REQUIREMENT, name, KEY_SR_OVERRIDE_IN_CHILD_PROJECTS);
error(String.format("Invalid value %s.%s.%s for submit requirement '%s': %s", SUBMIT_REQUIREMENT, name, KEY_SR_OVERRIDE_IN_CHILD_PROJECTS, name, canInheritValue));
continue;
}
if (submittabilityExpr == null) {
error(String.format("Setting a submittability expression for submit requirement '%s' is required:" + " Missing %s.%s.%s", name, SUBMIT_REQUIREMENT, name, KEY_SR_SUBMITTABILITY_EXPRESSION));
continue;
}
// The expressions are validated in SubmitRequirementExpressionsValidator.
SubmitRequirement submitRequirement = SubmitRequirement.builder().setName(name).setDescription(Optional.ofNullable(description)).setApplicabilityExpression(SubmitRequirementExpression.of(applicabilityExpr)).setSubmittabilityExpression(SubmitRequirementExpression.create(submittabilityExpr)).setOverrideExpression(SubmitRequirementExpression.of(overrideExpr)).setAllowOverrideInChildProjects(canInherit).build();
submitRequirementSections.put(name, submitRequirement);
}
}
use of com.google.gerrit.entities.SubmitRequirement in project gerrit by GerritCodeReview.
the class ProjectConfig method saveSubmitRequirementSections.
private void saveSubmitRequirementSections(Config rc) {
unsetSection(rc, SUBMIT_REQUIREMENT);
if (submitRequirementSections != null) {
for (Map.Entry<String, SubmitRequirement> entry : submitRequirementSections.entrySet()) {
String name = entry.getKey();
SubmitRequirement sr = entry.getValue();
if (sr.description().isPresent()) {
rc.setString(SUBMIT_REQUIREMENT, name, KEY_SR_DESCRIPTION, sr.description().get());
}
if (sr.applicabilityExpression().isPresent()) {
rc.setString(SUBMIT_REQUIREMENT, name, KEY_SR_APPLICABILITY_EXPRESSION, sr.applicabilityExpression().get().expressionString());
}
rc.setString(SUBMIT_REQUIREMENT, name, KEY_SR_SUBMITTABILITY_EXPRESSION, sr.submittabilityExpression().expressionString());
if (sr.overrideExpression().isPresent()) {
rc.setString(SUBMIT_REQUIREMENT, name, KEY_SR_OVERRIDE_EXPRESSION, sr.overrideExpression().get().expressionString());
}
rc.setBoolean(SUBMIT_REQUIREMENT, name, KEY_SR_OVERRIDE_IN_CHILD_PROJECTS, sr.allowOverrideInChildProjects());
}
}
}
use of com.google.gerrit.entities.SubmitRequirement in project gerrit by GerritCodeReview.
the class ProjectState method getSubmitRequirements.
/**
* Get all submit requirements for a project, including those from parent projects.
*/
public Map<String, SubmitRequirement> getSubmitRequirements() {
Map<String, SubmitRequirement> requirements = new LinkedHashMap<>();
for (ProjectState s : treeInOrder()) {
for (SubmitRequirement requirement : s.getConfig().getSubmitRequirementSections().values()) {
String lowerName = requirement.name().toLowerCase();
SubmitRequirement old = requirements.get(lowerName);
if (old == null || old.allowOverrideInChildProjects()) {
requirements.put(lowerName, requirement);
}
}
}
return ImmutableMap.copyOf(requirements);
}
use of com.google.gerrit.entities.SubmitRequirement in project gerrit by GerritCodeReview.
the class SubmitRequirementExpressionsValidator method validateSubmitRequirementExpressions.
private ImmutableList<CommitValidationMessage> validateSubmitRequirementExpressions(Collection<SubmitRequirement> submitRequirements) {
List<CommitValidationMessage> validationMessages = new ArrayList<>();
for (SubmitRequirement submitRequirement : submitRequirements) {
validateSubmitRequirementExpression(validationMessages, submitRequirement, submitRequirement.submittabilityExpression(), ProjectConfig.KEY_SR_SUBMITTABILITY_EXPRESSION);
submitRequirement.applicabilityExpression().ifPresent(expression -> validateSubmitRequirementExpression(validationMessages, submitRequirement, expression, ProjectConfig.KEY_SR_APPLICABILITY_EXPRESSION));
submitRequirement.overrideExpression().ifPresent(expression -> validateSubmitRequirementExpression(validationMessages, submitRequirement, expression, ProjectConfig.KEY_SR_OVERRIDE_EXPRESSION));
}
return ImmutableList.copyOf(validationMessages);
}
use of com.google.gerrit.entities.SubmitRequirement in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method projectSubmitRequirementDuplicatesGlobal_overrideNotAllowed_globalEvaluated.
@Test
public void projectSubmitRequirementDuplicatesGlobal_overrideNotAllowed_globalEvaluated() throws Exception {
SubmitRequirement globalSubmitRequirement = SubmitRequirement.builder().setName("CoDe-reView").setSubmittabilityExpression(SubmitRequirementExpression.create("topic:test")).setAllowOverrideInChildProjects(false).build();
try (Registration registration = extensionRegistry.newRegistration().add(globalSubmitRequirement)) {
configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(false).build());
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
// Vote does not satisfy submit requirement, because the global definition is evaluated.
voteLabel(changeId, "CoDe-reView", 2);
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(2);
assertSubmitRequirementStatus(change.submitRequirements, "CoDe-reView", Status.UNSATISFIED, /* isLegacy= */
false);
// In addition, the legacy submit requirement is emitted, since the status mismatch
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
true);
// Setting the topic satisfies the global definition.
gApi.changes().id(changeId).topic("test");
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "CoDe-reView", Status.SATISFIED, /* isLegacy= */
false);
}
}
Aggregations