Search in sources :

Example 61 with LabelType

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

the class SubmitRequirementIT method submitRequirement_returnsEmpty_forMergedChangeWithPreviouslyStoredSRs.

@Test
public void submitRequirement_returnsEmpty_forMergedChangeWithPreviouslyStoredSRs() throws Exception {
    for (SubmitType submitType : SubmitType.values()) {
        Project.NameKey project = createProjectForPush(submitType);
        TestRepository<InMemoryRepository> repo = cloneProject(project);
        configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(false).build());
        PushOneCommit.Result r = createChange(repo, "master", "Add a file", "foo", "content", "topic");
        String changeId = r.getChangeId();
        // Abandon change. Submit requirements get stored in the revision note of patch-set 1.
        gApi.changes().id(changeId).abandon();
        ChangeInfo change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(1);
        assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
        false);
        // Clear SRs for the project and update code-review label to be non-blocking.
        clearSubmitRequirements(project);
        LabelType cr = TestLabels.codeReview().toBuilder().setFunction(LabelFunction.NO_BLOCK).build();
        try (ProjectConfigUpdate u = updateProject(project)) {
            u.getConfig().upsertLabelType(cr);
            u.save();
        }
        // Restore the change. No SRs apply.
        gApi.changes().id(changeId).restore();
        change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).isEmpty();
        // Merge the change. Still, no SRs apply.
        gApi.changes().id(changeId).current().submit();
        change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).isEmpty();
    }
}
Also used : Project(com.google.gerrit.entities.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) LabelType(com.google.gerrit.entities.LabelType) SubmitType(com.google.gerrit.extensions.client.SubmitType) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 62 with LabelType

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

the class SubmitRequirementIT method legacySubmitRequirementWithIgnoreSelfApproval.

@Test
public void legacySubmitRequirementWithIgnoreSelfApproval() throws Exception {
    LabelType verified = label(LabelId.VERIFIED, value(1, "Passes"), value(0, "No score"), value(-1, "Failed"));
    verified = verified.toBuilder().setIgnoreSelfApproval(true).build();
    try (ProjectConfigUpdate u = updateProject(project)) {
        u.getConfig().upsertLabelType(verified);
        u.save();
    }
    projectOperations.project(project).forUpdate().add(allowLabel(verified.getName()).ref(RefNames.REFS_HEADS + "*").group(REGISTERED_USERS).range(-1, 1)).update();
    // The DefaultSubmitRule emits an "OK" submit record for Verified, while the
    // ignoreSelfApprovalRule emits a "NEED" submit record. The "submit requirements" adapter merges
    // both results and returns the blocking one only.
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    gApi.changes().id(changeId).addReviewer(user.id().toString());
    voteLabel(changeId, verified.getName(), +1);
    ChangeInfo changeInfo = gApi.changes().id(changeId).get();
    Collection<SubmitRequirementResultInfo> submitRequirements = changeInfo.submitRequirements;
    assertSubmitRequirementStatus(submitRequirements, "Verified", Status.UNSATISFIED, /* isLegacy= */
    true);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) LabelType(com.google.gerrit.entities.LabelType) SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 63 with LabelType

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

the class LabelTypeSerializerTest method roundTripWithMinimalValues.

@Test
public void roundTripWithMinimalValues() {
    LabelType autoValue = ALL_VALUES_SET.toBuilder().setRefPatterns(null).setCopyCondition(null).build();
    assertThat(deserialize(serialize(autoValue))).isEqualTo(autoValue);
}
Also used : LabelType(com.google.gerrit.entities.LabelType) Test(org.junit.Test)

Example 64 with LabelType

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

the class ProjectConfigTest method readConfigLabelOldStyleWithLeadingSpace.

@Test
public void readConfigLabelOldStyleWithLeadingSpace() throws Exception {
    RevCommit rev = tr.commit().add("groups", group(developers)).add("project.config", "[label \"CustomLabel\"]\n" + "  value = -1 Negative\n" + // Leading space before 0.
    "  value =  0 No Score\n" + "  value =  1 Positive\n").create();
    ProjectConfig cfg = read(rev);
    Map<String, LabelType> labels = cfg.getLabelSections();
    Short dv = labels.entrySet().iterator().next().getValue().getDefaultValue();
    assertThat((int) dv).isEqualTo(0);
}
Also used : LabelType(com.google.gerrit.entities.LabelType) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 65 with LabelType

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

the class ProjectConfigTest method readConfigLabelDefaultValueInRange.

@Test
public void readConfigLabelDefaultValueInRange() throws Exception {
    RevCommit rev = tr.commit().add("groups", group(developers)).add("project.config", "[label \"CustomLabel\"]\n" + "  value = -1 Negative\n" + "  value = 0 No Score\n" + "  value =  1 Positive\n" + "  defaultValue = -1\n").create();
    ProjectConfig cfg = read(rev);
    Map<String, LabelType> labels = cfg.getLabelSections();
    Short dv = labels.entrySet().iterator().next().getValue().getDefaultValue();
    assertThat((int) dv).isEqualTo(-1);
}
Also used : LabelType(com.google.gerrit.entities.LabelType) RevCommit(org.eclipse.jgit.revwalk.RevCommit) 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