@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); } } }
static List<Comment> filterCommentsWithoutContent( final List<Comment> unfilteredComments, final String containing) { final List<Comment> filteredComments = new ArrayList<>(); for (final Comment comment : unfilteredComments) { if (!comment.getContent().trim().contains(containing.trim())) { filteredComments.add(comment); } } return filteredComments; }
@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; }
@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); } } }
@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; }
static List<Comment> filterCommentsWithContent( final List<Comment> unfilteredComments, final String containing) { final List<Comment> filteredComments = new ArrayList<>(); for (final Comment comment : unfilteredComments) { if (comment.getContent().trim().contains(containing.trim())) { filteredComments.add(comment); } } return filteredComments; }
static ViolationComments getViolationComments( final List<Comment> comments, final List<Violation> violations) { final List<Violation> madeViolations = new ArrayList<>(); final List<Comment> madeComments = new ArrayList<>(); for (final Violation violation : violations) { for (final Comment candidate : comments) { final boolean containsIdentifier = candidate.getContent().contains(identifier(violation) + ""); if (containsIdentifier) { madeViolations.add(violation); madeComments.add(candidate); } } } return new ViolationComments(madeComments, madeViolations); } }