use of org.sonarqube.ws.Common.Comment in project sonarqube by SonarSource.
the class SearchResponseFormat method formatIssueComments.
private static void formatIssueComments(SearchResponseData data, Issue.Builder wsIssue, IssueDto dto) {
Comments.Builder wsComments = Comments.newBuilder();
List<IssueChangeDto> comments = data.getCommentsForIssueKey(dto.getKey());
if (comments != null) {
Comment.Builder wsComment = Comment.newBuilder();
for (IssueChangeDto comment : comments) {
String markdown = comment.getChangeData();
wsComment.clear().setKey(comment.getKey()).setUpdatable(data.isUpdatableComment(comment.getKey())).setCreatedAt(DateUtils.formatDateTime(new Date(comment.getIssueChangeCreationDate())));
ofNullable(data.getUserByUuid(comment.getUserUuid())).ifPresent(user -> wsComment.setLogin(user.getLogin()));
if (markdown != null) {
wsComment.setHtmlText(Markdown.convertToHtml(markdown)).setMarkdown(markdown);
}
wsComments.addComments(wsComment);
}
}
wsIssue.setComments(wsComments);
}
use of org.sonarqube.ws.Common.Comment in project sonarqube by SonarSource.
the class IssueChangeWSSupportTest method formatComments_returns_comment_markdown_and_html_when_available.
@Test
@UseDataProvider("loadAllOrComments")
public void formatComments_returns_comment_markdown_and_html_when_available(Load load) {
IssueDto issue = dbTester.issues().insertIssue();
IssueChangeDto withText = dbTester.issues().insertChange(newComment(issue).setChangeData("* foo"));
IssueChangeDto noText = dbTester.issues().insertChange(newComment(issue).setChangeData(null));
FormattingContext formattingContext = underTest.newFormattingContext(dbTester.getSession(), singleton(issue), load);
List<Comment> comments = underTest.formatComments(issue, Comment.newBuilder(), formattingContext).collect(Collectors.toList());
assertThat(comments).extracting(Comment::getKey, Comment::hasMarkdown, Comment::hasHtmlText).containsExactlyInAnyOrder(tuple(withText.getKey(), true, true), tuple(noText.getKey(), false, false));
assertThat(comments.stream().filter(Comment::hasHtmlText)).extracting(Comment::getMarkdown, Comment::getHtmlText).containsOnly(tuple(withText.getChangeData(), Markdown.convertToHtml(withText.getChangeData())));
}
use of org.sonarqube.ws.Common.Comment in project sonarqube by SonarSource.
the class EditCommentAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
hotspotWsSupport.checkLoggedIn();
String commentKey = request.mandatoryParam(PARAM_COMMENT);
String text = request.mandatoryParam(PARAM_TEXT);
try (DbSession dbSession = dbClient.openSession(false)) {
IssueChangeDto hotspotComment = getHotspotComment(commentKey, dbSession);
validate(dbSession, hotspotComment);
editComment(dbSession, hotspotComment, text);
Comment commentData = prepareResponse(dbSession, hotspotComment);
writeProtobuf(commentData, request, response);
}
}
Aggregations