Search in sources :

Example 31 with BatchUpdate

use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method newPatchSet.

protected Change newPatchSet(TestRepository<Repo> repo, Change c) throws Exception {
    // Add a new file so the patch set is not a trivial rebase, to avoid default
    // Code-Review label copying.
    int n = c.currentPatchSetId().get() + 1;
    RevCommit commit = repo.parseBody(repo.commit().message("message").add("file" + n, "contents " + n).create());
    ChangeControl ctl = changeControlFactory.controlFor(db, c, user);
    PatchSetInserter inserter = patchSetFactory.create(ctl, new PatchSet.Id(c.getId(), n), commit).setNotify(NotifyHandling.NONE).setFireRevisionCreated(false).setValidate(false);
    try (BatchUpdate bu = updateFactory.create(db, c.getProject(), user, TimeUtil.nowTs());
        ObjectInserter oi = repo.getRepository().newObjectInserter();
        ObjectReader reader = oi.newReader();
        RevWalk rw = new RevWalk(reader)) {
        bu.setRepository(repo.getRepository(), rw, oi);
        bu.addOp(c.getId(), inserter);
        bu.execute();
    }
    return inserter.getChange();
}
Also used : ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) PatchSetInserter(com.google.gerrit.server.change.PatchSetInserter) ChangeControl(com.google.gerrit.server.project.ChangeControl) ObjectReader(org.eclipse.jgit.lib.ObjectReader) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ObjectId(org.eclipse.jgit.lib.ObjectId) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 32 with BatchUpdate

use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.

the class ReviewProjectAccess method updateProjectConfig.

