Search in sources :

Example 6 with SubmitRequirementResult

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

the class MergeOp method checkSubmitRequirements.

public static void checkSubmitRequirements(ChangeData cd) throws ResourceConflictException {
    PatchSet patchSet = cd.currentPatchSet();
    if (patchSet == null) {
        throw new ResourceConflictException("missing current patch set for change " + cd.getId());
    }
    Map<SubmitRequirement, SubmitRequirementResult> srResults = cd.submitRequirementsIncludingLegacy();
    if (srResults.values().stream().allMatch(SubmitRequirementResult::fulfilled)) {
        return;
    } else if (srResults.isEmpty()) {
        throw new IllegalStateException(String.format("Submit requirement results for change '%s' and patchset '%s' " + "are empty in project '%s'", cd.getId(), patchSet.id(), cd.change().getProject().get()));
    }
    for (SubmitRequirementResult srResult : srResults.values()) {
        switch(srResult.status()) {
            case SATISFIED:
            case NOT_APPLICABLE:
            case OVERRIDDEN:
            case FORCED:
                break;
            case ERROR:
                throw new ResourceConflictException(String.format("submit requirement '%s' has an error: %s", srResult.submitRequirement().name(), srResult.errorMessage().orElse("")));
            case UNSATISFIED:
                throw new ResourceConflictException(String.format("submit requirement '%s' is unsatisfied.", srResult.submitRequirement().name()));
            default:
                throw new IllegalStateException(String.format("Unexpected submit requirement status %s for %s in %s", srResult.status().name(), patchSet.id().getId(), cd.change().getProject().get()));
        }
    }
    throw new IllegalStateException();
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) PatchSet(com.google.gerrit.entities.PatchSet) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult)

Example 7 with SubmitRequirementResult

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

the class ChangeField method formatSubmitRequirementValues.

/**
 * Generate submit requirement result formats that are compatible with the legacy submit record
 * statuses.
 */
@VisibleForTesting
static List<String> formatSubmitRequirementValues(Collection<SubmitRequirementResult> srResults) {
    List<String> result = new ArrayList<>();
    for (SubmitRequirementResult srResult : srResults) {
        switch(srResult.status()) {
            case SATISFIED:
            case OVERRIDDEN:
            case FORCED:
                result.add(SubmitRecord.Label.Status.OK.name() + "," + srResult.submitRequirement().name().toLowerCase());
                result.add(SubmitRecord.Label.Status.MAY.name() + "," + srResult.submitRequirement().name().toLowerCase());
                break;
            case UNSATISFIED:
                result.add(SubmitRecord.Label.Status.NEED.name() + "," + srResult.submitRequirement().name().toLowerCase());
                result.add(SubmitRecord.Label.Status.REJECT.name() + "," + srResult.submitRequirement().name().toLowerCase());
                break;
            case NOT_APPLICABLE:
            case ERROR:
                result.add(SubmitRecord.Label.Status.IMPOSSIBLE.name() + "," + srResult.submitRequirement().name().toLowerCase());
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with SubmitRequirementResult

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

the class SubmitRequirementIT method submitRequirement_storedForClosedChanges.

@Test
public void submitRequirement_storedForClosedChanges() 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();
        voteLabel(changeId, "Code-Review", 2);
        ChangeInfo change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(1);
        assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
        false);
        RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
        revision.review(ReviewInput.approve());
        revision.submit();
        ChangeNotes notes = notesFactory.create(project, r.getChange().getId());
        SubmitRequirementResult result = notes.getSubmitRequirementsResult().stream().collect(MoreCollectors.onlyElement());
        assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
        assertThat(result.submittabilityExpressionResult().get().status()).isEqualTo(SubmitRequirementExpressionResult.Status.PASS);
        assertThat(result.submittabilityExpressionResult().get().expression().expressionString()).isEqualTo("label:Code-Review=MAX");
    }
}
Also used : Project(com.google.gerrit.entities.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) SubmitType(com.google.gerrit.extensions.client.SubmitType) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) VerifyNoPiiInChangeNotes(com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 9 with SubmitRequirementResult

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

the class SubmitRequirementIT method submitRequirement_storedForAbandonedChanges.

@Test
public void submitRequirement_storedForAbandonedChanges() 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();
        voteLabel(changeId, "Code-Review", 2);
        ChangeInfo change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(1);
        assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
        false);
        gApi.changes().id(r.getChangeId()).abandon();
        ChangeNotes notes = notesFactory.create(project, r.getChange().getId());
        SubmitRequirementResult result = notes.getSubmitRequirementsResult().stream().collect(MoreCollectors.onlyElement());
        assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
        assertThat(result.submittabilityExpressionResult().get().status()).isEqualTo(SubmitRequirementExpressionResult.Status.PASS);
        assertThat(result.submittabilityExpressionResult().get().expression().expressionString()).isEqualTo("label:Code-Review=MAX");
    }
}
Also used : Project(com.google.gerrit.entities.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) SubmitType(com.google.gerrit.extensions.client.SubmitType) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) VerifyNoPiiInChangeNotes(com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 10 with SubmitRequirementResult

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

the class SubmitRequirementsEvaluatorIT method submitRequirement_alwaysApplicable.

@Test
public void submitRequirement_alwaysApplicable() {
    SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
    "is:true", /* submittabilityExpr= */
    "is:true", /* overrideExpr= */
    "");
    SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
    assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

SubmitRequirementResult (com.google.gerrit.entities.SubmitRequirementResult)47 Test (org.junit.Test)36 SubmitRequirement (com.google.gerrit.entities.SubmitRequirement)27 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)21 SubmitRecord (com.google.gerrit.entities.SubmitRecord)14 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)5 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)5 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)5 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 Map (java.util.Map)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)3 VerifyNoPiiInChangeNotes (com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes)3 Project (com.google.gerrit.entities.Project)3 Label (com.google.gerrit.entities.SubmitRecord.Label)3 SubmitType (com.google.gerrit.extensions.client.SubmitType)3 HashMap (java.util.HashMap)3 Optional (java.util.Optional)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3