use of com.google.gerrit.extensions.common.LabelDefinitionInput in project gerrit by GerritCodeReview.
the class CreateLabelIT method createWithBranches.
@Test
public void createWithBranches() throws Exception {
LabelDefinitionInput input = new LabelDefinitionInput();
input.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
// Branches can be full ref, ref pattern or regular expression.
input.branches = ImmutableList.of("refs/heads/master", "refs/heads/foo/*", "^refs/heads/stable-.*");
LabelDefinitionInfo createdLabel = gApi.projects().name(project.get()).label("Foo").create(input).get();
assertThat(createdLabel.branches).containsExactlyElementsIn(input.branches);
}
use of com.google.gerrit.extensions.common.LabelDefinitionInput in project gerrit by GerritCodeReview.
the class CreateLabelIT method functionEmptyAfterTrim.
@Test
public void functionEmptyAfterTrim() throws Exception {
LabelDefinitionInput input = new LabelDefinitionInput();
input.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
input.function = " ";
LabelDefinitionInfo createdLabel = gApi.projects().name(project.get()).label("Foo").create(input).get();
assertThat(createdLabel.function).isEqualTo(LabelFunction.MAX_WITH_BLOCK.getFunctionName());
}
use of com.google.gerrit.extensions.common.LabelDefinitionInput in project gerrit by GerritCodeReview.
the class CreateLabelIT method createWithCopyAllScoresIfNoCodeChange.
@Test
public void createWithCopyAllScoresIfNoCodeChange() throws Exception {
LabelDefinitionInput input = new LabelDefinitionInput();
input.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
input.copyAllScoresIfNoCodeChange = true;
LabelDefinitionInfo createdLabel = gApi.projects().name(project.get()).label("foo").create(input).get();
assertThat(createdLabel.copyAllScoresIfNoCodeChange).isTrue();
}
use of com.google.gerrit.extensions.common.LabelDefinitionInput in project gerrit by GerritCodeReview.
the class CreateLabelIT method createWithNameAndDescription.
@Test
public void createWithNameAndDescription() throws Exception {
LabelDefinitionInput input = new LabelDefinitionInput();
input.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
input.description = "Foo label description";
LabelDefinitionInfo createdLabel = gApi.projects().name(project.get()).label("Foo").create(input).get();
assertThat(createdLabel.name).isEqualTo("Foo");
assertThat(createdLabel.description).isEqualTo("Foo label description");
}
use of com.google.gerrit.extensions.common.LabelDefinitionInput in project gerrit by GerritCodeReview.
the class SetLabel method apply.
@Override
public Response<LabelDefinitionInfo> apply(LabelResource rsrc, LabelDefinitionInput input) throws AuthException, BadRequestException, ResourceConflictException, PermissionBackendException, IOException, ConfigInvalidException {
if (!user.get().isIdentifiedUser()) {
throw new AuthException("Authentication required");
}
permissionBackend.currentUser().project(rsrc.getProject().getNameKey()).check(ProjectPermission.WRITE_CONFIG);
if (input == null) {
input = new LabelDefinitionInput();
}
LabelType labelType = rsrc.getLabelType();
try (MetaDataUpdate md = updateFactory.create(rsrc.getProject().getNameKey())) {
ProjectConfig config = projectConfigFactory.read(md);
if (updateLabel(config, labelType, input)) {
if (input.commitMessage != null) {
md.setMessage(Strings.emptyToNull(input.commitMessage.trim()));
} else {
md.setMessage("Update label");
}
String newName = Strings.nullToEmpty(input.name).trim();
labelType = config.getLabelSections().get(newName.isEmpty() ? labelType.getName() : newName);
config.commit(md);
projectCache.evictAndReindex(rsrc.getProject().getProjectState().getProject());
}
}
return Response.ok(LabelDefinitionJson.format(rsrc.getProject().getNameKey(), labelType));
}
Aggregations