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()));
}
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);
}
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);
}
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"));
}
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();
}
Aggregations