diff --git a/dist/post_run/index.js b/dist/post_run/index.js index 2ee8638c72..3108ca31ab 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -66544,6 +66544,7 @@ const tmp_1 = __nccwpck_require__(8517); const util_1 = __nccwpck_require__(3837); const cache_1 = __nccwpck_require__(4810); const install_1 = __nccwpck_require__(1649); +const diffUtils_1 = __nccwpck_require__(3617); const version_1 = __nccwpck_require__(1946); const execShellCommand = (0, util_1.promisify)(child_process_1.exec); const writeFile = (0, util_1.promisify)(fs.writeFile); @@ -66600,7 +66601,7 @@ function fetchPatch() { const tempDir = yield createTempDir(); const patchPath = path.join(tempDir, "pull.patch"); core.info(`Writing patch to ${patchPath}`); - yield writeFile(patchPath, patch); + yield writeFile(patchPath, (0, diffUtils_1.alterDiffFile)(patch)); return patchPath; } catch (err) { @@ -66669,10 +66670,6 @@ function runLint(lintPath, patchPath) { const workingDirectory = core.getInput(`working-directory`); const cmdArgs = {}; if (workingDirectory) { - if (patchPath) { - // TODO: make them compatible - throw new Error(`options working-directory and only-new-issues aren't compatible`); - } if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) { throw new Error(`working-directory (${workingDirectory}) was not a path`); } @@ -66798,6 +66795,88 @@ function isValidEvent() { exports.isValidEvent = isValidEvent; +/***/ }), + +/***/ 3617: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.alterDiffFile = void 0; +const core = __importStar(__nccwpck_require__(2186)); +const path = __importStar(__nccwpck_require__(1017)); +// If needed alter diff file to be compatible with working directory +function alterDiffFile(diffFile) { + let workingDirectory = core.getInput(`working-directory`); + if (workingDirectory) { + const workspace = process.env["GITHUB_WORKSPACE"] || ""; + const relativeFile = path.relative(workspace, workingDirectory); + workingDirectory = relativeFile; + const diffLines = diffFile.split("\n"); + let ignore = false; + const filteredDiffLines = []; + for (const line of diffLines) { + if (line.startsWith("diff --git")) { + if (line.includes(`a/${workingDirectory}/`)) { + ignore = false; + filteredDiffLines.push(line.replace(` a/${workingDirectory}/`, " a/").replace(` b/${workingDirectory}/`, " b/")); + } + else { + ignore = true; + } + } + else { + if (!ignore) { + if (line.startsWith(`--- a/${workingDirectory}/`)) { + filteredDiffLines.push(line.replace(`--- a/${workingDirectory}/`, "--- a/")); + } + else if (line.startsWith(`+++ a/${workingDirectory}/`)) { + filteredDiffLines.push(line.replace(`+++ a/${workingDirectory}/`, "+++ a/")); + } + else if (line.startsWith(`--- b/${workingDirectory}/`)) { + filteredDiffLines.push(line.replace(`--- b/${workingDirectory}/`, "--- b/")); + } + else if (line.startsWith(`+++ b/${workingDirectory}/`)) { + filteredDiffLines.push(line.replace(`+++ b/${workingDirectory}/`, "+++ b/")); + } + else { + filteredDiffLines.push(line); + } + } + } + } + // Join the modified lines back into a diff string + diffFile = filteredDiffLines.join("\n"); + } + return diffFile; +} +exports.alterDiffFile = alterDiffFile; + + /***/ }), /***/ 1946: diff --git a/dist/run/index.js b/dist/run/index.js index d70a263b08..8e8bbb9396 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -66544,6 +66544,7 @@ const tmp_1 = __nccwpck_require__(8517); const util_1 = __nccwpck_require__(3837); const cache_1 = __nccwpck_require__(4810); const install_1 = __nccwpck_require__(1649); +const diffUtils_1 = __nccwpck_require__(3617); const version_1 = __nccwpck_require__(1946); const execShellCommand = (0, util_1.promisify)(child_process_1.exec); const writeFile = (0, util_1.promisify)(fs.writeFile); @@ -66600,7 +66601,7 @@ function fetchPatch() { const tempDir = yield createTempDir(); const patchPath = path.join(tempDir, "pull.patch"); core.info(`Writing patch to ${patchPath}`); - yield writeFile(patchPath, patch); + yield writeFile(patchPath, (0, diffUtils_1.alterDiffFile)(patch)); return patchPath; } catch (err) { @@ -66669,10 +66670,6 @@ function runLint(lintPath, patchPath) { const workingDirectory = core.getInput(`working-directory`); const cmdArgs = {}; if (workingDirectory) { - if (patchPath) { - // TODO: make them compatible - throw new Error(`options working-directory and only-new-issues aren't compatible`); - } if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) { throw new Error(`working-directory (${workingDirectory}) was not a path`); } @@ -66798,6 +66795,88 @@ function isValidEvent() { exports.isValidEvent = isValidEvent; +/***/ }), + +/***/ 3617: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.alterDiffFile = void 0; +const core = __importStar(__nccwpck_require__(2186)); +const path = __importStar(__nccwpck_require__(1017)); +// If needed alter diff file to be compatible with working directory +function alterDiffFile(diffFile) { + let workingDirectory = core.getInput(`working-directory`); + if (workingDirectory) { + const workspace = process.env["GITHUB_WORKSPACE"] || ""; + const relativeFile = path.relative(workspace, workingDirectory); + workingDirectory = relativeFile; + const diffLines = diffFile.split("\n"); + let ignore = false; + const filteredDiffLines = []; + for (const line of diffLines) { + if (line.startsWith("diff --git")) { + if (line.includes(`a/${workingDirectory}/`)) { + ignore = false; + filteredDiffLines.push(line.replace(` a/${workingDirectory}/`, " a/").replace(` b/${workingDirectory}/`, " b/")); + } + else { + ignore = true; + } + } + else { + if (!ignore) { + if (line.startsWith(`--- a/${workingDirectory}/`)) { + filteredDiffLines.push(line.replace(`--- a/${workingDirectory}/`, "--- a/")); + } + else if (line.startsWith(`+++ a/${workingDirectory}/`)) { + filteredDiffLines.push(line.replace(`+++ a/${workingDirectory}/`, "+++ a/")); + } + else if (line.startsWith(`--- b/${workingDirectory}/`)) { + filteredDiffLines.push(line.replace(`--- b/${workingDirectory}/`, "--- b/")); + } + else if (line.startsWith(`+++ b/${workingDirectory}/`)) { + filteredDiffLines.push(line.replace(`+++ b/${workingDirectory}/`, "+++ b/")); + } + else { + filteredDiffLines.push(line); + } + } + } + } + // Join the modified lines back into a diff string + diffFile = filteredDiffLines.join("\n"); + } + return diffFile; +} +exports.alterDiffFile = alterDiffFile; + + /***/ }), /***/ 1946: diff --git a/src/run.ts b/src/run.ts index df82c2cfa5..a0ef68d1ca 100644 --- a/src/run.ts +++ b/src/run.ts @@ -8,6 +8,7 @@ import { promisify } from "util" import { restoreCache, saveCache } from "./cache" import { installLint, InstallMode } from "./install" +import { alterDiffFile } from "./utils/diffUtils" import { findLintVersion } from "./version" const execShellCommand = promisify(exec) @@ -68,7 +69,7 @@ async function fetchPatch(): Promise { const tempDir = await createTempDir() const patchPath = path.join(tempDir, "pull.patch") core.info(`Writing patch to ${patchPath}`) - await writeFile(patchPath, patch) + await writeFile(patchPath, alterDiffFile(patch)) return patchPath } catch (err) { console.warn(`failed to save pull request patch:`, err) @@ -157,10 +158,6 @@ async function runLint(lintPath: string, patchPath: string): Promise { const workingDirectory = core.getInput(`working-directory`) const cmdArgs: ExecOptions = {} if (workingDirectory) { - if (patchPath) { - // TODO: make them compatible - throw new Error(`options working-directory and only-new-issues aren't compatible`) - } if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) { throw new Error(`working-directory (${workingDirectory}) was not a path`) } diff --git a/src/utils/diffUtils.ts b/src/utils/diffUtils.ts new file mode 100644 index 0000000000..10441595b6 --- /dev/null +++ b/src/utils/diffUtils.ts @@ -0,0 +1,44 @@ +import * as core from "@actions/core" +import * as path from "path" + +// If needed alter diff file to be compatible with working directory +export function alterDiffFile(diffFile: string): string { + let workingDirectory = core.getInput(`working-directory`) + if (workingDirectory) { + const workspace = process.env["GITHUB_WORKSPACE"] || "" + const relativeFile = path.relative(workspace, workingDirectory) + workingDirectory = relativeFile + + const diffLines = diffFile.split("\n") + let ignore = false + const filteredDiffLines = [] + + for (const line of diffLines) { + if (line.startsWith("diff --git")) { + if (line.includes(`a/${workingDirectory}/`)) { + ignore = false + filteredDiffLines.push(line.replace(` a/${workingDirectory}/`, " a/").replace(` b/${workingDirectory}/`, " b/")) + } else { + ignore = true + } + } else { + if (!ignore) { + if (line.startsWith(`--- a/${workingDirectory}/`)) { + filteredDiffLines.push(line.replace(`--- a/${workingDirectory}/`, "--- a/")) + } else if (line.startsWith(`+++ a/${workingDirectory}/`)) { + filteredDiffLines.push(line.replace(`+++ a/${workingDirectory}/`, "+++ a/")) + } else if (line.startsWith(`--- b/${workingDirectory}/`)) { + filteredDiffLines.push(line.replace(`--- b/${workingDirectory}/`, "--- b/")) + } else if (line.startsWith(`+++ b/${workingDirectory}/`)) { + filteredDiffLines.push(line.replace(`+++ b/${workingDirectory}/`, "+++ b/")) + } else { + filteredDiffLines.push(line) + } + } + } + } + // Join the modified lines back into a diff string + diffFile = filteredDiffLines.join("\n") + } + return diffFile +}