private void removeOldCommentsThatAreNotStillReported( final List<Comment> oldComments, final List<Comment> comments) { if (!commentsProvider.shouldKeepOldComments()) { final List<Comment> existingWithoutViolation = new ArrayList<>(); existingWithoutViolation.addAll(oldComments); existingWithoutViolation.removeAll(comments); commentsProvider.removeComments(existingWithoutViolation); } }
public void createComments() { if (commentsProvider.shouldCreateCommentWithAllSingleFileComments()) { createCommentWithAllSingleFileComments(); } if (commentsProvider.shouldCreateSingleFileComment()) { createSingleFileComments(); } if (!commentsProvider.shouldCreateCommentWithAllSingleFileComments() && !commentsProvider.shouldCreateSingleFileComment()) { violationsLogger.log( INFO, "Will not comment because both 'CreateCommentWithAllSingleFileComments' and 'CreateSingleFileComment' is false."); } }
private void createCommentWithAllSingleFileComments() { final List<String> accumulatedComments = getAccumulatedComments( violations, files, commentsProvider.findCommentTemplate().orElse(null), maxCommentSize); for (final String accumulatedComment : accumulatedComments) { violationsLogger.log( INFO, "Asking " + commentsProvider.getClass().getSimpleName() + " to create comment with all single file comments."); List<Comment> oldComments = commentsProvider.getComments(); oldComments = filterCommentsWithContent(oldComments, FINGERPRINT_ACC); final List<Comment> alreadyMadeComments = filterCommentsWithContent(oldComments, accumulatedComment); removeOldCommentsThatAreNotStillReported(oldComments, alreadyMadeComments); if (violations.isEmpty()) { return; } final boolean commentHasNotBeenMade = alreadyMadeComments.isEmpty(); if (commentHasNotBeenMade) { commentsProvider.createCommentWithAllSingleFileComments(accumulatedComment); } } }
private void createSingleFileComments() { List<Comment> oldComments = commentsProvider.getComments(); oldComments = filterCommentsWithContent(oldComments, FINGERPRINT); oldComments = filterCommentsWithoutContent(oldComments, FINGERPRINT_ACC); final String commentTemplate = commentsProvider.findCommentTemplate().orElse(null); final String singleFileCommentContent = createSingleFileCommentContent(changedFile.get(), violation, commentTemplate); + " " + violation.getSource()); commentsProvider.createSingleFileComment( changedFile.get(), violation.getStartLine(), singleFileCommentContent);
if (file.isPresent()) { final boolean shouldComment = commentsProvider.shouldComment(file.get(), violation.getStartLine()); if (shouldComment) { isChanged.add(violation);
CommentsCreator( ViolationsLogger violationsLogger, final CommentsProvider commentsProvider, final List<Violation> violations, final Integer maxCommentSize) { checkNotNull(violations, "violations"); checkNotNull(commentsProvider, "commentsProvider"); this.violationsLogger = checkNotNull(violationsLogger, "violationsLogger"); this.commentsProvider = commentsProvider; files = commentsProvider.getFiles(); this.violations = filterChanged(violations); this.maxCommentSize = maxCommentSize; }