Search in sources :

Example 56 with CommentInput

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

the class CommentContextIT method commentContextForGitSubmoduleFiles.

@Test
public void commentContextForGitSubmoduleFiles() throws Exception {
    String submodulePath = "submodule_path";
    PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo).addGitSubmodule(submodulePath, dummyCommit);
    PushOneCommit.Result pushResult = push.to("refs/for/master");
    String changeId = pushResult.getChangeId();
    CommentInput comment = CommentsUtil.newComment(submodulePath, Side.REVISION, 1, "comment", false);
    CommentsUtil.addComments(gApi, changeId, pushResult.getCommit().name(), comment);
    List<CommentInfo> comments = gApi.changes().id(changeId).commentsRequest().withContext(true).getAsList();
    assertThat(comments).hasSize(1);
    assertThat(comments.get(0).path).isEqualTo(submodulePath);
    assertThat(comments.get(0).contextLines).isEqualTo(createContextLines("1", "Subproject commit " + dummyCommit.getName()));
}
Also used : CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 57 with CommentInput

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

the class CommentContextIT method createChangeWithCommentLarge.

private String createChangeWithCommentLarge(int startLine, int endLine) throws Exception {
    StringBuilder largeContent = new StringBuilder();
    for (int i = 0; i < 1000; i++) {
        largeContent.append("line " + i + "\n");
    }
    PushOneCommit.Result result = createChange(testRepo, "master", SUBJECT, FILE_NAME, largeContent.toString(), "topic");
    String changeId = result.getChangeId();
    String ps1 = result.getCommit().name();
    Comment.Range commentRange = createCommentRange(startLine, endLine);
    CommentInput comment = CommentsUtil.newComment(FILE_NAME, Side.REVISION, commentRange, "comment", false);
    CommentsUtil.addComments(gApi, changeId, ps1, comment);
    return changeId;
}
Also used : Comment(com.google.gerrit.extensions.client.Comment) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit)

Example 58 with CommentInput

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

the class CommentContextIT method commentContextForCommitMessageInvalidLine.

@Test
public void commentContextForCommitMessageInvalidLine() throws Exception {
    PushOneCommit.Result result = createChange(testRepo, "master", SUBJECT, FILE_NAME, FILE_CONTENT, "topic");
    String changeId = result.getChangeId();
    String ps1 = result.getCommit().name();
    CommentInput comment = CommentsUtil.newComment(COMMIT_MSG, Side.REVISION, 100, "comment", false);
    CommentsUtil.addComments(gApi, changeId, ps1, comment);
    List<CommentInfo> comments = gApi.changes().id(changeId).commentsRequest().withContext(true).getAsList();
    assertThat(comments).hasSize(1);
    assertThat(comments.get(0).contextLines).isEmpty();
}
Also used : CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 59 with CommentInput

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

the class CommentContextIT method commentContextForRootCommitOnParentSideReturnsEmptyContext.

@Test
public void commentContextForRootCommitOnParentSideReturnsEmptyContext() throws Exception {
    // Create a change in a new branch, making the patchset commit a root commit
    ChangeInfo changeInfo = createChangeInNewBranch("newBranch");
    String changeId = changeInfo.changeId;
    String revision = changeInfo.revisions.keySet().iterator().next();
    // Write a comment on the parent side of the commit message. Set parent=1 because if unset, our
    // handler in PostReview assumes we want to write on the auto-merge commit and fails the
    // pre-condition.
    CommentInput comment = CommentsUtil.newComment(COMMIT_MSG, Side.PARENT, 0, "comment", false);
    comment.parent = 1;
    CommentsUtil.addComments(gApi, changeId, revision, comment);
    List<CommentInfo> comments = gApi.changes().id(changeId).commentsRequest().withContext(true).getAsList();
    assertThat(comments).hasSize(1);
    CommentInfo c = comments.stream().collect(MoreCollectors.onlyElement());
    assertThat(c.commitId).isEqualTo(ObjectId.zeroId().name());
    assertThat(c.contextLines).isEmpty();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 60 with CommentInput

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

the class CommentContextIT method commentContextForMergeList.

@Test
public void commentContextForMergeList() throws Exception {
    PushOneCommit.Result result = createMergeCommitChange("refs/for/master");
    String changeId = result.getChangeId();
    String ps1 = result.getCommit().name();
    CommentInput comment = CommentsUtil.newComment(MERGE_LIST, Side.REVISION, 1, "comment", false);
    CommentsUtil.addComments(gApi, changeId, ps1, comment);
    List<CommentInfo> comments = gApi.changes().id(changeId).commentsRequest().withContext(true).getAsList();
    assertThat(comments).hasSize(1);
    assertThat(comments.get(0).contextLines).containsExactlyElementsIn(createContextLines("1", "Merge List:"));
}
Also used : CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)63 Test (org.junit.Test)48 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)46 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)40 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)32 DeleteCommentInput (com.google.gerrit.extensions.api.changes.DeleteCommentInput)27 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)26 IdString (com.google.gerrit.extensions.restapi.IdString)21 ImmutableList (com.google.common.collect.ImmutableList)14 List (java.util.List)14 Collectors.toList (java.util.stream.Collectors.toList)14 ArrayList (java.util.ArrayList)12 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)11 Change (com.google.gerrit.entities.Change)9 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)8 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)6 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)6 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)5 Message (com.google.gerrit.testing.FakeEmailSender.Message)5 Comment (com.google.gerrit.extensions.client.Comment)4