Search in sources :

Example 1 with ChangeAttribute

use of com.google.gerrit.server.data.ChangeAttribute in project gerrit by GerritCodeReview.

the class OutputStreamQuery method buildChangeAttribute.

private ChangeAttribute buildChangeAttribute(ChangeData d, Map<Project.NameKey, Repository> repos, Map<Project.NameKey, RevWalk> revWalks) throws OrmException, IOException {
    ChangeControl cc = d.changeControl().forUser(user);
    LabelTypes labelTypes = cc.getLabelTypes();
    ChangeAttribute c = eventFactory.asChangeAttribute(db, d.change());
    eventFactory.extend(c, d.change());
    if (!trackingFooters.isEmpty()) {
        eventFactory.addTrackingIds(c, trackingFooters.extract(d.commitFooters()));
    }
    if (includeAllReviewers) {
        eventFactory.addAllReviewers(db, c, d.notes());
    }
    if (includeSubmitRecords) {
        eventFactory.addSubmitRecords(c, new SubmitRuleEvaluator(d).setAllowClosed(true).setAllowDraft(true).evaluate());
    }
    if (includeCommitMessage) {
        eventFactory.addCommitMessage(c, d.commitMessage());
    }
    RevWalk rw = null;
    if (includePatchSets || includeCurrentPatchSet || includeDependencies) {
        Project.NameKey p = d.change().getProject();
        rw = revWalks.get(p);
        // Cache and reuse repos and revwalks.
        if (rw == null) {
            Repository repo = repoManager.openRepository(p);
            checkState(repos.put(p, repo) == null);
            rw = new RevWalk(repo);
            revWalks.put(p, rw);
        }
    }
    if (includePatchSets) {
        eventFactory.addPatchSets(db, rw, c, d.visiblePatchSets(), includeApprovals ? d.approvals().asMap() : null, includeFiles, d.change(), labelTypes);
    }
    if (includeCurrentPatchSet) {
        PatchSet current = d.currentPatchSet();
        if (current != null && cc.isPatchVisible(current, d.db())) {
            c.currentPatchSet = eventFactory.asPatchSetAttribute(db, rw, d.change(), current);
            eventFactory.addApprovals(c.currentPatchSet, d.currentApprovals(), labelTypes);
            if (includeFiles) {
                eventFactory.addPatchSetFileNames(c.currentPatchSet, d.change(), d.currentPatchSet());
            }
            if (includeComments) {
                eventFactory.addPatchSetComments(c.currentPatchSet, d.publishedComments());
            }
        }
    }
    if (includeComments) {
        eventFactory.addComments(c, d.messages());
        if (includePatchSets) {
            eventFactory.addPatchSets(db, rw, c, d.visiblePatchSets(), includeApprovals ? d.approvals().asMap() : null, includeFiles, d.change(), labelTypes);
            for (PatchSetAttribute attribute : c.patchSets) {
                eventFactory.addPatchSetComments(attribute, d.publishedComments());
            }
        }
    }
    if (includeDependencies) {
        eventFactory.addDependencies(rw, c, d.change(), d.currentPatchSet());
    }
    c.plugins = queryProcessor.create(d);
    return c;
}
Also used : SubmitRuleEvaluator(com.google.gerrit.server.project.SubmitRuleEvaluator) Project(com.google.gerrit.reviewdb.client.Project) LabelTypes(com.google.gerrit.common.data.LabelTypes) Repository(org.eclipse.jgit.lib.Repository) ChangeAttribute(com.google.gerrit.server.data.ChangeAttribute) ChangeControl(com.google.gerrit.server.project.ChangeControl) PatchSetAttribute(com.google.gerrit.server.data.PatchSetAttribute) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Example 2 with ChangeAttribute

use of com.google.gerrit.server.data.ChangeAttribute in project gerrit by GerritCodeReview.

the class QueryIT method allReviewersOptionJSON.

@Test
public void allReviewersOptionJSON() throws Exception {
    String changeId = createChange().getChangeId();
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    gApi.changes().id(changeId).addReviewer(in);
    List<ChangeAttribute> changes = executeSuccessfulQuery(changeId);
    assertThat(changes.size()).isEqualTo(1);
    assertThat(changes.get(0).allReviewers).isNull();
    changes = executeSuccessfulQuery("--all-reviewers " + changeId);
    assertThat(changes.size()).isEqualTo(1);
    assertThat(changes.get(0).allReviewers).isNotNull();
    assertThat(changes.get(0).allReviewers.size()).isEqualTo(1);
}
Also used : ChangeAttribute(com.google.gerrit.server.data.ChangeAttribute) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with ChangeAttribute

use of com.google.gerrit.server.data.ChangeAttribute in project gerrit by GerritCodeReview.

the class QueryIT method commentOptionInPatchSetsJSON.

