UNPKG

danger-plugin-lint-report

Version:

This plugin reads checkstyle / lint reports and posts issues and violations as inline comments in pull requests.

42 lines (41 loc) 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getChangedLinesByFile = exports.isFileInChangeset = void 0; /** * If a git object is supplied, this function checks if a given relative file path * is within the changeset (modified + created files). * @param git Git object * @param relativeFilePath Sanitized file path to match with the changeset */ function isFileInChangeset(git, relativeFilePath) { if (git) { const isModified = git.modified_files.includes(relativeFilePath); const isAdded = git.created_files.includes(relativeFilePath); if (isModified || isAdded) { // get changed lines return true; } } else { return true; } return false; } exports.isFileInChangeset = isFileInChangeset; function getChangedLinesByFile(git, relativeFilePath) { return git.structuredDiffForFile(relativeFilePath).then(diff => { const lines = []; if (diff) { diff.chunks.forEach(chunk => { chunk.changes.forEach(change => { if (change.type === "add") { // is addition lines.push(change.ln); } }); }); } return lines; }); } exports.getChangedLinesByFile = getChangedLinesByFile;