Search in sources :

Example 76 with ReviewInput

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

the class CommentsIT method insertCommentsWithHistoricTimestamp.

@Test
public void insertCommentsWithHistoricTimestamp() throws Exception {
    Timestamp timestamp = new Timestamp(0);
    for (Integer line : lines) {
        String file = "file";
        String contents = "contents " + line;
        PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, "first subject", file, contents);
        PushOneCommit.Result r = push.to("refs/for/master");
        String changeId = r.getChangeId();
        String revId = r.getCommit().getName();
        Timestamp origLastUpdated = r.getChange().change().getLastUpdatedOn();
        ReviewInput input = new ReviewInput();
        CommentInput comment = newComment(file, Side.REVISION, line, "comment 1", false);
        comment.updated = timestamp;
        input.comments = new HashMap<>();
        input.comments.put(comment.path, Lists.newArrayList(comment));
        ChangeResource changeRsrc = changes.get().parse(TopLevelResource.INSTANCE, IdString.fromDecoded(changeId));
        RevisionResource revRsrc = revisions.parse(changeRsrc, IdString.fromDecoded(revId));
        postReview.get().apply(batchUpdateFactory, revRsrc, input, timestamp);
        Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
        assertThat(result).isNotEmpty();
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        CommentInput ci = infoToInput(file).apply(actual);
        ci.updated = comment.updated;
        assertThat(comment).isEqualTo(ci);
        assertThat(actual.updated).isEqualTo(gApi.changes().id(r.getChangeId()).info().created);
        // Updating historic comments doesn't cause lastUpdatedOn to regress.
        assertThat(r.getChange().change().getLastUpdatedOn()).isEqualTo(origLastUpdated);
    }
}
Also used : RevisionResource(com.google.gerrit.server.change.RevisionResource) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Timestamp(java.sql.Timestamp) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ChangeResource(com.google.gerrit.server.change.ChangeResource) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 77 with ReviewInput

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

the class CommentsIT method postCommentWithReply.

@Test
public void postCommentWithReply() throws Exception {
    for (Integer line : lines) {
        String file = "file";
        String contents = "contents " + line;
        PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, "first subject", file, contents);
        PushOneCommit.Result r = push.to("refs/for/master");
        String changeId = r.getChangeId();
        String revId = r.getCommit().getName();
        ReviewInput input = new ReviewInput();
        CommentInput comment = newComment(file, Side.REVISION, line, "comment 1", false);
        input.comments = new HashMap<>();
        input.comments.put(comment.path, Lists.newArrayList(comment));
        revision(r).review(input);
        Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        input = new ReviewInput();
        comment = newComment(file, Side.REVISION, line, "comment 1 reply", false);
        comment.inReplyTo = actual.id;
        input.comments = new HashMap<>();
        input.comments.put(comment.path, Lists.newArrayList(comment));
        revision(r).review(input);
        result = getPublishedComments(changeId, revId);
        actual = result.get(comment.path).get(1);
        assertThat(comment).isEqualTo(infoToInput(file).apply(actual));
        assertThat(comment).isEqualTo(infoToInput(file).apply(getPublishedComment(changeId, revId, actual.id)));
    }
}
Also used : DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 78 with ReviewInput

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

the class CommentsIT method postCommentOnCommitMessageOnAutoMerge.

@Test
public void postCommentOnCommitMessageOnAutoMerge() throws Exception {
    PushOneCommit.Result r = createMergeCommitChange("refs/for/master");
    ReviewInput input = new ReviewInput();
    CommentInput c = newComment(Patch.COMMIT_MSG, Side.PARENT, 0, "comment on auto-merge", false);
    input.comments = new HashMap<>();
    input.comments.put(Patch.COMMIT_MSG, ImmutableList.of(c));
    exception.expect(BadRequestException.class);
    exception.expectMessage("cannot comment on " + Patch.COMMIT_MSG + " on auto-merge");
    revision(r).review(input);
}
Also used : DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 79 with ReviewInput

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

the class CommentsIT method postCommentOnMergeCommitChange.

@Test
public void postCommentOnMergeCommitChange() throws Exception {
    for (Integer line : lines) {
        String file = "foo";
        PushOneCommit.Result r = createMergeCommitChange("refs/for/master", file);
        String changeId = r.getChangeId();
        String revId = r.getCommit().getName();
        ReviewInput input = new ReviewInput();
        CommentInput c1 = newComment(file, Side.REVISION, line, "ps-1", false);
        CommentInput c2 = newComment(file, Side.PARENT, line, "auto-merge of ps-1", false);
        CommentInput c3 = newCommentOnParent(file, 1, line, "parent-1 of ps-1");
        CommentInput c4 = newCommentOnParent(file, 2, line, "parent-2 of ps-1");
        input.comments = new HashMap<>();
        input.comments.put(file, ImmutableList.of(c1, c2, c3, c4));
        revision(r).review(input);
        Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
        assertThat(result).isNotEmpty();
        assertThat(Lists.transform(result.get(file), infoToInput(file))).containsExactly(c1, c2, c3, c4);
    }
    // for the commit message comments on the auto-merge are not possible
    for (Integer line : lines) {
        String file = Patch.COMMIT_MSG;
        PushOneCommit.Result r = createMergeCommitChange("refs/for/master");
        String changeId = r.getChangeId();
        String revId = r.getCommit().getName();
        ReviewInput input = new ReviewInput();
        CommentInput c1 = newComment(file, Side.REVISION, line, "ps-1", false);
        CommentInput c2 = newCommentOnParent(file, 1, line, "parent-1 of ps-1");
        CommentInput c3 = newCommentOnParent(file, 2, line, "parent-2 of ps-1");
        input.comments = new HashMap<>();
        input.comments.put(file, ImmutableList.of(c1, c2, c3));
        revision(r).review(input);
        Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
        assertThat(result).isNotEmpty();
        assertThat(Lists.transform(result.get(file), infoToInput(file))).containsExactly(c1, c2, c3);
    }
}
Also used : DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) IdString(com.google.gerrit.extensions.restapi.IdString) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 80 with ReviewInput

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

the class CommentsIT method addComments.

private void addComments(String changeId, String revision, CommentInput... commentInputs) throws Exception {
    ReviewInput input = new ReviewInput();
    input.comments = Arrays.stream(commentInputs).collect(Collectors.groupingBy(c -> c.path));
    gApi.changes().id(changeId).revision(revision).review(input);
}
Also used : ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput)

Aggregations

ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)103 Test (org.junit.Test)85 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)77 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)70 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)25 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)20 Change (com.google.gerrit.reviewdb.client.Change)16 ArrayList (java.util.ArrayList)15 List (java.util.List)14 ImmutableList (com.google.common.collect.ImmutableList)13 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)13 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)12 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)12 RevisionApi (com.google.gerrit.extensions.api.changes.RevisionApi)11 LabelType (com.google.gerrit.common.data.LabelType)10 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)10 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)9 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 RestResponse (com.google.gerrit.acceptance.RestResponse)8 TestAccount (com.google.gerrit.acceptance.TestAccount)8