Search in sources :

Example 11 with LabelType

use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.

the class ChangeEditIT method editCommitMessageCopiesLabelScores.

@Test
public void editCommitMessageCopiesLabelScores() throws Exception {
    String cr = LabelId.CODE_REVIEW;
    try (ProjectConfigUpdate u = updateProject(project)) {
        LabelType codeReview = TestLabels.codeReview();
        u.getConfig().upsertLabelType(codeReview);
        u.getConfig().updateLabelType(codeReview.getName(), lt -> lt.setCopyAllScoresIfNoCodeChange(true));
        u.save();
    }
    ReviewInput r = new ReviewInput();
    r.labels = ImmutableMap.of(cr, (short) 1);
    gApi.changes().id(changeId).current().review(r);
    createEmptyEditFor(changeId);
    String newSubj = "New commit message";
    String newMsg = newSubj + "\n\nChange-Id: " + changeId + "\n";
    gApi.changes().id(changeId).edit().modifyCommitMessage(newMsg);
    PublishChangeEditInput publishInput = new PublishChangeEditInput();
    publishInput.notify = NotifyHandling.NONE;
    gApi.changes().id(changeId).edit().publish(publishInput);
    ChangeInfo info = get(changeId, DETAILED_LABELS);
    assertThat(info.subject).isEqualTo(newSubj);
    List<ApprovalInfo> approvals = info.labels.get(cr).all;
    assertThat(approvals).hasSize(1);
    assertThat(approvals.get(0).value).isEqualTo(1);
}
Also used : ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) LabelType(com.google.gerrit.entities.LabelType) PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with LabelType

use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.

the class SchemaCreatorImplTest method assertValueRange.

private void assertValueRange(LabelType label, Integer... range) {
    List<Integer> rangeList = Arrays.asList(range);
    assertThat(rangeList).isNotEmpty();
    assertThat(rangeList).isInStrictOrder();
    assertThat(label.getValues().stream().map(v -> (int) v.getValue())).containsExactlyElementsIn(rangeList).inOrder();
    assertThat(label.getMax().getValue()).isEqualTo(Collections.max(rangeList));
    assertThat(label.getMin().getValue()).isEqualTo(Collections.min(rangeList));
    for (LabelValue v : label.getValues()) {
        assertThat(v.getText()).isNotNull();
        assertThat(v.getText()).isNotEmpty();
    }
}
Also used : AllUsersName(com.google.gerrit.server.config.AllUsersName) GroupNameNotes(com.google.gerrit.server.group.db.GroupNameNotes) InMemoryModule(com.google.gerrit.testing.InMemoryModule) Arrays(java.util.Arrays) ProjectConfig(com.google.gerrit.server.project.ProjectConfig) Inject(com.google.inject.Inject) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ArrayList(java.util.ArrayList) GroupReference(com.google.gerrit.entities.GroupReference) LabelTypes(com.google.gerrit.entities.LabelTypes) List(java.util.List) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) ImmutableList(com.google.common.collect.ImmutableList) LabelValue(com.google.gerrit.entities.LabelValue) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) LabelType(com.google.gerrit.entities.LabelType) LabelFunction(com.google.gerrit.entities.LabelFunction) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ServiceUserClassifier(com.google.gerrit.server.account.ServiceUserClassifier) Collections(java.util.Collections) Repository(org.eclipse.jgit.lib.Repository) Before(org.junit.Before) LabelValue(com.google.gerrit.entities.LabelValue)

Example 13 with LabelType

use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.

the class SchemaCreatorImplTest method createSchema_LabelTypes.

@Test
public void createSchema_LabelTypes() throws Exception {
    List<String> labels = new ArrayList<>();
    for (LabelType label : getLabelTypes().getLabelTypes()) {
        labels.add(label.getName());
    }
    assertThat(labels).containsExactly("Code-Review");
}
Also used : LabelType(com.google.gerrit.entities.LabelType) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 14 with LabelType

use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.

the class ReviewCommand method parseCommandLine.

@Override
protected void parseCommandLine(DynamicOptions pluginOptions) throws UnloggedFailure {
    optionMap = new LinkedHashMap<>();
    customLabels = new HashMap<>();
    ProjectState allProjectsState;
    try {
        allProjectsState = projectCache.getAllProjects();
    } catch (Exception e) {
        throw die("missing " + allProjects.get(), e);
    }
    for (LabelType type : allProjectsState.getLabelTypes().getLabelTypes()) {
        StringBuilder usage = new StringBuilder("score for ").append(type.getName()).append("\n");
        for (LabelValue v : type.getValues()) {
            usage.append(v.format()).append("\n");
        }
        optionMap.put(newApproveOption(type, usage.toString()), new LabelSetter(type));
    }
    super.parseCommandLine(pluginOptions);
}
Also used : LabelValue(com.google.gerrit.entities.LabelValue) LabelType(com.google.gerrit.entities.LabelType) ProjectState(com.google.gerrit.server.project.ProjectState) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) CmdLineException(org.kohsuke.args4j.CmdLineException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) JsonSyntaxException(com.google.gson.JsonSyntaxException) StorageException(com.google.gerrit.exceptions.StorageException) IOException(java.io.IOException)

Example 15 with LabelType

use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.

the class ImpersonationIT method voteOnBehalfOfLabelNotPermitted.

@Test
public void voteOnBehalfOfLabelNotPermitted() throws Exception {
    try (ProjectConfigUpdate u = updateProject(project)) {
        LabelType verified = TestLabels.verified();
        u.getConfig().upsertLabelType(verified);
        u.save();
    }
    PushOneCommit.Result r = createChange();
    RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
    ReviewInput in = new ReviewInput();
    in.onBehalfOf = user.id().toString();
    in.label(LabelId.VERIFIED, 1);
    AuthException thrown = assertThrows(AuthException.class, () -> revision.review(in));
    assertThat(thrown).hasMessageThat().contains("not permitted to modify label \"Verified\" on behalf of \"" + in.onBehalfOf + '"');
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) LabelType(com.google.gerrit.entities.LabelType) AuthException(com.google.gerrit.extensions.restapi.AuthException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

LabelType (com.google.gerrit.entities.LabelType)71 Test (org.junit.Test)26 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)20 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)16 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)14 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)13 Map (java.util.Map)12 LabelTypes (com.google.gerrit.entities.LabelTypes)10 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)9 Account (com.google.gerrit.entities.Account)8 LabelValue (com.google.gerrit.entities.LabelValue)8 AuthException (com.google.gerrit.extensions.restapi.AuthException)8 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)8 HashMap (java.util.HashMap)8 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)7 ArrayList (java.util.ArrayList)7 LabelPermission (com.google.gerrit.server.permissions.LabelPermission)6 ProjectState (com.google.gerrit.server.project.ProjectState)6 Change (com.google.gerrit.entities.Change)5 SubmitRecord (com.google.gerrit.entities.SubmitRecord)5