@Override public List<ChangedFile> getFiles() { final List<ChangedFile> changedFiles = new ArrayList<>(); for (final GitlabCommitDiff change : mergeRequest.getChanges()) { final String filename = change.getNewPath(); final List<String> specifics = new ArrayList<>(); final String patchString = change.getDiff(); specifics.add(patchString); specifics.add(change.getOldPath()); specifics.add(change.getNewPath()); final ChangedFile changedFile = new ChangedFile(filename, specifics); changedFiles.add(changedFile); } return changedFiles; }
/** * When creating comment, the call should use the file as it is specified by the comments * provider. Not the one specified by the {@link Violation}. The one in the {@link Violation} may * not be recognized. <br> * <br> * Here we make a guess on which file in the {@link CommentsProvider} to use. */ static Optional<ChangedFile> findChangedFile( final List<ChangedFile> files, final Violation violation) { for (final ChangedFile providerFile : files) { String violationFile = violation.getFile(); String fileFile = providerFile.getFilename(); if (violationFile.endsWith(fileFile) || fileFile.endsWith(violationFile)) { return ofNullable(providerFile); } } return empty(); } }
@Override public boolean shouldComment(final ChangedFile changedFile, final Integer line) { final String patchString = changedFile.getSpecifics().get(0); final boolean lineChanged = new PatchParser(patchString).isLineInDiff(line); final boolean commentOnlyChangedContent = violationCommentsToGitHubApi.getCommentOnlyChangedContent(); if (commentOnlyChangedContent && !lineChanged) { return false; } return true; }
@Override public void createSingleFileComment( final ChangedFile file, final Integer line, final String comment) { final String patchString = file.getSpecifics().get(0); Optional<Integer> lineToCommentOpt = new PatchParser(patchString).findLineInDiff(line); final Integer lineToComment = lineToCommentOpt.orElse(1); final CommitComment commitComment = new CommitComment(); commitComment.setBody(comment); commitComment.setPath(file.getFilename()); commitComment.setCommitId(pullRequestCommit); commitComment.setPosition(lineToComment);
@Override public boolean shouldComment(final ChangedFile changedFile, final Integer line) { final String patchString = changedFile.getSpecifics().get(0); if (!violationCommentsToGitLabApi.getCommentOnlyChangedContent()) return true; return new PatchParser(patchString) // .isLineInDiff(line); }
.map((f) -> f.getFilename()) //
@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; }
final String startSha = mergeRequest.getStartSha(); final String headSha = mergeRequest.getHeadSha(); final String patchString = file.getSpecifics().get(0); final String oldPath = file.getSpecifics().get(1); final String newPath = file.getSpecifics().get(2); Integer oldLine = new PatchParser(patchString) //
+ violation.getRule() + " " + changedFile.get().getFilename() + " " + violation.getStartLine()