Search in sources :

Example 6 with SubmitRequirementResultInfo

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

the class SubmitRequirementIT method submitRequirements_eliminatesMultipleDuplicatesForLegacyMatchingSRs.

@Test
public void submitRequirements_eliminatesMultipleDuplicatesForLegacyMatchingSRs() throws Exception {
    // If a custom/prolog submit rule emits the same label name multiple times, we merge these into
    // a single submit requirement result: in this test, we have five different submit rules that
    // return the same label name, all with an "OK" status. The submit requirements API returns
    // a single SR result with status=SATISFIED.
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    try (Registration registration = extensionRegistry.newRegistration()) {
        IntStream.range(0, 5).forEach(i -> registration.add(createSubmitRule("r" + i, SubmitRecord.Status.OK, "CR", SubmitRecord.Label.Status.OK)));
        ChangeInfo change = gApi.changes().id(changeId).get();
        Collection<SubmitRequirementResultInfo> submitRequirements = change.submitRequirements;
        assertThat(submitRequirements).hasSize(2);
        assertSubmitRequirementStatus(submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
        true);
        assertSubmitRequirementStatus(submitRequirements, "CR", Status.SATISFIED, /* isLegacy= */
        true);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 7 with SubmitRequirementResultInfo

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

the class SubmitRequirementsJson method toInfo.

public static SubmitRequirementResultInfo toInfo(SubmitRequirement req, SubmitRequirementResult result) {
    SubmitRequirementResultInfo info = new SubmitRequirementResultInfo();
    info.name = req.name();
    info.description = req.description().orElse(null);
    if (req.applicabilityExpression().isPresent()) {
        info.applicabilityExpressionResult = submitRequirementExpressionToInfo(req.applicabilityExpression().get(), result.applicabilityExpressionResult().get(), /* hide= */
        true);
    // Always hide applicability expressions on the API
    }
    if (req.overrideExpression().isPresent() && result.overrideExpressionResult().isPresent()) {
        info.overrideExpressionResult = submitRequirementExpressionToInfo(req.overrideExpression().get(), result.overrideExpressionResult().get(), /* hide= */
        false);
    }
    if (result.submittabilityExpressionResult().isPresent()) {
        info.submittabilityExpressionResult = submitRequirementExpressionToInfo(req.submittabilityExpression(), result.submittabilityExpressionResult().get(), /* hide= */
        false);
    }
    info.status = SubmitRequirementResultInfo.Status.valueOf(result.status().toString());
    info.isLegacy = result.isLegacy();
    return info;
}
Also used : SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo)

Example 8 with SubmitRequirementResultInfo

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

the class SubmitRequirementIT method submitRequirements_disallowsTheIsSubmittableOperator.

@Test
public void submitRequirements_disallowsTheIsSubmittableOperator() throws Exception {
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    configSubmitRequirement(project, SubmitRequirement.builder().setName("Wrong-Req").setSubmittabilityExpression(SubmitRequirementExpression.create("is:submittable")).setAllowOverrideInChildProjects(false).build());
    ChangeInfo change = gApi.changes().id(changeId).get();
    SubmitRequirementResultInfo srResult = change.submitRequirements.stream().filter(sr -> sr.name.equals("Wrong-Req")).collect(MoreCollectors.onlyElement());
    assertThat(srResult.status).isEqualTo(Status.ERROR);
    assertThat(srResult.submittabilityExpressionResult.errorMessage).isEqualTo("Operator 'is:submittable' cannot be used in submit requirement expressions.");
}
Also used : Status(com.google.gerrit.extensions.common.SubmitRequirementResultInfo.Status) Arrays(java.util.Arrays) ProjectConfig(com.google.gerrit.server.project.ProjectConfig) Inject(com.google.inject.Inject) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) RevObject(org.eclipse.jgit.revwalk.RevObject) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) LegacySubmitRequirement(com.google.gerrit.entities.LegacySubmitRequirement) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) LabelType(com.google.gerrit.entities.LabelType) Map(java.util.Map) RefNames(com.google.gerrit.entities.RefNames) SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) TestProjectUpdate(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) MoreCollectors(com.google.common.collect.MoreCollectors) SubmitType(com.google.gerrit.extensions.client.SubmitType) Collection(java.util.Collection) VerifyNoPiiInChangeNotes(com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) RawParseUtils(org.eclipse.jgit.util.RawParseUtils) TestLabels.label(com.google.gerrit.server.project.testing.TestLabels.label) TestLabels.value(com.google.gerrit.server.project.testing.TestLabels.value) SubmitRecord(com.google.gerrit.entities.SubmitRecord) NoHttpd(com.google.gerrit.acceptance.NoHttpd) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) Ref(org.eclipse.jgit.lib.Ref) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) TestProjectUpdate.allowLabel(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowLabel) IndexPreloadingUtil(com.google.gerrit.httpd.raw.IndexPreloadingUtil) IntStream(java.util.stream.IntStream) GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) TestLabels(com.google.gerrit.server.project.testing.TestLabels) UseTimezone(com.google.gerrit.acceptance.UseTimezone) ImmutableList(com.google.common.collect.ImmutableList) LabelFunction(com.google.gerrit.entities.LabelFunction) SubmitRequirementInput(com.google.gerrit.extensions.common.SubmitRequirementInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) SubmitRecordInfo(com.google.gerrit.extensions.common.SubmitRecordInfo) ActionInfo(com.google.gerrit.extensions.common.ActionInfo) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) TestRepository(org.eclipse.jgit.junit.TestRepository) SubmitRule(com.google.gerrit.server.rules.SubmitRule) Permission(com.google.gerrit.entities.Permission) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) LegacySubmitRequirementInfo(com.google.gerrit.extensions.common.LegacySubmitRequirementInfo) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Project(com.google.gerrit.entities.Project) Repository(org.eclipse.jgit.lib.Repository) SubmitRequirementExpressionInfo(com.google.gerrit.extensions.common.SubmitRequirementExpressionInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 9 with SubmitRequirementResultInfo

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

the class SubmitRequirementIT method submitRequirement_emptyApplicable_submittabilityAndOverrideEvaluated.

@Test
public void submitRequirement_emptyApplicable_submittabilityAndOverrideEvaluated() throws Exception {
    configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setApplicabilityExpression(Optional.empty()).setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setOverrideExpression(SubmitRequirementExpression.of("project:non-existent")).setAllowOverrideInChildProjects(false).build());
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    voteLabel(changeId, "Code-Review", 2);
    ChangeInfo changeInfo = gApi.changes().id(changeId).get();
    assertSubmitRequirementStatus(changeInfo.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
    false);
    SubmitRequirementResultInfo requirement = changeInfo.submitRequirements.stream().collect(MoreCollectors.onlyElement());
    assertThat(requirement.applicabilityExpressionResult).isNull();
    assertSubmitRequirementExpression(requirement.submittabilityExpressionResult, /* expression= */
    SubmitRequirementExpression.maxCodeReview().expressionString(), /* passingAtoms= */
    ImmutableList.of(SubmitRequirementExpression.maxCodeReview().expressionString()), /* failingAtoms= */
    ImmutableList.of(), /* fulfilled= */
    true);
    assertSubmitRequirementExpression(requirement.overrideExpressionResult, /* expression= */
    "project:non-existent", /* passingAtoms= */
    ImmutableList.of(), /* failingAtoms= */
    ImmutableList.of("project:non-existent"), /* fulfilled= */
    false);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 10 with SubmitRequirementResultInfo

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

the class SubmitRequirementIT method checkSubmitRequirement_notApplicable.

@Test
public void checkSubmitRequirement_notApplicable() throws Exception {
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    SubmitRequirementInput in = createSubmitRequirementInput("Code-Review", /* applicableIf= */
    "branch:non-existent", /* submittableIf= */
    "label:Code-Review=+2", /* overrideIf= */
    null);
    SubmitRequirementResultInfo result = gApi.changes().id(changeId).checkSubmitRequirement(in);
    assertThat(result.status).isEqualTo(SubmitRequirementResultInfo.Status.NOT_APPLICABLE);
    voteLabel(changeId, "Code-Review", 2);
    result = gApi.changes().id(changeId).checkSubmitRequirement(in);
    assertThat(result.status).isEqualTo(SubmitRequirementResultInfo.Status.NOT_APPLICABLE);
}
Also used : SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) SubmitRequirementInput(com.google.gerrit.extensions.common.SubmitRequirementInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

SubmitRequirementResultInfo (com.google.gerrit.extensions.common.SubmitRequirementResultInfo)17 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)16 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 Test (org.junit.Test)16 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)12 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)8 SubmitRequirementInput (com.google.gerrit.extensions.common.SubmitRequirementInput)7 SubmitRule (com.google.gerrit.server.rules.SubmitRule)7 LabelType (com.google.gerrit.entities.LabelType)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Iterables (com.google.common.collect.Iterables)3 MoreCollectors (com.google.common.collect.MoreCollectors)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 ExtensionRegistry (com.google.gerrit.acceptance.ExtensionRegistry)3 NoHttpd (com.google.gerrit.acceptance.NoHttpd)3 UseTimezone (com.google.gerrit.acceptance.UseTimezone)3 VerifyNoPiiInChangeNotes (com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes)3