Search in sources :

Example 1 with Comment

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);
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) Comment(org.sonarqube.ws.Common.Comment) Comments(org.sonarqube.ws.Issues.Comments) Date(java.util.Date)

Example 2 with Comment

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())));
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) FormattingContext(org.sonar.server.issue.IssueChangeWSSupport.FormattingContext) Comment(org.sonarqube.ws.Common.Comment) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 3 with Comment

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);
    }
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) DbSession(org.sonar.db.DbSession) Comment(org.sonarqube.ws.Common.Comment)

Aggregations

IssueChangeDto (org.sonar.db.issue.IssueChangeDto)3 Comment (org.sonarqube.ws.Common.Comment)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Date (java.util.Date)1 Test (org.junit.Test)1 DbSession (org.sonar.db.DbSession)1 IssueDto (org.sonar.db.issue.IssueDto)1 FormattingContext (org.sonar.server.issue.IssueChangeWSSupport.FormattingContext)1 Comments (org.sonarqube.ws.Issues.Comments)1