Search in sources :

Example 31 with CommentInfo

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

the class NoteDbPrimaryIT method deleteDraftComment.

@Test
public void deleteDraftComment() throws Exception {
    PushOneCommit.Result r = createChange();
    Change.Id id = r.getChange().getId();
    setNoteDbPrimary(id);
    DraftInput din = new DraftInput();
    din.path = PushOneCommit.FILE_NAME;
    din.line = 1;
    din.message = "A comment";
    gApi.changes().id(id.get()).current().createDraft(din);
    CommentInfo di = Iterables.getOnlyElement(gApi.changes().id(id.get()).current().drafts().get(PushOneCommit.FILE_NAME));
    assertThat(di.message).isEqualTo(din.message);
    assertThat(db.patchComments().draftByChangeFileAuthor(id, din.path, admin.id)).isEmpty();
    gApi.changes().id(id.get()).current().draft(di.id).delete();
    assertThat(gApi.changes().id(id.get()).current().drafts()).isEmpty();
}
Also used : DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) Change(com.google.gerrit.reviewdb.client.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 32 with CommentInfo

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

the class DeleteComment method applyImpl.

@Override
public CommentInfo applyImpl(BatchUpdate.Factory batchUpdateFactory, CommentResource rsrc, DeleteCommentInput input) throws RestApiException, IOException, ConfigInvalidException, OrmException, PermissionBackendException, UpdateException {
    CurrentUser user = userProvider.get();
    permissionBackend.user(user).check(GlobalPermission.ADMINISTRATE_SERVER);
    String newMessage = getCommentNewMessage(user.asIdentifiedUser().getName(), input.reason);
    DeleteCommentOp deleteCommentOp = new DeleteCommentOp(rsrc, newMessage);
    try (BatchUpdate batchUpdate = batchUpdateFactory.create(dbProvider.get(), rsrc.getRevisionResource().getProject(), user, TimeUtil.nowTs())) {
        batchUpdate.addOp(rsrc.getRevisionResource().getChange().getId(), deleteCommentOp).execute();
    }
    ChangeNotes updatedNotes = notesFactory.createChecked(rsrc.getRevisionResource().getChange().getId());
    List<Comment> changeComments = commentsUtil.publishedByChange(dbProvider.get(), updatedNotes);
    Optional<Comment> 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 commentJson.get().newCommentFormatter().format(updatedComment.get());
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) OrmException(com.google.gwtorm.server.OrmException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Inject(com.google.inject.Inject) CommentsUtil(com.google.gerrit.server.CommentsUtil) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) UpdateException(com.google.gerrit.server.update.UpdateException) Strings(com.google.common.base.Strings) Comment(com.google.gerrit.reviewdb.client.Comment) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) RetryHelper(com.google.gerrit.server.update.RetryHelper) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) RetryingRestModifyView(com.google.gerrit.server.update.RetryingRestModifyView) 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) TimeUtil(com.google.gerrit.common.TimeUtil) 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) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Optional(java.util.Optional) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) Singleton(com.google.inject.Singleton) Comment(com.google.gerrit.reviewdb.client.Comment) CurrentUser(com.google.gerrit.server.CurrentUser) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 33 with CommentInfo

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

the class AbstractQueryChangesTest method byComment.

@Test
public void byComment() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    ChangeInserter ins = newChange(repo);
    Change change = insert(repo, ins);
    ReviewInput input = new ReviewInput();
    input.message = "toplevel";
    ReviewInput.CommentInput commentInput = new ReviewInput.CommentInput();
    commentInput.line = 1;
    commentInput.message = "inline";
    input.comments = ImmutableMap.<String, List<ReviewInput.CommentInput>>of(Patch.COMMIT_MSG, ImmutableList.<ReviewInput.CommentInput>of(commentInput));
    gApi.changes().id(change.getId().get()).current().review(input);
    Map<String, List<CommentInfo>> comments = gApi.changes().id(change.getId().get()).current().comments();
    assertThat(comments).hasSize(1);
    CommentInfo comment = Iterables.getOnlyElement(comments.get(Patch.COMMIT_MSG));
    assertThat(comment.message).isEqualTo(commentInput.message);
    ChangeMessageInfo lastMsg = Iterables.getLast(gApi.changes().id(change.getId().get()).get().messages, null);
    assertThat(lastMsg.message).isEqualTo("Patch Set 1:\n\n(1 comment)\n\n" + input.message);
    assertQuery("comment:foo");
    assertQuery("comment:toplevel", change);
    assertQuery("comment:inline", change);
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) Change(com.google.gerrit.reviewdb.client.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Test(org.junit.Test)

Aggregations

CommentInfo (com.google.gerrit.extensions.common.CommentInfo)33 Test (org.junit.Test)31 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)24 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)23 List (java.util.List)18 ImmutableList (com.google.common.collect.ImmutableList)17 ArrayList (java.util.ArrayList)17 IdString (com.google.gerrit.extensions.restapi.IdString)16 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)12 DeleteCommentInput (com.google.gerrit.extensions.api.changes.DeleteCommentInput)10 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)10 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)10 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)9 Change (com.google.gerrit.reviewdb.client.Change)6 MailMessage (com.google.gerrit.server.mail.receive.MailMessage)6 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)5 Timestamp (java.sql.Timestamp)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)3 ChangeResource (com.google.gerrit.server.change.ChangeResource)3