Search in sources :

Example 1 with RelatedChangeAndCommitInfo

use of com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo in project gerrit by GerritCodeReview.

the class GetRelated method getRelated.

public ImmutableList<RelatedChangeAndCommitInfo> getRelated(RevisionResource rsrc) throws IOException, PermissionBackendException {
    boolean isEdit = rsrc.getEdit().isPresent();
    PatchSet basePs = isEdit ? rsrc.getEdit().get().getBasePatchSet() : rsrc.getPatchSet();
    logger.atFine().log("isEdit = %s, basePs = %s", isEdit, basePs);
    List<RelatedChangesSorter.PatchSetData> sortedResult = getRelatedChangesUtil.getRelated(changeDataFactory.create(rsrc.getNotes()), basePs);
    List<RelatedChangeAndCommitInfo> result = new ArrayList<>(sortedResult.size());
    for (RelatedChangesSorter.PatchSetData d : sortedResult) {
        PatchSet ps = d.patchSet();
        RevCommit commit;
        if (isEdit && ps.id().equals(basePs.id())) {
            // Replace base of an edit with the edit itself.
            ps = rsrc.getPatchSet();
            commit = rsrc.getEdit().get().getEditCommit();
            logger.atFine().log("Replaced base of edit (patch set %s, commit %s) with edit (patch set %s, commit %s)", d.patchSet().id(), d.commit(), ps.id(), commit);
        } else {
            commit = d.commit();
        }
        result.add(newChangeAndCommit(rsrc.getProject(), d.data().change(), ps, commit));
    }
    if (result.size() == 1) {
        RelatedChangeAndCommitInfo r = result.get(0);
        if (r.commit != null && r.commit.commit.equals(rsrc.getPatchSet().commitId().name())) {
            return ImmutableList.of();
        }
    }
    return ImmutableList.copyOf(result);
}
Also used : RelatedChangeAndCommitInfo(com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo) RelatedChangesSorter(com.google.gerrit.server.change.RelatedChangesSorter) ArrayList(java.util.ArrayList) PatchSet(com.google.gerrit.entities.PatchSet) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with RelatedChangeAndCommitInfo

use of com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo in project gerrit by GerritCodeReview.

the class ChangeIT method rebaseOnChangeNumber.

