Search in sources :

Example 81 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class DeleteComment method apply.

@Override
public Response<CommentInfo> apply(HumanCommentResource rsrc, DeleteCommentInput input) throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException, UpdateException {
    CurrentUser user = userProvider.get();
    permissionBackend.user(user).check(GlobalPermission.ADMINISTRATE_SERVER);
    if (input == null) {
        input = new DeleteCommentInput();
    }
    String newMessage = getCommentNewMessage(user.asIdentifiedUser().getName(), input.reason);
    DeleteCommentOp deleteCommentOp = new DeleteCommentOp(rsrc, newMessage);
    try (BatchUpdate batchUpdate = updateFactory.create(rsrc.getRevisionResource().getProject(), user, TimeUtil.now())) {
        batchUpdate.addOp(rsrc.getRevisionResource().getChange().getId(), deleteCommentOp).execute();
    }
    ChangeNotes updatedNotes = notesFactory.createChecked(rsrc.getRevisionResource().getProject(), rsrc.getRevisionResource().getChangeResource().getId());
    List<HumanComment> changeComments = commentsUtil.publishedHumanCommentsByChange(updatedNotes);
    Optional<HumanComment> updatedComment = changeComments.stream().filter(c -> c.key.equals(rsrc.getComment().key)).findFirst();
    if (!updatedComment.isPresent()) {
        // This should not happen as this endpoint should not remove the whole comment.
        throw new ResourceNotFoundException("comment not found: " + rsrc.getComment().key);
    }
    return Response.ok(commentJson.get().newHumanCommentFormatter().format(updatedComment.get()));
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Inject(com.google.inject.Inject) HumanComment(com.google.gerrit.entities.HumanComment) CommentsUtil(com.google.gerrit.server.CommentsUtil) Response(com.google.gerrit.extensions.restapi.Response) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) UpdateException(com.google.gerrit.server.update.UpdateException) RestModifyView(com.google.gerrit.extensions.restapi.RestModifyView) Strings(com.google.common.base.Strings) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) PatchSet(com.google.gerrit.entities.PatchSet) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ChangeContext(com.google.gerrit.server.update.ChangeContext) GlobalPermission(com.google.gerrit.server.permissions.GlobalPermission) CurrentUser(com.google.gerrit.server.CurrentUser) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) Provider(com.google.inject.Provider) List(java.util.List) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Optional(java.util.Optional) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) HumanCommentResource(com.google.gerrit.server.change.HumanCommentResource) Singleton(com.google.inject.Singleton) CurrentUser(com.google.gerrit.server.CurrentUser) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) HumanComment(com.google.gerrit.entities.HumanComment) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 82 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class ChangeIT method fourByteEmoji.

@Test
public void fourByteEmoji() throws Exception {
    // U+1F601 GRINNING FACE WITH SMILING EYES
    String smile = new String(Character.toChars(0x1f601));
    assertThat(smile).isEqualTo("😁");
    // Thanks, Java.
    assertThat(smile).hasLength(2);
    assertThat(smile.getBytes(UTF_8)).hasLength(4);
    String subject = "A happy change " + smile;
    PushOneCommit.Result r = pushFactory.create(admin.newIdent(), testRepo, subject, FILE_NAME, FILE_CONTENT).to("refs/for/master");
    r.assertOkStatus();
    String id = r.getChangeId();
    ReviewInput ri = ReviewInput.approve();
    ri.message = "I like it " + smile;
    ReviewInput.CommentInput ci = new ReviewInput.CommentInput();
    ci.path = FILE_NAME;
    ci.side = Side.REVISION;
    ci.message = "Good " + smile;
    ri.comments = ImmutableMap.of(FILE_NAME, ImmutableList.of(ci));
    gApi.changes().id(id).current().review(ri);
    ChangeInfo info = gApi.changes().id(id).get(MESSAGES, CURRENT_COMMIT, CURRENT_REVISION);
    assertThat(info.subject).isEqualTo(subject);
    assertThat(Iterables.getLast(info.messages).message).endsWith(ri.message);
    assertThat(Iterables.getOnlyElement(info.revisions.values()).commit.message).startsWith(subject);
    List<CommentInfo> comments = Iterables.getOnlyElement(gApi.changes().id(id).commentsRequest().get().values());
    assertThat(Iterables.getOnlyElement(comments).message).isEqualTo(ci.message);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 83 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class CommentContextIT method commentContextReturnsCorrectContentTypeForCommitMessage.

@Test
public void commentContextReturnsCorrectContentTypeForCommitMessage() 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, 7, "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).path).isEqualTo(COMMIT_MSG);
    assertThat(comments.get(0).sourceContentType).isEqualTo(FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE);
}
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 84 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class CommentContextIT method commentContextForCommitMessageForLineComment.

@Test
public void commentContextForCommitMessageForLineComment() 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, 7, "comment", false);
    CommentsUtil.addComments(gApi, changeId, ps1, comment);
    List<CommentInfo> comments = gApi.changes().id(changeId).commentsRequest().withContext(true).getAsList();
    assertThat(comments).hasSize(1);
    // The first few lines of the commit message are the headers, e.g.
    // Parent: ...
    // Author: ...
    // AuthorDate: ...
    // etc...
    assertThat(comments.get(0).contextLines).containsExactlyElementsIn(createContextLines("7", "Commit Header"));
}
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 85 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class CommentContextIT method commentContextIsEmptyForPatchsetLevelComments.

@Test
public void commentContextIsEmptyForPatchsetLevelComments() throws Exception {
    PushOneCommit.Result result = createChange();
    String changeId = result.getChangeId();
    String ps1 = result.getCommit().name();
    CommentInput comment = CommentsUtil.newCommentWithOnlyMandatoryFields(PATCHSET_LEVEL, "comment");
    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)

Aggregations

CommentInfo (com.google.gerrit.extensions.common.CommentInfo)186 Test (org.junit.Test)178 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)164 Change (com.google.gerrit.entities.Change)120 PatchSet (com.google.gerrit.entities.PatchSet)62 RobotCommentInfo (com.google.gerrit.extensions.common.RobotCommentInfo)56 List (java.util.List)51 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)47 ImmutableList (com.google.common.collect.ImmutableList)46 IdString (com.google.gerrit.extensions.restapi.IdString)34 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)27 ArrayList (java.util.ArrayList)26 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)25 Collectors.toList (java.util.stream.Collectors.toList)25 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)24 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)22 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)21 DeleteCommentInput (com.google.gerrit.extensions.api.changes.DeleteCommentInput)20 CommentInfoSubject.assertThatList (com.google.gerrit.extensions.common.testing.CommentInfoSubject.assertThatList)19 MailMessage (com.google.gerrit.mail.MailMessage)13