Search in sources :

Example 11 with ChangeContext

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

the class PrivateChangeIT method markMergedChangePrivate.

private void markMergedChangePrivate(Change.Id changeId) throws Exception {
    try (BatchUpdate u = batchUpdateFactory.create(project, identifiedUserFactory.create(admin.id()), TimeUtil.now())) {
        u.addOp(changeId, new BatchUpdateOp() {

            @Override
            public boolean updateChange(ChangeContext ctx) {
                ctx.getChange().setPrivate(true);
                ChangeUpdate update = ctx.getUpdate(ctx.getChange().currentPatchSetId());
                ctx.getChange().setPrivate(true);
                ctx.getChange().setLastUpdatedOn(ctx.getWhen());
                update.setPrivate(true);
                return true;
            }
        }).execute();
    }
    assertThat(gApi.changes().id(changeId.get()).get().isPrivate).isTrue();
}
Also used : ChangeContext(com.google.gerrit.server.update.ChangeContext) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) ChangeUpdate(com.google.gerrit.server.notedb.ChangeUpdate)

Example 12 with ChangeContext

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

the class ConsistencyCheckerIT method mergedChangeIsNotMerged.

@Test
public void mergedChangeIsNotMerged() throws Exception {
    ChangeNotes notes = insertChange();
    try (BatchUpdate bu = newUpdate(adminId)) {
        bu.addOp(notes.getChangeId(), new BatchUpdateOp() {

            @Override
            public boolean updateChange(ChangeContext ctx) {
                ctx.getChange().setStatus(Change.Status.MERGED);
                ctx.getUpdate(ctx.getChange().currentPatchSetId()).fixStatusToMerged(new SubmissionId(ctx.getChange()));
                return true;
            }
        });
        bu.execute();
    }
    notes = reload(notes);
    ObjectId tip = getDestRef(notes);
    assertProblems(notes, null, problem("Patch set 1 (" + psUtil.current(notes).commitId().name() + ") 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) ObjectId(org.eclipse.jgit.lib.ObjectId) SubmissionId(com.google.gerrit.entities.SubmissionId) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 13 with ChangeContext

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

the class ConsistencyCheckerIT method mergeChange.

private ChangeNotes mergeChange(ChangeNotes notes) throws Exception {
    ObjectId oldId = getDestRef(notes);
    ObjectId newId = psUtil.current(notes).commitId();
    String dest = notes.getChange().getDest().branch();
    try (BatchUpdate bu = newUpdate(adminId)) {
        bu.addOp(notes.getChangeId(), new BatchUpdateOp() {

            @Override
            public void updateRepo(RepoContext ctx) throws IOException {
                ctx.addRefUpdate(oldId, newId, dest);
            }

            @Override
            public boolean updateChange(ChangeContext ctx) {
                ctx.getChange().setStatus(Change.Status.MERGED);
                ctx.getUpdate(ctx.getChange().currentPatchSetId()).fixStatusToMerged(new SubmissionId(ctx.getChange()));
                return true;
            }
        });
        bu.execute();
    }
    return reload(notes);
}
Also used : RepoContext(com.google.gerrit.server.update.RepoContext) ChangeContext(com.google.gerrit.server.update.ChangeContext) ObjectId(org.eclipse.jgit.lib.ObjectId) SubmissionId(com.google.gerrit.entities.SubmissionId) IOException(java.io.IOException) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp)

Aggregations

ChangeContext (com.google.gerrit.server.update.ChangeContext)13 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)12 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)11 ObjectId (org.eclipse.jgit.lib.ObjectId)5 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)4 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)4 OrmException (com.google.gwtorm.server.OrmException)4 IOException (java.io.IOException)4 Test (org.junit.Test)4 Change (com.google.gerrit.entities.Change)3 Change (com.google.gerrit.reviewdb.client.Change)3 RepoContext (com.google.gerrit.server.update.RepoContext)3 Account (com.google.gerrit.entities.Account)2 SubmissionId (com.google.gerrit.entities.SubmissionId)2 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)2 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)2 ChangeUpdate (com.google.gerrit.server.notedb.ChangeUpdate)2 ChangeData (com.google.gerrit.server.query.change.ChangeData)2 UpdateException (com.google.gerrit.server.update.UpdateException)2