Search in sources :

Example 1 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class UnfusedNoteDbBatchUpdate method newChangeContext.

private ChangeContextImpl newChangeContext(Change.Id id) throws OrmException {
    logDebug("Opening change {} for update", id);
    Change c = newChanges.get(id);
    boolean isNew = c != null;
    if (!isNew) {
        // Pass a synthetic change into ChangeNotes.Factory, which will take care of checking for
        // existence and populating columns from the parsed notes state.
        // TODO(dborowitz): This dance made more sense when using Reviewdb; consider a nicer way.
        c = ChangeNotes.Factory.newNoteDbOnlyChange(project, id);
    } else {
        logDebug("Change {} is new", id);
    }
    ChangeNotes notes = changeNotesFactory.createForBatchUpdate(c, !isNew);
    ChangeControl ctl = changeControlFactory.controlFor(notes, user);
    return new ChangeContextImpl(ctl);
}
Also used : ChangeControl(com.google.gerrit.server.project.ChangeControl) Change(com.google.gerrit.reviewdb.client.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes)

Example 2 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class FusedNoteDbBatchUpdate method newChangeContext.

private ChangeContextImpl newChangeContext(Change.Id id) throws OrmException {
    logDebug("Opening change {} for update", id);
    Change c = newChanges.get(id);
    boolean isNew = c != null;
    if (!isNew) {
        // Pass a synthetic change into ChangeNotes.Factory, which will take care of checking for
        // existence and populating columns from the parsed notes state.
        // TODO(dborowitz): This dance made more sense when using Reviewdb; consider a nicer way.
        c = ChangeNotes.Factory.newNoteDbOnlyChange(project, id);
    } else {
        logDebug("Change {} is new", id);
    }
    ChangeNotes notes = changeNotesFactory.createForBatchUpdate(c, !isNew);
    ChangeControl ctl = changeControlFactory.controlFor(notes, user);
    return new ChangeContextImpl(ctl);
}
Also used : ChangeControl(com.google.gerrit.server.project.ChangeControl) Change(com.google.gerrit.reviewdb.client.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes)

Example 3 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class ReplaceOp method fireCommentAddedEvent.

private void fireCommentAddedEvent(Context ctx) throws OrmException {
    if (approvals.isEmpty()) {
        return;
    }
    /* For labels that are not set in this operation, show the "current" value
     * of 0, and no oldValue as the value was not modified by this operation.
     * For labels that are set in this operation, the value was modified, so
     * show a transition from an oldValue of 0 to the new value.
     */
    ChangeControl changeControl = changeControlFactory.controlFor(ctx.getDb(), notes.getChange(), ctx.getUser());
    List<LabelType> labels = changeControl.getLabelTypes().getLabelTypes();
    Map<String, Short> allApprovals = new HashMap<>();
    Map<String, Short> oldApprovals = new HashMap<>();
    for (LabelType lt : labels) {
        allApprovals.put(lt.getName(), (short) 0);
        oldApprovals.put(lt.getName(), null);
    }
    for (Map.Entry<String, Short> entry : approvals.entrySet()) {
        if (entry.getValue() != 0) {
            allApprovals.put(entry.getKey(), entry.getValue());
            oldApprovals.put(entry.getKey(), (short) 0);
        }
    }
    commentAdded.fire(notes.getChange(), newPatchSet, ctx.getAccount(), null, allApprovals, oldApprovals, ctx.getWhen());
}
Also used : HashMap(java.util.HashMap) ChangeControl(com.google.gerrit.server.project.ChangeControl) LabelType(com.google.gerrit.common.data.LabelType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl 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 5 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class EventUtil method revisionInfo.

public RevisionInfo revisionInfo(Project.NameKey project, PatchSet ps) throws OrmException, PatchListNotAvailableException, GpgException, IOException {
    ChangeData cd = changeDataFactory.create(db.get(), project, ps.getId().getParentKey());
    ChangeControl ctl = cd.changeControl();
    return changeJson.getRevisionInfo(ctl, ps);
}
Also used : ChangeControl(com.google.gerrit.server.project.ChangeControl) ChangeData(com.google.gerrit.server.query.change.ChangeData)

Aggregations

ChangeControl (com.google.gerrit.server.project.ChangeControl)34 Change (com.google.gerrit.reviewdb.client.Change)11 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)9 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)7 AuthException (com.google.gerrit.extensions.restapi.AuthException)6 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)6 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)5 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)5 Project (com.google.gerrit.reviewdb.client.Project)5 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 HashMap (java.util.HashMap)5 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)4 ObjectId (org.eclipse.jgit.lib.ObjectId)4 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)4 ObjectReader (org.eclipse.jgit.lib.ObjectReader)4 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 LabelType (com.google.gerrit.common.data.LabelType)3 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)3 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)3 Branch (com.google.gerrit.reviewdb.client.Branch)3