use of com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo in project gerrit by GerritCodeReview.
the class SubmittedTogetherIT method hiddenDraftInTopic.
@Test
public void hiddenDraftInTopic() throws Exception {
RevCommit initialHead = getRemoteHead();
RevCommit a = commitBuilder().add("a", "1").message("change 1").create();
pushHead(testRepo, "refs/for/master/" + name("topic"), false);
String id1 = getChangeId(a);
testRepo.reset(initialHead);
commitBuilder().add("b", "2").message("invisible change").create();
pushHead(testRepo, "refs/drafts/master/" + name("topic"), false);
setApiUser(user);
SubmittedTogetherInfo result = gApi.changes().id(id1).submittedTogether(EnumSet.of(NON_VISIBLE_CHANGES));
if (isSubmitWholeTopicEnabled()) {
assertThat(result.changes).hasSize(1);
assertThat(result.changes.get(0).changeId).isEqualTo(id1);
assertThat(result.nonVisibleChanges).isEqualTo(1);
} else {
assertThat(result.changes).isEmpty();
assertThat(result.nonVisibleChanges).isEqualTo(0);
}
}
use of com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo in project gerrit by GerritCodeReview.
the class SubmittedTogetherIT method doNotRevealVisibleAncestorOfHiddenDraft.
@Test
public void doNotRevealVisibleAncestorOfHiddenDraft() throws Exception {
RevCommit initialHead = getRemoteHead();
commitBuilder().message("parent").create();
pushHead(testRepo, "refs/for/master", false);
commitBuilder().message("draft").create();
pushHead(testRepo, "refs/drafts/master/" + name("topic"), false);
testRepo.reset(initialHead);
RevCommit change = commitBuilder().message("same topic").create();
pushHead(testRepo, "refs/for/master/" + name("topic"), false);
String id = getChangeId(change);
setApiUser(user);
SubmittedTogetherInfo result = gApi.changes().id(id).submittedTogether(EnumSet.of(NON_VISIBLE_CHANGES));
if (isSubmitWholeTopicEnabled()) {
assertThat(result.changes).hasSize(1);
assertThat(result.changes.get(0).changeId).isEqualTo(id);
assertThat(result.nonVisibleChanges).isEqualTo(2);
} else {
assertThat(result.changes).isEmpty();
assertThat(result.nonVisibleChanges).isEqualTo(0);
}
}
use of com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo in project gerrit by GerritCodeReview.
the class SubmittedTogetherIT method returnsCurrentFilesIfOptionRequested.
@Test
public void returnsCurrentFilesIfOptionRequested() throws Exception {
RevCommit c1_1 = commitBuilder().add("a.txt", "1").message("subject: 1").create();
RevCommit c2_1 = commitBuilder().add("b.txt", "2").message("subject: 2").create();
String id2 = getChangeId(c2_1);
pushHead(testRepo, "refs/for/master", false);
SubmittedTogetherInfo info = gApi.changes().id(id2).submittedTogether(EnumSet.of(ListChangesOption.CURRENT_FILES), EnumSet.of(NON_VISIBLE_CHANGES));
assertThat(info.changes).hasSize(2);
assertThat(info.changes.get(0).currentRevision).isEqualTo(c2_1.name());
assertThat(info.changes.get(1).currentRevision).isEqualTo(c1_1.name());
assertThat(info.changes.get(0).currentRevision).isEqualTo(c2_1.name());
RevisionInfo rev = info.changes.get(0).revisions.get(c2_1.name());
assertThat(rev).isNotNull();
FileInfo file = rev.files.get("b.txt");
assertThat(file).isNotNull();
assertThat(file.status).isEqualTo('A');
}
use of com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo in project gerrit by GerritCodeReview.
the class SubmittedTogether method applyInfo.
public SubmittedTogetherInfo applyInfo(ChangeResource resource) throws AuthException, IOException, OrmException {
Change c = resource.getChange();
try {
List<ChangeData> cds;
int hidden;
if (c.getStatus().isOpen()) {
ChangeSet cs = mergeSuperSet.get().completeChangeSet(dbProvider.get(), c, resource.getControl().getUser());
cds = cs.changes().asList();
hidden = cs.nonVisibleChanges().size();
} else if (c.getStatus().asChangeStatus() == ChangeStatus.MERGED) {
cds = queryProvider.get().bySubmissionId(c.getSubmissionId());
hidden = 0;
} else {
cds = Collections.emptyList();
hidden = 0;
}
if (hidden != 0 && !options.contains(NON_VISIBLE_CHANGES)) {
throw new AuthException("change would be submitted with a change that you cannot see");
}
if (cds.size() <= 1 && hidden == 0) {
cds = Collections.emptyList();
} else {
// Skip sorting for singleton lists, to avoid WalkSorter opening the
// repo just to fill out the commit field in PatchSetData.
cds = sort(cds);
}
SubmittedTogetherInfo info = new SubmittedTogetherInfo();
info.changes = json.create(jsonOpt).formatChangeDatas(cds);
info.nonVisibleChanges = hidden;
return info;
} catch (OrmException | IOException e) {
log.error("Error on getting a ChangeSet", e);
throw e;
}
}
use of com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method assertSubmittedTogether.
protected void assertSubmittedTogether(String chId, String... expected) throws Exception {
List<ChangeInfo> actual = gApi.changes().id(chId).submittedTogether();
SubmittedTogetherInfo info = gApi.changes().id(chId).submittedTogether(EnumSet.of(NON_VISIBLE_CHANGES));
assertThat(info.nonVisibleChanges).isEqualTo(0);
assertThat(actual).hasSize(expected.length);
assertThat(changeIds(actual)).containsExactly((Object[]) expected).inOrder();
assertThat(changeIds(info.changes)).containsExactly((Object[]) expected).inOrder();
}
Aggregations