Search in sources :

Example 61 with Project

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

the class SubmitRequirementIT method submitRequirement_retrievedFromNoteDbForAbandonedChanges.

@Test
public void submitRequirement_retrievedFromNoteDbForAbandonedChanges() 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);
        gApi.changes().id(changeId).abandon();
        // Add another submit requirement. This will not get returned for the abandoned change, since
        // we return the state of the SR results when the change was abandoned.
        configSubmitRequirement(project, SubmitRequirement.builder().setName("New-Requirement").setSubmittabilityExpression(SubmitRequirementExpression.create("-has:unresolved")).setAllowOverrideInChildProjects(false).build());
        ChangeInfo changeInfo = gApi.changes().id(changeId).get(ListChangesOption.SUBMIT_REQUIREMENTS);
        assertThat(changeInfo.submitRequirements).hasSize(1);
        assertSubmitRequirementStatus(changeInfo.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
        false, /* submittabilityCondition= */
        "label:Code-Review=MAX");
        // Restore the change, the new requirement will show up
        gApi.changes().id(changeId).restore();
        changeInfo = gApi.changes().id(changeId).get(ListChangesOption.SUBMIT_REQUIREMENTS);
        assertThat(changeInfo.submitRequirements).hasSize(2);
        assertSubmitRequirementStatus(changeInfo.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
        false, /* submittabilityCondition= */
        "label:Code-Review=MAX");
        assertSubmitRequirementStatus(changeInfo.submitRequirements, "New-Requirement", Status.SATISFIED, /* isLegacy= */
        false, /* submittabilityCondition= */
        "-has:unresolved");
        // Abandon again, make sure the new requirement was persisted
        gApi.changes().id(changeId).abandon();
        changeInfo = gApi.changes().id(changeId).get(ListChangesOption.SUBMIT_REQUIREMENTS);
        assertThat(changeInfo.submitRequirements).hasSize(2);
        assertSubmitRequirementStatus(changeInfo.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
        false, /* submittabilityCondition= */
        "label:Code-Review=MAX");
        assertSubmitRequirementStatus(changeInfo.submitRequirements, "New-Requirement", Status.SATISFIED, /* isLegacy= */
        false, /* submittabilityCondition= */
        "-has:unresolved");
    }
}
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) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 62 with Project

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

the class SubmitRequirementIT method submitRequirement_overriden_submittabilityEvaluated.

@Test
public void submitRequirement_overriden_submittabilityEvaluated() throws Exception {
    configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setApplicabilityExpression(Optional.empty()).setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setOverrideExpression(SubmitRequirementExpression.of("project:" + project.get())).setAllowOverrideInChildProjects(false).build());
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    voteLabel(changeId, "Code-Review", 1);
    ChangeInfo changeInfo = gApi.changes().id(changeId).get();
    assertSubmitRequirementStatus(changeInfo.submitRequirements, "Code-Review", Status.OVERRIDDEN, /* isLegacy= */
    false);
    SubmitRequirementResultInfo requirement = changeInfo.submitRequirements.stream().filter(sr -> !sr.isLegacy).collect(MoreCollectors.onlyElement());
    assertThat(requirement.applicabilityExpressionResult).isNull();
    assertSubmitRequirementExpression(requirement.submittabilityExpressionResult, /* expression= */
    SubmitRequirementExpression.maxCodeReview().expressionString(), /* passingAtoms= */
    ImmutableList.of(), /* failingAtoms= */
    ImmutableList.of(SubmitRequirementExpression.maxCodeReview().expressionString()), /* fulfilled= */
    false);
    assertSubmitRequirementExpression(requirement.overrideExpressionResult, /* expression= */
    "project:" + project.get(), /* passingAtoms= */
    ImmutableList.of("project:" + project.get()), /* failingAtoms= */
    ImmutableList.of(), /* fulfilled= */
    true);
}
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 63 with Project

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

the class SubmitRequirementIT method submitRequirement_loadedFromTheLatestRevisionNoteForClosedChanges.

@Test
public void submitRequirement_loadedFromTheLatestRevisionNoteForClosedChanges() 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);
        // Restore the change.
        gApi.changes().id(changeId).restore();
        change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(1);
        assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
        false);
        // Upload a second patch-set, fulfill the CR submit requirement.
        amendChange(changeId, "refs/for/master", user, repo);
        change = gApi.changes().id(changeId).get();
        assertThat(change.revisions).hasSize(2);
        voteLabel(changeId, "Code-Review", 2);
        change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(1);
        assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
        false);
        // Abandon the change.
        gApi.changes().id(changeId).abandon();
        change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(1);
        assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
        false);
    }
}
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) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 64 with Project

use of com.google.gerrit.entities.Project 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 65 with Project

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

the class SubmitRequirementIT method submitRequirement_returnsEmpty_forAbandonedChangeWithPreviouslyStoredSRs.

@Test
public void submitRequirement_returnsEmpty_forAbandonedChangeWithPreviouslyStoredSRs() 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();
        // Abandon the change. Still, no SRs apply.
        gApi.changes().id(changeId).abandon();
        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)

Aggregations

Project (com.google.gerrit.entities.Project)184 Test (org.junit.Test)109 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)67 Change (com.google.gerrit.entities.Change)43 Repository (org.eclipse.jgit.lib.Repository)34 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)33 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)32 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)31 BranchNameKey (com.google.gerrit.entities.BranchNameKey)30 Config (org.eclipse.jgit.lib.Config)26 ObjectId (org.eclipse.jgit.lib.ObjectId)26 IOException (java.io.IOException)25 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)24 ProjectState (com.google.gerrit.server.project.ProjectState)23 Inject (com.google.inject.Inject)23 List (java.util.List)23 AuthException (com.google.gerrit.extensions.restapi.AuthException)22 ChangeData (com.google.gerrit.server.query.change.ChangeData)22 RevCommit (org.eclipse.jgit.revwalk.RevCommit)22 PatchSet (com.google.gerrit.entities.PatchSet)20