Search in sources :

Example 51 with LabelDefinitionInfo

use of com.google.gerrit.extensions.common.LabelDefinitionInfo 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());
}
Also used : LabelDefinitionInfo(com.google.gerrit.extensions.common.LabelDefinitionInfo) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 52 with LabelDefinitionInfo

use of com.google.gerrit.extensions.common.LabelDefinitionInfo 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();
}
Also used : LabelDefinitionInfo(com.google.gerrit.extensions.common.LabelDefinitionInfo) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 53 with LabelDefinitionInfo

use of com.google.gerrit.extensions.common.LabelDefinitionInfo 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");
}
Also used : LabelDefinitionInfo(com.google.gerrit.extensions.common.LabelDefinitionInfo) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 54 with LabelDefinitionInfo

use of com.google.gerrit.extensions.common.LabelDefinitionInfo in project gerrit by GerritCodeReview.

the class LabelDefinitionJson method format.

public static LabelDefinitionInfo format(Project.NameKey projectName, LabelType labelType) {
    LabelDefinitionInfo label = new LabelDefinitionInfo();
    label.name = labelType.getName();
    label.description = labelType.getDescription().orElse(null);
    label.projectName = projectName.get();
    label.function = labelType.getFunction().getFunctionName();
    label.values = labelType.getValues().stream().collect(toMap(LabelValue::formatValue, LabelValue::getText));
    label.defaultValue = labelType.getDefaultValue();
    label.branches = labelType.getRefPatterns() != null ? labelType.getRefPatterns() : null;
    label.canOverride = toBoolean(labelType.isCanOverride());
    label.copyCondition = labelType.getCopyCondition().orElse(null);
    label.copyAnyScore = toBoolean(labelType.isCopyAnyScore());
    label.copyMinScore = toBoolean(labelType.isCopyMinScore());
    label.copyMaxScore = toBoolean(labelType.isCopyMaxScore());
    label.copyAllScoresIfListOfFilesDidNotChange = toBoolean(labelType.isCopyAllScoresIfListOfFilesDidNotChange());
    label.copyAllScoresIfNoChange = toBoolean(labelType.isCopyAllScoresIfNoChange());
    label.copyAllScoresIfNoCodeChange = toBoolean(labelType.isCopyAllScoresIfNoCodeChange());
    label.copyAllScoresOnTrivialRebase = toBoolean(labelType.isCopyAllScoresOnTrivialRebase());
    label.copyAllScoresOnMergeFirstParentUpdate = toBoolean(labelType.isCopyAllScoresOnMergeFirstParentUpdate());
    label.copyValues = labelType.getCopyValues().isEmpty() ? null : labelType.getCopyValues();
    label.allowPostSubmit = toBoolean(labelType.isAllowPostSubmit());
    label.ignoreSelfApproval = toBoolean(labelType.isIgnoreSelfApproval());
    return label;
}
Also used : LabelValue(com.google.gerrit.entities.LabelValue) LabelDefinitionInfo(com.google.gerrit.extensions.common.LabelDefinitionInfo)

Example 55 with LabelDefinitionInfo

use of com.google.gerrit.extensions.common.LabelDefinitionInfo in project gerrit by GerritCodeReview.

the class ListLabels method listLabels.

private List<LabelDefinitionInfo> listLabels(ProjectState projectState) {
    Collection<LabelType> labelTypes = projectState.getConfig().getLabelSections().values();
    List<LabelDefinitionInfo> labels = new ArrayList<>(labelTypes.size());
    for (LabelType labelType : labelTypes) {
        labels.add(LabelDefinitionJson.format(projectState.getNameKey(), labelType));
    }
    labels.sort(Comparator.comparing(l -> l.name));
    return labels;
}
Also used : PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) RestReadView(com.google.gerrit.extensions.restapi.RestReadView) CurrentUser(com.google.gerrit.server.CurrentUser) Inject(com.google.inject.Inject) Collection(java.util.Collection) ProjectState(com.google.gerrit.server.project.ProjectState) ProjectResource(com.google.gerrit.server.project.ProjectResource) Option(org.kohsuke.args4j.Option) Response(com.google.gerrit.extensions.restapi.Response) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) LabelDefinitionJson(com.google.gerrit.server.project.LabelDefinitionJson) ArrayList(java.util.ArrayList) ProjectPermission(com.google.gerrit.server.permissions.ProjectPermission) Provider(com.google.inject.Provider) List(java.util.List) LabelType(com.google.gerrit.entities.LabelType) AuthException(com.google.gerrit.extensions.restapi.AuthException) Comparator(java.util.Comparator) LabelDefinitionInfo(com.google.gerrit.extensions.common.LabelDefinitionInfo) LabelType(com.google.gerrit.entities.LabelType) LabelDefinitionInfo(com.google.gerrit.extensions.common.LabelDefinitionInfo) ArrayList(java.util.ArrayList)

Aggregations

LabelDefinitionInfo (com.google.gerrit.extensions.common.LabelDefinitionInfo)93 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)91 Test (org.junit.Test)91 LabelDefinitionInput (com.google.gerrit.extensions.common.LabelDefinitionInput)79 BatchLabelInput (com.google.gerrit.extensions.common.BatchLabelInput)3 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)2 LabelType (com.google.gerrit.entities.LabelType)1 LabelValue (com.google.gerrit.entities.LabelValue)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 Response (com.google.gerrit.extensions.restapi.Response)1 RestReadView (com.google.gerrit.extensions.restapi.RestReadView)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 ProjectPermission (com.google.gerrit.server.permissions.ProjectPermission)1 LabelDefinitionJson (com.google.gerrit.server.project.LabelDefinitionJson)1 ProjectResource (com.google.gerrit.server.project.ProjectResource)1 ProjectState (com.google.gerrit.server.project.ProjectState)1 Inject (com.google.inject.Inject)1 Provider (com.google.inject.Provider)1