Search in sources :

Example 1 with SubmittedTogetherInfo

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);
    }
}
Also used : SubmittedTogetherInfo(com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with SubmittedTogetherInfo

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);
    }
}
Also used : SubmittedTogetherInfo(com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with SubmittedTogetherInfo

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');
}
Also used : RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) FileInfo(com.google.gerrit.extensions.common.FileInfo) SubmittedTogetherInfo(com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with SubmittedTogetherInfo

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;
    }
}
Also used : OrmException(com.google.gwtorm.server.OrmException) AuthException(com.google.gerrit.extensions.restapi.AuthException) Change(com.google.gerrit.reviewdb.client.Change) SubmittedTogetherInfo(com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo) IOException(java.io.IOException) ChangeData(com.google.gerrit.server.query.change.ChangeData) ChangeSet(com.google.gerrit.server.git.ChangeSet)

Example 5 with SubmittedTogetherInfo

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();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) SubmittedTogetherInfo(com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo)

Aggregations

SubmittedTogetherInfo (com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo)6 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 Test (org.junit.Test)4 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)2 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)1 FileInfo (com.google.gerrit.extensions.common.FileInfo)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 Change (com.google.gerrit.reviewdb.client.Change)1 ChangeSet (com.google.gerrit.server.git.ChangeSet)1 ChangeData (com.google.gerrit.server.query.change.ChangeData)1 OrmException (com.google.gwtorm.server.OrmException)1 IOException (java.io.IOException)1