@Override public void createCommentWithAllSingleFileComments(final String comment) { try { issueSerivce.createComment( repository, violationCommentsToGitHubApi.getPullRequestId(), comment); } catch (final IOException e) { violationsLogger.log(SEVERE, e.getMessage(), e); } }
@Override public void createCommentWithAllSingleFileComments(final String comment) { markMergeRequestAsWIP(); try { gitlabApi.createNote(mergeRequest, comment); } catch (final Throwable e) { violationsLogger.log(SEVERE, "Could create comment " + comment, e); } }
@Override public void removeComments(final List<Comment> comments) { for (final Comment comment : comments) { try { final Long commentId = Long.valueOf(comment.getIdentifier()); if (comment.getType().equals(TYPE_DIFF)) { pullRequestService.deleteComment(repository, commentId); } else { issueSerivce.deleteComment(repository, commentId); } } catch (final Throwable e) { violationsLogger.log(SEVERE, e.getMessage(), e); } } }
violationsLogger.log(INFO, "Files changed:\n " + changedFiles); violationsLogger.log(INFO, "Files with violations:\n " + violationFiles); violationsLogger.log( INFO, "Will include violations on:\n " + included.stream().collect(joining("\n "))); violationsLogger.log( INFO, "Will not include violations on changed files because violation reported on untouched lines:\n " violationsLogger.log( INFO, "Will not include violations on unchanged files:\n "
@Override public List<ChangedFile> getFiles() { final List<ChangedFile> changedFiles = new ArrayList<>(); try { final List<CommitFile> files = pullRequestService.getFiles(repository, violationCommentsToGitHubApi.getPullRequestId()); for (final CommitFile commitFile : files) { final List<String> list = new ArrayList<>(); list.add(commitFile.getPatch()); changedFiles.add(new ChangedFile(commitFile.getFilename(), list)); } } catch (final IOException e) { violationsLogger.log(SEVERE, e.getMessage(), e); } return changedFiles; }
@Override public List<Comment> getComments() { final List<Comment> found = new ArrayList<>(); try { final List<GitlabNote> notes = gitlabApi.getAllNotes(mergeRequest); for (final GitlabNote note : notes) { final String identifier = note.getId() + ""; final String content = note.getBody(); final String type = "PR"; final List<String> specifics = new ArrayList<>(); final Comment comment = new Comment(identifier, content, type, specifics); found.add(comment); } } catch (final Throwable e) { violationsLogger.log(SEVERE, "Could not get comments", e); } return found; }
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); } } }
@Override public List<Comment> getComments() { final List<Comment> comments = new ArrayList<>(); try { final List<String> specifics = new ArrayList<>(); for (final CommitComment commitComment : pullRequestService.getComments( repository, violationCommentsToGitHubApi.getPullRequestId())) { comments.add( new Comment( Long.toString(commitComment.getId()), commitComment.getBody(), TYPE_DIFF, specifics)); } for (final org.eclipse.egit.github.core.Comment comment : issueSerivce.getComments(repository, violationCommentsToGitHubApi.getPullRequestId())) { comments.add( new Comment(Long.toString(comment.getId()), comment.getBody(), TYPE_PR, specifics)); } } catch (final Exception e) { violationsLogger.log(SEVERE, e.getMessage(), e); } return comments; }
@Override public void removeComments(final List<Comment> comments) { for (final Comment comment : comments) { try { final GitlabNote noteToDelete = new GitlabNote(); noteToDelete.setId(Integer.parseInt(comment.getIdentifier())); gitlabApi.deleteNote(mergeRequest, noteToDelete); } catch (final Throwable e) { violationsLogger.log( INFO, "Exception thrown when delete note " + comment.getIdentifier() + ". This is probably because of " + "https://github.com/timols/java-gitlab-api/issues/321"); // violationsLogger.log(SEVERE, "Could not delete note " + comment, e); } } }
labels); } catch (final Throwable e) { violationsLogger.log(SEVERE, e.getMessage(), e);
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."); } }
oldComments = filterCommentsWithContent(oldComments, FINGERPRINT); oldComments = filterCommentsWithoutContent(oldComments, FINGERPRINT_ACC); violationsLogger.log( INFO, "Asking " + commentsProvider.getClass().getSimpleName() + " to comment:"); final String singleFileCommentContent = createSingleFileCommentContent(changedFile.get(), violation, commentTemplate); violationsLogger.log( INFO, violation.getReporter()
} catch (final Throwable e) { final String lineSeparator = System.lineSeparator(); violationsLogger.log( SEVERE, "Could not create diff discussion!"
repository, violationCommentsToGitHubApi.getPullRequestId(), commitComment); } catch (final IOException e) { violationsLogger.log( SEVERE, "File: \""