// TODO(dborowitz): Hack MetaDataUpdate so it can be created within a BatchUpdate and we can avoid
// calling setUpdateRef(false).
@SuppressWarnings("deprecation")
@Override
protected Change.Id updateProjectConfig(ProjectControl projectControl, ProjectConfig config, MetaDataUpdate md, boolean parentProjectUpdate) throws IOException, OrmException, PermissionDeniedException {
    RefControl refsMetaConfigControl = projectControl.controlForRef(RefNames.REFS_CONFIG);
    if (!refsMetaConfigControl.isVisible()) {
        throw new PermissionDeniedException(RefNames.REFS_CONFIG + " not visible");
    }
    if (!projectControl.isOwner() && !refsMetaConfigControl.canUpload()) {
        throw new PermissionDeniedException("cannot upload to " + RefNames.REFS_CONFIG);
    }
    md.setInsertChangeId(true);
    Change.Id changeId = new Change.Id(seq.nextChangeId());
    RevCommit commit = config.commitToNewRef(md, new PatchSet.Id(changeId, Change.INITIAL_PATCH_SET_ID).toRefName());
    if (commit.getId().equals(base)) {
        return null;
    }
    try (ObjectInserter objInserter = md.getRepository().newObjectInserter();
        ObjectReader objReader = objInserter.newReader();
        RevWalk rw = new RevWalk(objReader);
        BatchUpdate bu = updateFactory.create(db, config.getProject().getNameKey(), projectControl.getUser(), TimeUtil.nowTs())) {
        bu.setRepository(md.getRepository(), rw, objInserter);
        bu.insertChange(changeInserterFactory.create(changeId, commit, RefNames.REFS_CONFIG).setValidate(false).setUpdateRef(// Created by commitToNewRef.
        false));
        bu.execute();
    } catch (UpdateException | RestApiException e) {
        throw new IOException(e);
    }
    ChangeResource rsrc;
    try {
        rsrc = changes.parse(changeId);
    } catch (ResourceNotFoundException e) {
        throw new IOException(e);
    }
    addProjectOwnersAsReviewers(rsrc);
    if (parentProjectUpdate) {
        addAdministratorsAsReviewers(rsrc);
    }
    return changeId;
}
Also used : RefControl(com.google.gerrit.server.project.RefControl) Change(com.google.gerrit.reviewdb.client.Change) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) ChangeResource(com.google.gerrit.server.change.ChangeResource) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) PermissionDeniedException(com.google.gerrit.common.errors.PermissionDeniedException) ObjectReader(org.eclipse.jgit.lib.ObjectReader) ObjectId(org.eclipse.jgit.lib.ObjectId) UpdateException(com.google.gerrit.server.update.UpdateException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 33 with BatchUpdate

use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.

the class ChangeIT method setChangeStatus.

private void setChangeStatus(Change.Id id, Change.Status newStatus) throws Exception {
    try (BatchUpdate batchUpdate = batchUpdateFactory.create(db, project, atrScope.get().getUser(), TimeUtil.nowTs())) {
        batchUpdate.addOp(id, new ChangeStatusUpdateOp(newStatus));
        batchUpdate.execute();
    }
    ChangeStatus changeStatus = gApi.changes().id(id.get()).get().status;
    assertThat(changeStatus).isEqualTo(newStatus.asChangeStatus());
}
Also used : ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 34 with BatchUpdate

use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.

the class DraftChangeIT method setDraftStatusOfPatchSetsOfChange.

private void setDraftStatusOfPatchSetsOfChange(Change.Id id, boolean draftStatus) throws Exception {
    try (BatchUpdate batchUpdate = batchUpdateFactory.create(db, project, atrScope.get().getUser(), TimeUtil.nowTs())) {
        batchUpdate.addOp(id, new DraftStatusOfPatchSetsUpdateOp(draftStatus));
        batchUpdate.execute();
    }
    Boolean expectedDraftStatus = draftStatus ? Boolean.TRUE : null;
    List<Boolean> patchSetDraftStatuses = getPatchSetDraftStatuses(id);
    patchSetDraftStatuses.forEach(status -> assertThat(status).isEqualTo(expectedDraftStatus));
}
Also used : BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 35 with BatchUpdate

use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method mergedChangeIsNotMerged.

@Test
public void mergedChangeIsNotMerged() throws Exception {
    ChangeControl ctl = insertChange();
    try (BatchUpdate bu = newUpdate(adminId)) {
        bu.addOp(ctl.getId(), new BatchUpdateOp() {

            @Override
            public boolean updateChange(ChangeContext ctx) throws OrmException {
                ctx.getChange().setStatus(Change.Status.MERGED);
                ctx.getUpdate(ctx.getChange().currentPatchSetId()).fixStatus(Change.Status.MERGED);
                return true;
            }
        });
        bu.execute();
    }
    ctl = reload(ctl);
    String rev = psUtil.current(db, ctl.getNotes()).getRevision().get();
    ObjectId tip = getDestRef(ctl);
    assertProblems(ctl, null, problem("Patch set 1 (" + rev + ") is not merged into destination ref" + " refs/heads/master (" + tip.name() + "), but change status is MERGED"));
}
Also used : ChangeContext(com.google.gerrit.server.update.ChangeContext) OrmException(com.google.gwtorm.server.OrmException) ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeControl(com.google.gerrit.server.project.ChangeControl) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

BatchUpdate (com.google.gerrit.server.update.BatchUpdate)54 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)26 Change (com.google.gerrit.reviewdb.client.Change)22 ObjectId (org.eclipse.jgit.lib.ObjectId)14 OrmException (com.google.gwtorm.server.OrmException)13 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)12 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)12 UpdateException (com.google.gerrit.server.update.UpdateException)12 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)11 ChangeControl (com.google.gerrit.server.project.ChangeControl)11 ChangeContext (com.google.gerrit.server.update.ChangeContext)11 AuthException (com.google.gerrit.extensions.restapi.AuthException)10 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)10 ObjectReader (org.eclipse.jgit.lib.ObjectReader)10 Repository (org.eclipse.jgit.lib.Repository)9 RevWalk (org.eclipse.jgit.revwalk.RevWalk)9 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)8 IOException (java.io.IOException)8 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)7