Search in sources :

Example 6 with SubmitType

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

Example 7 with SubmitType

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

the class ChangeNotificationsIT method mergeByOwnerAllSubmitStrategies.

private void mergeByOwnerAllSubmitStrategies(boolean advanceBranchBeforeSubmitting) throws Exception {
    for (SubmitType submitType : SubmitType.values()) {
        try (ProjectConfigUpdate u = updateProject(project)) {
            u.getConfig().updateProject(p -> p.setSubmitType(submitType));
            u.save();
        }
        StagedChange sc = stageChangeReadyForMerge();
        String name = submitType + " sender";
        if (advanceBranchBeforeSubmitting) {
            if (submitType == SubmitType.FAST_FORWARD_ONLY) {
                continue;
            }
            try (Repository repo = repoManager.openRepository(project);
                TestRepository<Repository> tr = new TestRepository<>(repo)) {
                tr.branch("master").commit().create();
            }
            name += " after branch has advanced";
        }
        merge(sc.changeId, sc.owner);
        assertWithMessage(name).about(fakeEmailSenders()).that(sender).sent("merged", sc).cc(sc.reviewer, sc.ccer).cc(StagedUsers.REVIEWER_BY_EMAIL, StagedUsers.CC_BY_EMAIL).bcc(sc.starrer).bcc(ALL_COMMENTS, SUBMITTED_CHANGES).noOneElse();
        assertWithMessage(name).about(fakeEmailSenders()).that(sender).didNotSend();
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) TestRepository(org.eclipse.jgit.junit.TestRepository) SubmitType(com.google.gerrit.extensions.client.SubmitType)

Example 8 with SubmitType

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

the class ProjectInfoScreen method initProjectOptions.

private void initProjectOptions() {
    grid.addHeader(new SmallHeading(AdminConstants.I.headingProjectOptions()));
    state = new ListBox();
    for (ProjectState stateValue : ProjectState.values()) {
        state.addItem(Util.toLongString(stateValue), stateValue.name());
    }
    saveEnabler.listenTo(state);
    grid.add(AdminConstants.I.headingProjectState(), state);
    submitType = new ListBox();
    for (final SubmitType type : SubmitType.values()) {
        submitType.addItem(Util.toLongString(type), type.name());
    }
    submitType.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            setEnabledForUseContentMerge();
        }
    });
    saveEnabler.listenTo(submitType);
    grid.add(AdminConstants.I.headingProjectSubmitType(), submitType);
    contentMerge = newInheritedBooleanBox();
    saveEnabler.listenTo(contentMerge);
    grid.add(AdminConstants.I.useContentMerge(), contentMerge);
    newChangeForAllNotInTarget = newInheritedBooleanBox();
    saveEnabler.listenTo(newChangeForAllNotInTarget);
    grid.add(AdminConstants.I.createNewChangeForAllNotInTarget(), newChangeForAllNotInTarget);
    requireChangeID = newInheritedBooleanBox();
    saveEnabler.listenTo(requireChangeID);
    grid.addHtml(AdminConstants.I.requireChangeID(), requireChangeID);
    if (Gerrit.info().receive().enableSignedPush()) {
        enableSignedPush = newInheritedBooleanBox();
        saveEnabler.listenTo(enableSignedPush);
        grid.add(AdminConstants.I.enableSignedPush(), enableSignedPush);
        requireSignedPush = newInheritedBooleanBox();
        saveEnabler.listenTo(requireSignedPush);
        grid.add(AdminConstants.I.requireSignedPush(), requireSignedPush);
    }
    rejectImplicitMerges = newInheritedBooleanBox();
    saveEnabler.listenTo(rejectImplicitMerges);
    grid.addHtml(AdminConstants.I.rejectImplicitMerges(), rejectImplicitMerges);
    enableReviewerByEmail = newInheritedBooleanBox();
    saveEnabler.listenTo(enableReviewerByEmail);
    grid.addHtml(AdminConstants.I.enableReviewerByEmail(), enableReviewerByEmail);
    maxObjectSizeLimit = new NpTextBox();
    saveEnabler.listenTo(maxObjectSizeLimit);
    effectiveMaxObjectSizeLimit = new Label();
    effectiveMaxObjectSizeLimit.setStyleName(Gerrit.RESOURCES.css().maxObjectSizeLimitEffectiveLabel());
    HorizontalPanel p = new HorizontalPanel();
    p.add(maxObjectSizeLimit);
    p.add(effectiveMaxObjectSizeLimit);
    grid.addHtml(AdminConstants.I.headingMaxObjectSizeLimit(), p);
}
Also used : SmallHeading(com.google.gerrit.client.ui.SmallHeading) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Label(com.google.gwt.user.client.ui.Label) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) ProjectState(com.google.gerrit.extensions.client.ProjectState) SubmitType(com.google.gerrit.extensions.client.SubmitType) ListBox(com.google.gwt.user.client.ui.ListBox) NpTextBox(com.google.gwtexpui.globalkey.client.NpTextBox)

