Search in sources :

Example 1 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.

the class RobotCommentsIT method queryChangesWithUnresolvedCommentCount.

@Test
public void queryChangesWithUnresolvedCommentCount() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    PushOneCommit.Result r1 = createChange();
    PushOneCommit.Result r2 = pushFactory.create(db, admin.getIdent(), testRepo, SUBJECT, FILE_NAME, "new content", r1.getChangeId()).to("refs/for/master");
    addRobotComment(r2.getChangeId(), createRobotCommentInputWithMandatoryFields());
    AcceptanceTestRequestScope.Context ctx = disableDb();
    try {
        ChangeInfo result = Iterables.getOnlyElement(query(r2.getChangeId()));
        // currently, we create all robot comments as 'resolved' by default.
        // if we allow users to resolve a robot comment, then this test should
        // be modified.
        assertThat(result.unresolvedCommentCount).isEqualTo(0);
    } finally {
        enableDb(ctx);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AcceptanceTestRequestScope(com.google.gerrit.acceptance.AcceptanceTestRequestScope) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.

the class StickyApprovalsIT method cherryPick.

private String cherryPick(String changeId, ChangeKind changeKind) throws Exception {
    switch(changeKind) {
        case REWORK:
        case TRIVIAL_REBASE:
            break;
        case NO_CODE_CHANGE:
        case NO_CHANGE:
        case MERGE_FIRST_PARENT_UPDATE:
        default:
            fail("unexpected change kind: " + changeKind);
    }
    testRepo.reset(getRemoteHead());
    PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "other.txt", "new content " + System.nanoTime()).to("refs/for/master");
    r.assertOkStatus();
    vote(admin, r.getChangeId(), 2, 1);
    merge(r);
    String subject = TRIVIAL_REBASE.equals(changeKind) ? PushOneCommit.SUBJECT : "Reworked change " + System.nanoTime();
    CherryPickInput in = new CherryPickInput();
    in.destination = "master";
    in.message = String.format("%s\n\nChange-Id: %s", subject, changeId);
    ChangeInfo c = gApi.changes().id(changeId).revision("current").cherryPick(in).get();
    return c.changeId;
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit)

Example 3 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.

the class ChangeIT method checkLabelsForAbandonedChange.