@Test
public void rebaseOnChangeNumber() throws Exception {
    String branchTip = testRepo.getRepository().exactRef("HEAD").getObjectId().name();
    PushOneCommit.Result r1 = createChange();
    testRepo.reset("HEAD~1");
    PushOneCommit.Result r2 = createChange();
    ChangeInfo ci2 = get(r2.getChangeId(), CURRENT_REVISION, CURRENT_COMMIT);
    RevisionInfo ri2 = ci2.revisions.get(ci2.currentRevision);
    assertThat(ri2.commit.parents.get(0).commit).isEqualTo(branchTip);
    Change.Id id1 = r1.getChange().getId();
    RebaseInput in = new RebaseInput();
    in.base = id1.toString();
    gApi.changes().id(r2.getChangeId()).rebase(in);
    Change.Id id2 = r2.getChange().getId();
    ci2 = get(r2.getChangeId(), CURRENT_REVISION, CURRENT_COMMIT);
    ri2 = ci2.revisions.get(ci2.currentRevision);
    assertThat(ri2.commit.parents.get(0).commit).isEqualTo(r1.getCommit().name());
    List<RelatedChangeAndCommitInfo> related = gApi.changes().id(id2.get()).revision(ri2._number).related().changes;
    assertThat(related).hasSize(2);
    assertThat(related.get(0)._changeNumber).isEqualTo(id2.get());
    assertThat(related.get(0)._revisionNumber).isEqualTo(2);
    assertThat(related.get(1)._changeNumber).isEqualTo(id1.get());
    assertThat(related.get(1)._revisionNumber).isEqualTo(1);
}
Also used : RelatedChangeAndCommitInfo(com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) Change(com.google.gerrit.entities.Change) RebaseInput(com.google.gerrit.extensions.api.changes.RebaseInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with RelatedChangeAndCommitInfo

use of com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo in project gerrit by GerritCodeReview.

the class GetRelated method newChangeAndCommit.

static RelatedChangeAndCommitInfo newChangeAndCommit(Project.NameKey project, @Nullable Change change, @Nullable PatchSet ps, RevCommit c) {
    RelatedChangeAndCommitInfo info = new RelatedChangeAndCommitInfo();
    info.project = project.get();
    if (change != null) {
        info.changeId = change.getKey().get();
        info._changeNumber = change.getChangeId();
        info._revisionNumber = ps != null ? ps.number() : null;
        PatchSet.Id curr = change.currentPatchSetId();
        info._currentRevisionNumber = curr != null ? curr.get() : null;
        info.status = ChangeUtil.status(change).toUpperCase(Locale.US);
    }
    info.commit = new CommitInfo();
    info.commit.commit = c.name();
    info.commit.parents = Lists.newArrayListWithCapacity(c.getParentCount());
    for (int i = 0; i < c.getParentCount(); i++) {
        CommitInfo p = new CommitInfo();
        p.commit = c.getParent(i).name();
        info.commit.parents.add(p);
    }
    info.commit.author = CommonConverters.toGitPerson(c.getAuthorIdent());
    info.commit.subject = c.getShortMessage();
    return info;
}
Also used : RelatedChangeAndCommitInfo(com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo) PatchSet(com.google.gerrit.entities.PatchSet) RelatedChangeAndCommitInfo(com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo) CommitInfo(com.google.gerrit.extensions.common.CommitInfo)

Example 4 with RelatedChangeAndCommitInfo

use of com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo in project gerrit by GerritCodeReview.

the class GetRelatedIT method getRelatedManyChanges.

@Test
public void getRelatedManyChanges() throws Exception {
    List<ObjectId> commitIds = new ArrayList<>();
    for (int i = 1; i <= 5; i++) {
        commitIds.add(commitBuilder().add(i + ".txt", "i").message("subject: " + i).create().copy());
    }
    pushHead(testRepo, "refs/for/master", false);
    List<RelatedChangeAndCommitInfo> expected = new ArrayList<>(commitIds.size());
    for (ObjectId commitId : commitIds) {
        expected.add(changeAndCommit(getPatchSetId(commitId), commitId, 1));
    }
    Collections.reverse(expected);
    PatchSet.Id lastPsId = getPatchSetId(Iterables.getLast(commitIds));
    assertRelated(lastPsId, expected);
    Account.Id accountId = accountOperations.newAccount().create();
    AccountGroup.UUID groupUuid = groupOperations.newGroup().addMember(accountId).create();
    projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.QUERY_LIMIT).group(groupUuid).range(0, 2)).update();
    requestScopeOperations.setApiUser(accountId);
    assertRelated(lastPsId, expected);
}
Also used : Account(com.google.gerrit.entities.Account) RelatedChangeAndCommitInfo(com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo) AccountGroup(com.google.gerrit.entities.AccountGroup) ObjectId(org.eclipse.jgit.lib.ObjectId) ArrayList(java.util.ArrayList) PatchSet(com.google.gerrit.entities.PatchSet) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with RelatedChangeAndCommitInfo

use of com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo in project gerrit by GerritCodeReview.

the class GetRelatedIT method assertRelated.

private void assertRelated(PatchSet.Id psId, List<RelatedChangeAndCommitInfo> expected) throws Exception {
    List<RelatedChangeAndCommitInfo> actual = gApi.changes().id(psId.changeId().get()).revision(psId.get()).related().changes;
    assertWithMessage("related to " + psId).that(actual).hasSize(expected.size());
    for (int i = 0; i < actual.size(); i++) {
        String name = "index " + i + " related to " + psId;
        RelatedChangeAndCommitInfo a = actual.get(i);
        RelatedChangeAndCommitInfo e = expected.get(i);
        assertWithMessage("project of " + name).that(a.project).isEqualTo(e.project);
        assertWithMessage("change ID of " + name).that(a._changeNumber).isEqualTo(e._changeNumber);
        // Don't bother checking changeId; assume _changeNumber is sufficient.
        assertWithMessage("revision of " + name).that(a._revisionNumber).isEqualTo(e._revisionNumber);
        assertWithMessage("commit of " + name).that(a.commit.commit).isEqualTo(e.commit.commit);
        assertWithMessage("current revision of " + name).that(a._currentRevisionNumber).isEqualTo(e._currentRevisionNumber);
        assertThat(a.status).isEqualTo(e.status);
    }
}
Also used : RelatedChangeAndCommitInfo(com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo)

Aggregations

RelatedChangeAndCommitInfo (com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 PatchSet (com.google.gerrit.entities.PatchSet)3 Test (org.junit.Test)3 Change (com.google.gerrit.entities.Change)2 CommitInfo (com.google.gerrit.extensions.common.CommitInfo)2 ArrayList (java.util.ArrayList)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 Account (com.google.gerrit.entities.Account)1 AccountGroup (com.google.gerrit.entities.AccountGroup)1 RebaseInput (com.google.gerrit.extensions.api.changes.RebaseInput)1 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)1 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)1 RelatedChangesSorter (com.google.gerrit.server.change.RelatedChangesSorter)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1