public void postCommentPerIssue(String project,String repository,String pullRequestId,String sonarQubeURL,SonarQubeIssuesReport issueReport,StashDiffReport diffReport,StashClient stashClient){
  try {
    Map<String,StashCommentReport> commentsByFile=new HashMap<>();
    for (    SonarQubeIssue issue : issueReport.getIssues()) {
      if (commentsByFile.get(issue.getPath()) == null) {
        StashCommentReport comments=stashClient.getPullRequestComments(project,repository,pullRequestId,issue.getPath());
        comments.applyDiffReport(diffReport);
        commentsByFile.put(issue.getPath(),comments);
      }
    }
    List<String> taskSeverities=getReportedSeverities();
    for (    SonarQubeIssue issue : issueReport.getIssues()) {
      StashCommentReport comments=commentsByFile.get(issue.getPath());
      if ((comments != null) && (comments.contains(MarkdownPrinter.printIssueMarkdown(issue,sonarQubeURL),issue.getPath(),issue.getLine()))) {
        LOGGER.debug("Comment \"{}\" already pushed on file {} ({})",issue.getRule(),issue.getPath(),issue.getLine());
        continue;
      }
      String type=diffReport.getType(issue.getPath(),issue.getLine());
      if (type == null) {
        LOGGER.info("Comment \"{}\" cannot be pushed to Stash like it does not belong to diff view - {} (line: {})",issue.getRule(),issue.getPath(),issue.getLine());
        continue;
      }
      long line=diffReport.getLine(issue.getPath(),issue.getLine());
      StashComment comment=stashClient.postCommentLineOnPullRequest(project,repository,pullRequestId,MarkdownPrinter.printIssueMarkdown(issue,sonarQubeURL),issue.getPath(),line,type);
      LOGGER.debug("Comment \"{}\" has been created ({}) on file {} ({})",issue.getRule(),type,issue.getPath(),line);
      if (taskSeverities.contains(issue.getSeverity())) {
        stashClient.postTaskOnComment(issue.getMessage(),comment.getId());
        LOGGER.debug("Comment \"{}\" has been linked to a Stash task",comment.getId());
      }
    }
    LOGGER.info("New SonarQube issues have been reported to Stash.");
  }
 catch (  StashClientException e) {
    LOGGER.error("Unable to link SonarQube issues to Stash",e);
  }
}

public void postCommentPerIssue ( String project , String repository , String pullRequestId , String sonarQubeURL , SonarQubeIssuesReport issueReport , StashDiffReport diffReport , StashClient stashClient ) { try { Map < String , StashCommentReport > commentsByFile = new HashMap < > ( ) ; for ( SonarQubeIssue issue : issueReport . getIssues ( ) ) { if ( commentsByFile . get ( issue . getPath ( ) ) == null ) { StashCommentReport comments = stashClient . getPullRequestComments ( project , repository , pullRequestId , issue . getPath ( ) ) ; comments . applyDiffReport ( diffReport ) ; commentsByFile . put ( issue . getPath ( ) , comments ) ; } } List < String > taskSeverities = getReportedSeverities ( ) ; for ( SonarQubeIssue issue : issueReport . getIssues ( ) ) { StashCommentReport comments = commentsByFile . get ( issue . getPath ( ) ) ; if ( ( comments != null ) && ( comments . contains ( MarkdownPrinter . printIssueMarkdown ( issue , sonarQubeURL ) , issue . getPath ( ) , issue . getLine ( ) ) ) ) { LOGGER . debug ( "Comment \"{}\" already pushed on file {} ({})" , issue . getRule ( ) , issue . getPath ( ) , issue . getLine ( ) ) ; continue ; } String type = diffReport . getType ( issue . getPath ( ) , issue . getLine ( ) ) ; if ( type == null ) { LOGGER . info ( "Comment \"{}\" cannot be pushed to Stash like it does not belong to diff view - {} (line: {})" , issue . getRule ( ) , issue . getPath ( ) , issue . getLine ( ) ) ; continue ; } long line = diffReport . getLine ( issue . getPath ( ) , issue . getLine ( ) ) ; StashComment comment = stashClient . postCommentLineOnPullRequest ( project , repository , pullRequestId , MarkdownPrinter . printIssueMarkdown ( issue , sonarQubeURL ) , issue . getPath ( ) , line , type ) ; LOGGER . debug ( "Comment \"{}\" has been created ({}) on file {} ({})" , issue . getRule ( ) , type , issue . getPath ( ) , line ) ; if ( taskSeverities . contains ( issue . getSeverity ( ) ) ) { stashClient . postTaskOnComment ( issue . getMessage ( ) , comment . getId ( ) ) ; LOGGER . debug ( "Comment \"{}\" has been linked to a Stash task" , comment . getId ( ) ) ; } } LOGGER . info ( "New SonarQube issues have been reported to Stash." ) ; } catch ( StashClientException e ) { LOGGER . error ( "Unable to link SonarQube issues to Stash" , e ) ; } }
post one comment by found issue on stash .
