use of com.google.gerrit.extensions.common.LabelDefinitionInput in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirement_overrideOverideExpression.
@Test
public void submitRequirement_overrideOverideExpression() throws Exception {
// Define submit requirement in root project.
configSubmitRequirement(allProjects, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.create("label:Code-Review=+1")).setOverrideExpression(SubmitRequirementExpression.of("label:build-cop-override=+1")).setAllowOverrideInChildProjects(true).build());
// Create Code-Review-Override label
LabelDefinitionInput input = new LabelDefinitionInput();
input.function = "NoOp";
input.values = ImmutableMap.of("+1", "Override", " 0", "No Override");
gApi.projects().name(project.get()).label("Code-Review-Override").create(input).get();
// Allow to vote on the Code-Review-Override label.
projectOperations.project(project).forUpdate().add(TestProjectUpdate.allowLabel("Code-Review-Override").range(0, 1).ref("refs/*").group(REGISTERED_USERS).build()).update();
// Override submit requirement in project (requires Code-Review-Override+1 as override instead
// of build-cop-override+1).
configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.create("label:Code-Review=+1")).setOverrideExpression(SubmitRequirementExpression.of("label:Code-Review-Override=+1")).setAllowOverrideInChildProjects(false).build());
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
false);
voteLabel(changeId, "Code-Review-Override", 1);
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(2);
// Code-Review-Override+1 was enough to fulfill the override expression of the requirement
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.OVERRIDDEN, /* isLegacy= */
false);
// Legacy requirement is coming from the label MaxWithBlock function. Still unsatisfied.
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
true);
}
use of com.google.gerrit.extensions.common.LabelDefinitionInput in project gerrit by GerritCodeReview.
the class PostLabels method apply.
@Override
public Response<?> apply(ProjectResource rsrc, BatchLabelInput input) throws AuthException, UnprocessableEntityException, PermissionBackendException, IOException, ConfigInvalidException, BadRequestException, ResourceConflictException {
if (!user.get().isIdentifiedUser()) {
throw new AuthException("Authentication required");
}
permissionBackend.currentUser().project(rsrc.getNameKey()).check(ProjectPermission.WRITE_CONFIG);
if (input == null) {
input = new BatchLabelInput();
}
try (MetaDataUpdate md = updateFactory.create(rsrc.getNameKey())) {
boolean dirty = false;
ProjectConfig config = projectConfigFactory.read(md);
if (input.delete != null && !input.delete.isEmpty()) {
for (String labelName : input.delete) {
if (!deleteLabel.deleteLabel(config, labelName.trim())) {
throw new UnprocessableEntityException(String.format("label %s not found", labelName));
}
}
dirty = true;
}
if (input.create != null && !input.create.isEmpty()) {
for (LabelDefinitionInput labelInput : input.create) {
if (labelInput.name == null || labelInput.name.trim().isEmpty()) {
throw new BadRequestException("label name is required for new label");
}
if (labelInput.commitMessage != null) {
throw new BadRequestException("commit message on label definition input not supported");
}
createLabel.createLabel(config, labelInput.name.trim(), labelInput);
}
dirty = true;
}
if (input.update != null && !input.update.isEmpty()) {
for (Map.Entry<String, LabelDefinitionInput> e : input.update.entrySet()) {
LabelType labelType = config.getLabelSections().get(e.getKey().trim());
if (labelType == null) {
throw new UnprocessableEntityException(String.format("label %s not found", e.getKey()));
}
if (e.getValue().commitMessage != null) {
throw new BadRequestException("commit message on label definition input not supported");
}
setLabel.updateLabel(config, labelType, e.getValue());
}
dirty = true;
}
if (input.commitMessage != null) {
md.setMessage(Strings.emptyToNull(input.commitMessage.trim()));
} else {
md.setMessage("Update labels");
}
if (dirty) {
config.commit(md);
projectCache.evictAndReindex(rsrc.getProjectState().getProject());
}
}
return Response.ok("");
}
use of com.google.gerrit.extensions.common.LabelDefinitionInput in project gerrit by GerritCodeReview.
the class CreateLabel method apply.
@Override
public Response<LabelDefinitionInfo> apply(ProjectResource rsrc, IdString id, LabelDefinitionInput input) throws AuthException, BadRequestException, ResourceConflictException, PermissionBackendException, IOException, ConfigInvalidException {
if (!user.get().isIdentifiedUser()) {
throw new AuthException("Authentication required");
}
permissionBackend.currentUser().project(rsrc.getNameKey()).check(ProjectPermission.WRITE_CONFIG);
if (input == null) {
input = new LabelDefinitionInput();
}
if (input.name != null && !input.name.equals(id.get())) {
throw new BadRequestException("name in input must match name in URL");
}
try (MetaDataUpdate md = updateFactory.create(rsrc.getNameKey())) {
ProjectConfig config = projectConfigFactory.read(md);
LabelType labelType = createLabel(config, id.get(), input);
if (input.commitMessage != null) {
md.setMessage(Strings.emptyToNull(input.commitMessage.trim()));
} else {
md.setMessage("Update label");
}
config.commit(md);
projectCache.evictAndReindex(rsrc.getProjectState().getProject());
return Response.created(LabelDefinitionJson.format(rsrc.getNameKey(), labelType));
}
}
use of com.google.gerrit.extensions.common.LabelDefinitionInput in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirement_partiallyOverriddenSRIsIgnored.
@Test
public void submitRequirement_partiallyOverriddenSRIsIgnored() throws Exception {
// Create build-cop-override label
LabelDefinitionInput input = new LabelDefinitionInput();
input.function = "NoOp";
input.values = ImmutableMap.of("+1", "Override", " 0", "No Override");
gApi.projects().name(project.get()).label("build-cop-override").create(input).get();
// Allow to vote on the build-cop-override label.
projectOperations.project(project).forUpdate().add(TestProjectUpdate.allowLabel("build-cop-override").range(0, 1).ref("refs/*").group(REGISTERED_USERS).build()).update();
// Define submit requirement in root project.
configSubmitRequirement(allProjects, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.create("label:Code-Review=+1")).setOverrideExpression(SubmitRequirementExpression.of("label:build-cop-override=+1")).setAllowOverrideInChildProjects(true).build());
// Create Code-Review-Override label
gApi.projects().name(project.get()).label("Code-Review-Override").create(input).get();
// Allow to vote on the Code-Review-Override label.
projectOperations.project(project).forUpdate().add(TestProjectUpdate.allowLabel("Code-Review-Override").range(0, 1).ref("refs/*").group(REGISTERED_USERS).build()).update();
// Override submit requirement in project (requires Code-Review-Override+1 as override instead
// of build-cop-override+1), but do not set all required properties (submittability expression
// is missing). We update the project.config file directly in the remote repository, since
// trying to push such a submit requirement would be rejected by the commit validation.
projectOperations.project(project).forInvalidation().addProjectConfigUpdater(config -> config.setString(ProjectConfig.SUBMIT_REQUIREMENT, "Code-Review", ProjectConfig.KEY_SR_OVERRIDE_EXPRESSION, "label:Code-Review-Override=+1")).invalidate();
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
false);
voteLabel(changeId, "Code-Review-Override", 1);
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
// The override expression in the project is satisfied, but it's ignored since the SR is
// incomplete.
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
false);
voteLabel(changeId, "build-cop-override", 1);
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(2);
// The submit requirement is overridden now (the override expression in the child project is
// ignored)
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.OVERRIDDEN, /* isLegacy= */
false);
// Legacy requirement is coming from the label MaxWithBlock function. Still unsatisfied.
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
true);
}
use of com.google.gerrit.extensions.common.LabelDefinitionInput in project gerrit by GerritCodeReview.
the class CreateLabelIT method createWithCopyAnyScore.
@Test
public void createWithCopyAnyScore() throws Exception {
LabelDefinitionInput input = new LabelDefinitionInput();
input.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
input.copyAnyScore = true;
LabelDefinitionInfo createdLabel = gApi.projects().name(project.get()).label("foo").create(input).get();
assertThat(createdLabel.copyAnyScore).isTrue();
}
Aggregations