@Test
public void checkLabelsForAbandonedChange() throws Exception {
    PushOneCommit.Result r = createChange();
    gApi.changes().id(r.getChangeId()).abandon();
    ChangeInfo change = gApi.changes().id(r.getChangeId()).get();
    assertThat(change.status).isEqualTo(ChangeStatus.ABANDONED);
    assertThat(change.labels).isEmpty();
    assertThat(change.permittedLabels).isEmpty();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.

the class AbstractSubmitByMerge method repairChangeStateAfterFailure.

@Test
public void repairChangeStateAfterFailure() throws Exception {
    // In NoteDb-only mode, repo and meta updates are atomic (at least in InMemoryRepository).
    assume().that(notesMigration.disableChangeReviewDb()).isFalse();
    RevCommit initialHead = getRemoteHead();
    PushOneCommit.Result change = createChange("Change 1", "a.txt", "content");
    submit(change.getChangeId());
    RevCommit afterChange1Head = getRemoteHead();
    testRepo.reset(initialHead);
    PushOneCommit.Result change2 = createChange("Change 2", "b.txt", "other content");
    Change.Id id2 = change2.getChange().getId();
    SubmitInput failAfterRefUpdates = new TestSubmitInput(new SubmitInput(), true);
    submit(change2.getChangeId(), failAfterRefUpdates, ResourceConflictException.class, "Failing after ref updates");
    // Bad: ref advanced but change wasn't updated.
    PatchSet.Id psId1 = new PatchSet.Id(id2, 1);
    ChangeInfo info = gApi.changes().id(id2.get()).get();
    assertThat(info.status).isEqualTo(ChangeStatus.NEW);
    assertThat(info.revisions.get(info.currentRevision)._number).isEqualTo(1);
    RevCommit tip;
    try (Repository repo = repoManager.openRepository(project);
        RevWalk rw = new RevWalk(repo)) {
        ObjectId rev1 = repo.exactRef(psId1.toRefName()).getObjectId();
        assertThat(rev1).isNotNull();
        tip = rw.parseCommit(repo.exactRef("refs/heads/master").getObjectId());
        assertThat(tip.getParentCount()).isEqualTo(2);
        assertThat(tip.getParent(0)).isEqualTo(afterChange1Head);
        assertThat(tip.getParent(1)).isEqualTo(change2.getCommit());
    }
    submit(change2.getChangeId(), new SubmitInput(), null, null);
    // Change status and patch set entities were updated, and branch tip stayed
    // the same.
    info = gApi.changes().id(id2.get()).get();
    assertThat(info.status).isEqualTo(ChangeStatus.MERGED);
    assertThat(info.revisions.get(info.currentRevision)._number).isEqualTo(1);
    assertThat(Iterables.getLast(info.messages).message).isEqualTo("Change has been successfully merged by Administrator");
    try (Repository repo = repoManager.openRepository(project)) {
        assertThat(repo.exactRef("refs/heads/master").getObjectId()).isEqualTo(tip);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) TestSubmitInput(com.google.gerrit.server.change.Submit.TestSubmitInput) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) TestSubmitInput(com.google.gerrit.server.change.Submit.TestSubmitInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 5 with ChangeInfo

use of com.google.gerrit.extensions.common.ChangeInfo in project gerrit by GerritCodeReview.

the class AbstractSubmitByRebase method repairChangeStateAfterFailure.

@Test
public void repairChangeStateAfterFailure() throws Exception {
    // In NoteDb-only mode, repo and meta updates are atomic (at least in InMemoryRepository).
    assume().that(notesMigration.disableChangeReviewDb()).isFalse();
    RevCommit initialHead = getRemoteHead();
    PushOneCommit.Result change = createChange("Change 1", "a.txt", "content");
    submit(change.getChangeId());
    RevCommit headAfterFirstSubmit = getRemoteHead();
    testRepo.reset(initialHead);
    PushOneCommit.Result change2 = createChange("Change 2", "b.txt", "other content");
    Change.Id id2 = change2.getChange().getId();
    SubmitInput failAfterRefUpdates = new TestSubmitInput(new SubmitInput(), true);
    submit(change2.getChangeId(), failAfterRefUpdates, ResourceConflictException.class, "Failing after ref updates");
    RevCommit headAfterFailedSubmit = getRemoteHead();
    // Bad: ref advanced but change wasn't updated.
    PatchSet.Id psId1 = new PatchSet.Id(id2, 1);
    PatchSet.Id psId2 = new PatchSet.Id(id2, 2);
    ChangeInfo info = gApi.changes().id(id2.get()).get();
    assertThat(info.status).isEqualTo(ChangeStatus.NEW);
    assertThat(info.revisions.get(info.currentRevision)._number).isEqualTo(1);
    assertThat(getPatchSet(psId2)).isNull();
    ObjectId rev2;
    try (Repository repo = repoManager.openRepository(project);
        RevWalk rw = new RevWalk(repo)) {
        ObjectId rev1 = repo.exactRef(psId1.toRefName()).getObjectId();
        assertThat(rev1).isNotNull();
        rev2 = repo.exactRef(psId2.toRefName()).getObjectId();
        assertThat(rev2).isNotNull();
        assertThat(rev2).isNotEqualTo(rev1);
        assertThat(rw.parseCommit(rev2).getParent(0)).isEqualTo(headAfterFirstSubmit);
        assertThat(repo.exactRef("refs/heads/master").getObjectId()).isEqualTo(rev2);
    }
    submit(change2.getChangeId());
    RevCommit headAfterSecondSubmit = getRemoteHead();
    assertThat(headAfterSecondSubmit).isEqualTo(headAfterFailedSubmit);
    // Change status and patch set entities were updated, and branch tip stayed
    // the same.
    info = gApi.changes().id(id2.get()).get();
    assertThat(info.status).isEqualTo(ChangeStatus.MERGED);
    assertThat(info.revisions.get(info.currentRevision)._number).isEqualTo(2);
    PatchSet ps2 = getPatchSet(psId2);
    assertThat(ps2).isNotNull();
    assertThat(ps2.getRevision().get()).isEqualTo(rev2.name());
    assertThat(Iterables.getLast(info.messages).message).isEqualTo("Change has been successfully rebased and submitted as " + rev2.name() + " by Administrator");
    try (Repository repo = repoManager.openRepository(project)) {
        assertThat(repo.exactRef("refs/heads/master").getObjectId()).isEqualTo(rev2);
    }
    assertRefUpdatedEvents(initialHead, headAfterFirstSubmit);
    assertChangeMergedEvents(change.getChangeId(), headAfterFirstSubmit.name(), change2.getChangeId(), headAfterSecondSubmit.name());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) TestSubmitInput(com.google.gerrit.server.change.Submit.TestSubmitInput) Repository(org.eclipse.jgit.lib.Repository) GitUtil.getChangeId(com.google.gerrit.acceptance.GitUtil.getChangeId) ObjectId(org.eclipse.jgit.lib.ObjectId) TestSubmitInput(com.google.gerrit.server.change.Submit.TestSubmitInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)504 Test (org.junit.Test)434 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)393 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)276 Change (com.google.gerrit.entities.Change)73 RevCommit (org.eclipse.jgit.revwalk.RevCommit)67 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)52 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)50 Project (com.google.gerrit.entities.Project)45 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)45 ChangeInput (com.google.gerrit.extensions.common.ChangeInput)36 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)36 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)35 Repository (org.eclipse.jgit.lib.Repository)35 CommitInfo (com.google.gerrit.extensions.common.CommitInfo)32 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)32 TestRepository (org.eclipse.jgit.junit.TestRepository)32 ObjectId (org.eclipse.jgit.lib.ObjectId)30 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)29 List (java.util.List)29