Search in sources :

Example 1 with SubmitType

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

the class MergeOp method validateChangeList.

private BranchBatch validateChangeList(OpenRepo or, Collection<ChangeData> submitted) throws IntegrationException {
    logDebug("Validating {} changes", submitted.size());
    Set<CodeReviewCommit> toSubmit = new LinkedHashSet<>(submitted.size());
    SetMultimap<ObjectId, PatchSet.Id> revisions = getRevisions(or, submitted);
    SubmitType submitType = null;
    ChangeData choseSubmitTypeFrom = null;
    for (ChangeData cd : submitted) {
        Change.Id changeId = cd.getId();
        ChangeControl ctl;
        Change chg;
        try {
            ctl = cd.changeControl();
            chg = cd.change();
        } catch (OrmException e) {
            commitStatus.logProblem(changeId, e);
            continue;
        }
        SubmitType st = getSubmitType(cd);
        if (st == null) {
            commitStatus.logProblem(changeId, "No submit type for change");
            continue;
        }
        if (submitType == null) {
            submitType = st;
            choseSubmitTypeFrom = cd;
        } else if (st != submitType) {
            commitStatus.problem(changeId, String.format("Change has submit type %s, but previously chose submit type %s " + "from change %s in the same batch", st, submitType, choseSubmitTypeFrom.getId()));
            continue;
        }
        if (chg.currentPatchSetId() == null) {
            String msg = "Missing current patch set on change";
            logError(msg + " " + changeId);
            commitStatus.problem(changeId, msg);
            continue;
        }
        PatchSet ps;
        Branch.NameKey destBranch = chg.getDest();
        try {
            ps = cd.currentPatchSet();
        } catch (OrmException e) {
            commitStatus.logProblem(changeId, e);
            continue;
        }
        if (ps == null || ps.getRevision() == null || ps.getRevision().get() == null) {
            commitStatus.logProblem(changeId, "Missing patch set or revision on change");
            continue;
        }
        String idstr = ps.getRevision().get();
        ObjectId id;
        try {
            id = ObjectId.fromString(idstr);
        } catch (IllegalArgumentException e) {
            commitStatus.logProblem(changeId, e);
            continue;
        }
        if (!revisions.containsEntry(id, ps.getId())) {
            // TODO this is actually an error, the branch is gone but we
            // want to merge the issue. We can't safely do that if the
            // tip is not reachable.
            //
            commitStatus.logProblem(changeId, "Revision " + idstr + " of patch set " + ps.getPatchSetId() + " does not match " + ps.getId().toRefName() + " for change");
            continue;
        }
        CodeReviewCommit commit;
        try {
            commit = or.rw.parseCommit(id);
        } catch (IOException e) {
            commitStatus.logProblem(changeId, e);
            continue;
        }
        // TODO(dborowitz): Consider putting ChangeData in CodeReviewCommit.
        commit.setControl(ctl);
        commit.setPatchsetId(ps.getId());
        commitStatus.put(commit);
        MergeValidators mergeValidators = mergeValidatorsFactory.create();
        try {
            mergeValidators.validatePreMerge(or.repo, commit, or.project, destBranch, ps.getId(), caller);
        } catch (MergeValidationException mve) {
            commitStatus.problem(changeId, mve.getMessage());
            continue;
        }
        commit.add(or.canMergeFlag);
        toSubmit.add(commit);
    }
    logDebug("Submitting on this run: {}", toSubmit);
    return new AutoValue_MergeOp_BranchBatch(submitType, toSubmit);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) IOException(java.io.IOException) ChangeData(com.google.gerrit.server.query.change.ChangeData) MergeValidationException(com.google.gerrit.server.git.validators.MergeValidationException) OrmException(com.google.gwtorm.server.OrmException) ChangeControl(com.google.gerrit.server.project.ChangeControl) Branch(com.google.gerrit.reviewdb.client.Branch) OpenBranch(com.google.gerrit.server.git.MergeOpRepoManager.OpenBranch) SubmitType(com.google.gerrit.extensions.client.SubmitType) RequestId(com.google.gerrit.server.util.RequestId) ObjectId(org.eclipse.jgit.lib.ObjectId) MergeValidators(com.google.gerrit.server.git.validators.MergeValidators)

Example 2 with SubmitType

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

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

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

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

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