Example 9 with SubmitType

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

the class PRED_project_default_submit_type_1 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    ProjectState projectState = StoredValues.PROJECT_STATE.get(engine);
    SubmitType submitType = projectState.getSubmitType();
    if (!a1.unify(term[submitType.ordinal()], engine.trail)) {
        return engine.fail();
    }
    return cont;
}
Also used : ProjectState(com.google.gerrit.server.project.ProjectState) SubmitType(com.google.gerrit.extensions.client.SubmitType) Term(com.googlecode.prolog_cafe.lang.Term) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm)

Example 10 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) {
    logger.atFine().log("Validating %d 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();
        ChangeNotes notes;
        Change chg;
        SubmitType st;
        try {
            notes = cd.notes();
            chg = cd.change();
            st = getSubmitType(cd);
        } catch (StorageException e) {
            commitStatus.logProblem(changeId, e);
            continue;
        }
        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";
            logger.atSevere().log("%s %s", msg, changeId);
            commitStatus.problem(changeId, msg);
            continue;
        }
        PatchSet ps;
        BranchNameKey destBranch = chg.getDest();
        try {
            ps = cd.currentPatchSet();
        } catch (StorageException e) {
            commitStatus.logProblem(changeId, e);
            continue;
        }
        if (ps == null) {
            commitStatus.logProblem(changeId, "Missing patch set on change");
            continue;
        }
        ObjectId id = ps.commitId();
        if (!revisions.containsEntry(id, ps.id())) {
            if (revisions.containsValue(ps.id())) {
                // TODO This is actually an error, the patch set ref exists but points to a revision that
                // is different from the revision that we have stored for the patch set in the change
                // meta data.
                commitStatus.logProblem(changeId, "Revision " + id.name() + " of patch set " + ps.number() + " does not match the revision of the patch set ref " + ps.id().toRefName());
                continue;
            }
            // The patch set ref is not found but we want to merge the change. We can't safely do that
            // if the patch set ref is missing. In a cluster setups with multiple primary nodes this can
            // indicate a replication lag (e.g. the change meta data was already replicated, but the
            // replication of the patch set ref is still pending).
            commitStatus.logProblem(changeId, "Patch set ref " + ps.id().toRefName() + " not found. Expected patch set ref of " + ps.number() + " to point to revision " + id.name());
            continue;
        }
        CodeReviewCommit commit;
        try {
            commit = or.rw.parseCommit(id);
        } catch (IOException e) {
            commitStatus.logProblem(changeId, e);
            continue;
        }
        commit.setNotes(notes);
        commit.setPatchsetId(ps.id());
        commitStatus.put(commit);
        MergeValidators mergeValidators = mergeValidatorsFactory.create();
        try {
            mergeValidators.validatePreMerge(or.repo, or.rw, commit, or.project, destBranch, ps.id(), caller);
        } catch (MergeValidationException mve) {
            commitStatus.problem(changeId, mve.getMessage());
            continue;
        }
        commit.add(or.canMergeFlag);
        toSubmit.add(commit);
    }
    logger.atFine().log("Submitting on this run: %s", toSubmit);
    return new AutoValue_MergeOp_BranchBatch(submitType, ImmutableSet.copyOf(toSubmit));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) CodeReviewCommit(com.google.gerrit.server.git.CodeReviewCommit) ChangeData(com.google.gerrit.server.query.change.ChangeData) MergeValidationException(com.google.gerrit.server.git.validators.MergeValidationException) BranchNameKey(com.google.gerrit.entities.BranchNameKey) SubmitType(com.google.gerrit.extensions.client.SubmitType) SubmissionId(com.google.gerrit.entities.SubmissionId) ObjectId(org.eclipse.jgit.lib.ObjectId) RequestId(com.google.gerrit.server.logging.RequestId) MergeValidators(com.google.gerrit.server.git.validators.MergeValidators) StorageException(com.google.gerrit.exceptions.StorageException)

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