Search in sources :

Example 11 with SubmitType

use of com.google.gerrit.extensions.client.SubmitType in project gerrit by GerritCodeReview.

the class SubmitRequirementIT method submitRequirement_abandonRestoreUpdateMerge.

@Test
public void submitRequirement_abandonRestoreUpdateMerge() 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);
        // Update the change.
        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);
        // Merge the change.
        gApi.changes().id(changeId).current().submit();
        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 12 with SubmitType

use of com.google.gerrit.extensions.client.SubmitType 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 13 with SubmitType

use of com.google.gerrit.extensions.client.SubmitType in project gerrit by GerritCodeReview.

the class SubmitRequirementIT method submitRequirement_withMultipleAbandonAndRestore.

@Test
public void submitRequirement_withMultipleAbandonAndRestore() 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);
        // Abandon the change again.
        gApi.changes().id(changeId).abandon();
        change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(1);
        assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
        false);
        // Restore, vote CR=+2, and abandon again. Make sure the requirement is now satisfied.
        gApi.changes().id(changeId).restore();
        voteLabel(changeId, "Code-Review", 2);
        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)

Aggregations

SubmitType (com.google.gerrit.extensions.client.SubmitType)13 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)8 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)8 Project (com.google.gerrit.entities.Project)8 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)8 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)8 Test (org.junit.Test)8 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)3 VerifyNoPiiInChangeNotes (com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes)2 LabelType (com.google.gerrit.entities.LabelType)2 SubmitRequirementResult (com.google.gerrit.entities.SubmitRequirementResult)2 MergeValidationException (com.google.gerrit.server.git.validators.MergeValidationException)2 MergeValidators (com.google.gerrit.server.git.validators.MergeValidators)2 ChangeData (com.google.gerrit.server.query.change.ChangeData)2 IOException (java.io.IOException)2 LinkedHashSet (java.util.LinkedHashSet)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 SmallHeading (com.google.gerrit.client.ui.SmallHeading)1 BranchNameKey (com.google.gerrit.entities.BranchNameKey)1 Change (com.google.gerrit.entities.Change)1