@Test
public void commentOptionInPatchSetsJSON() throws Exception {
    String changeId = createChange().getChangeId();
    ReviewInput review = new ReviewInput();
    ReviewInput.CommentInput comment = new ReviewInput.CommentInput();
    comment.path = PushOneCommit.FILE_NAME;
    comment.side = Side.REVISION;
    comment.message = "comment 1";
    review.comments = new HashMap<>();
    review.comments.put(comment.path, Lists.newArrayList(comment));
    gApi.changes().id(changeId).current().review(review);
    List<ChangeAttribute> changes = executeSuccessfulQuery("--patch-sets " + changeId);
    assertThat(changes.size()).isEqualTo(1);
    assertThat(changes.get(0).patchSets.get(0).comments).isNull();
    changes = executeSuccessfulQuery("--patch-sets --comments " + changeId);
    assertThat(changes.size()).isEqualTo(1);
    assertThat(changes.get(0).patchSets.get(0).comments).isNotNull();
    assertThat(changes.get(0).patchSets.get(0).comments.size()).isEqualTo(1);
    changes = executeSuccessfulQuery("--patch-sets --comments --files " + changeId);
    assertThat(changes.size()).isEqualTo(1);
    assertThat(changes.get(0).patchSets.get(0).comments).isNotNull();
    assertThat(changes.get(0).patchSets.get(0).comments.size()).isEqualTo(1);
    assertThat(changes.get(0).patchSets.get(0).files).isNotNull();
    assertThat(changes.get(0).patchSets.get(0).files.size()).isEqualTo(2);
    gApi.changes().id(changeId).current().review(ReviewInput.approve());
    changes = executeSuccessfulQuery("--patch-sets --comments --files --all-approvals " + changeId);
    assertThat(changes.size()).isEqualTo(1);
    assertThat(changes.get(0).patchSets.get(0).comments).isNotNull();
    assertThat(changes.get(0).patchSets.get(0).comments.size()).isEqualTo(1);
    assertThat(changes.get(0).patchSets.get(0).files).isNotNull();
    assertThat(changes.get(0).patchSets.get(0).files.size()).isEqualTo(2);
    assertThat(changes.get(0).patchSets.get(0).approvals).isNotNull();
    assertThat(changes.get(0).patchSets.get(0).approvals.size()).isEqualTo(1);
}
Also used : ChangeAttribute(com.google.gerrit.server.data.ChangeAttribute) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with ChangeAttribute

use of com.google.gerrit.server.data.ChangeAttribute in project gerrit by GerritCodeReview.

the class QueryIT method queryWithNonVisibleCurrentPatchSet.

@Test
public void queryWithNonVisibleCurrentPatchSet() throws Exception {
    String changeId = createChange().getChangeId();
    amendChangeAsDraft(changeId);
    String query = "--current-patch-set --patch-sets " + changeId;
    List<ChangeAttribute> changes = executeSuccessfulQuery(query);
    assertThat(changes.size()).isEqualTo(1);
    assertThat(changes.get(0).patchSets).isNotNull();
    assertThat(changes.get(0).patchSets).hasSize(2);
    assertThat(changes.get(0).currentPatchSet).isNotNull();
    SshSession userSession = new SshSession(server, user);
    initSsh(user);
    userSession.open();
    changes = executeSuccessfulQuery(query, userSession);
    assertThat(changes.size()).isEqualTo(1);
    assertThat(changes.get(0).patchSets).hasSize(1);
    assertThat(changes.get(0).currentPatchSet).isNull();
    userSession.close();
}
Also used : ChangeAttribute(com.google.gerrit.server.data.ChangeAttribute) SshSession(com.google.gerrit.acceptance.SshSession) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with ChangeAttribute

use of com.google.gerrit.server.data.ChangeAttribute in project gerrit by GerritCodeReview.

the class QueryIT method commentOptionsInCurrentPatchSetJSON.

@Test
public void commentOptionsInCurrentPatchSetJSON() throws Exception {
    String changeId = createChange().getChangeId();
    ReviewInput review = new ReviewInput();
    ReviewInput.CommentInput comment = new ReviewInput.CommentInput();
    comment.path = PushOneCommit.FILE_NAME;
    comment.side = Side.REVISION;
    comment.message = "comment 1";
    review.comments = new HashMap<>();
    review.comments.put(comment.path, Lists.newArrayList(comment));
    gApi.changes().id(changeId).current().review(review);
    List<ChangeAttribute> changes = executeSuccessfulQuery("--current-patch-set " + changeId);
    assertThat(changes.size()).isEqualTo(1);
    assertThat(changes.get(0).currentPatchSet.comments).isNull();
    changes = executeSuccessfulQuery("--current-patch-set --comments " + changeId);
    assertThat(changes.size()).isEqualTo(1);
    assertThat(changes.get(0).currentPatchSet.comments).isNotNull();
    assertThat(changes.get(0).currentPatchSet.comments.size()).isEqualTo(1);
}
Also used : ChangeAttribute(com.google.gerrit.server.data.ChangeAttribute) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ChangeAttribute (com.google.gerrit.server.data.ChangeAttribute)6 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 Test (org.junit.Test)4 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)2 SshSession (com.google.gerrit.acceptance.SshSession)1 LabelTypes (com.google.gerrit.common.data.LabelTypes)1 AddReviewerInput (com.google.gerrit.extensions.api.changes.AddReviewerInput)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 Project (com.google.gerrit.reviewdb.client.Project)1 PatchSetAttribute (com.google.gerrit.server.data.PatchSetAttribute)1 PatchListNotAvailableException (com.google.gerrit.server.patch.PatchListNotAvailableException)1 ChangeControl (com.google.gerrit.server.project.ChangeControl)1 SubmitRuleEvaluator (com.google.gerrit.server.project.SubmitRuleEvaluator)1 OrmException (com.google.gwtorm.server.OrmException)1 IOException (java.io.IOException)1 Repository (org.eclipse.jgit.lib.Repository)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1