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);
}
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);
}
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;
}
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);
}
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);
}
}
Aggregations