Skip to content

Commit b174c03

Browse files
committed
fix: compatible working-directory+only-new-issues
1 parent a422a81 commit b174c03

File tree

4 files changed

+214
-15
lines changed

4 files changed

+214
-15
lines changed

dist/post_run/index.js

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66544,6 +66544,7 @@ const tmp_1 = __nccwpck_require__(8517);
6654466544
const util_1 = __nccwpck_require__(3837);
6654566545
const cache_1 = __nccwpck_require__(4810);
6654666546
const install_1 = __nccwpck_require__(1649);
66547+
const diffUtils_1 = __nccwpck_require__(3617);
6654766548
const version_1 = __nccwpck_require__(1946);
6654866549
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
6654966550
const writeFile = (0, util_1.promisify)(fs.writeFile);
@@ -66600,7 +66601,7 @@ function fetchPatch() {
6660066601
const tempDir = yield createTempDir();
6660166602
const patchPath = path.join(tempDir, "pull.patch");
6660266603
core.info(`Writing patch to ${patchPath}`);
66603-
yield writeFile(patchPath, patch);
66604+
yield writeFile(patchPath, (0, diffUtils_1.alterDiffFile)(patch));
6660466605
return patchPath;
6660566606
}
6660666607
catch (err) {
@@ -66669,10 +66670,6 @@ function runLint(lintPath, patchPath) {
6666966670
const workingDirectory = core.getInput(`working-directory`);
6667066671
const cmdArgs = {};
6667166672
if (workingDirectory) {
66672-
if (patchPath) {
66673-
// TODO: make them compatible
66674-
throw new Error(`options working-directory and only-new-issues aren't compatible`);
66675-
}
6667666673
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
6667766674
throw new Error(`working-directory (${workingDirectory}) was not a path`);
6667866675
}
@@ -66798,6 +66795,88 @@ function isValidEvent() {
6679866795
exports.isValidEvent = isValidEvent;
6679966796

6680066797

66798+
/***/ }),
66799+
66800+
/***/ 3617:
66801+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
66802+
66803+
"use strict";
66804+
66805+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
66806+
if (k2 === undefined) k2 = k;
66807+
var desc = Object.getOwnPropertyDescriptor(m, k);
66808+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
66809+
desc = { enumerable: true, get: function() { return m[k]; } };
66810+
}
66811+
Object.defineProperty(o, k2, desc);
66812+
}) : (function(o, m, k, k2) {
66813+
if (k2 === undefined) k2 = k;
66814+
o[k2] = m[k];
66815+
}));
66816+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
66817+
Object.defineProperty(o, "default", { enumerable: true, value: v });
66818+
}) : function(o, v) {
66819+
o["default"] = v;
66820+
});
66821+
var __importStar = (this && this.__importStar) || function (mod) {
66822+
if (mod && mod.__esModule) return mod;
66823+
var result = {};
66824+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
66825+
__setModuleDefault(result, mod);
66826+
return result;
66827+
};
66828+
Object.defineProperty(exports, "__esModule", ({ value: true }));
66829+
exports.alterDiffFile = void 0;
66830+
const core = __importStar(__nccwpck_require__(2186));
66831+
const path = __importStar(__nccwpck_require__(1017));
66832+
// If needed alter diff file to be compatible with working directory
66833+
function alterDiffFile(diffFile) {
66834+
let workingDirectory = core.getInput(`working-directory`);
66835+
if (workingDirectory) {
66836+
const workspace = process.env["GITHUB_WORKSPACE"] || "";
66837+
const relativeFile = path.relative(workspace, workingDirectory);
66838+
workingDirectory = relativeFile;
66839+
const diffLines = diffFile.split("\n");
66840+
let ignore = false;
66841+
const filteredDiffLines = [];
66842+
for (const line of diffLines) {
66843+
if (line.startsWith("diff --git")) {
66844+
if (line.includes(`a/${workingDirectory}/`)) {
66845+
ignore = false;
66846+
filteredDiffLines.push(line.replace(` a/${workingDirectory}/`, " a/").replace(` b/${workingDirectory}/`, " b/"));
66847+
}
66848+
else {
66849+
ignore = true;
66850+
}
66851+
}
66852+
else {
66853+
if (!ignore) {
66854+
if (line.startsWith(`--- a/${workingDirectory}/`)) {
66855+
filteredDiffLines.push(line.replace(`--- a/${workingDirectory}/`, "--- a/"));
66856+
}
66857+
else if (line.startsWith(`+++ a/${workingDirectory}/`)) {
66858+
filteredDiffLines.push(line.replace(`+++ a/${workingDirectory}/`, "+++ a/"));
66859+
}
66860+
else if (line.startsWith(`--- b/${workingDirectory}/`)) {
66861+
filteredDiffLines.push(line.replace(`--- b/${workingDirectory}/`, "--- b/"));
66862+
}
66863+
else if (line.startsWith(`+++ b/${workingDirectory}/`)) {
66864+
filteredDiffLines.push(line.replace(`+++ b/${workingDirectory}/`, "+++ b/"));
66865+
}
66866+
else {
66867+
filteredDiffLines.push(line);
66868+
}
66869+
}
66870+
}
66871+
}
66872+
// Join the modified lines back into a diff string
66873+
diffFile = filteredDiffLines.join("\n");
66874+
}
66875+
return diffFile;
66876+
}
66877+
exports.alterDiffFile = alterDiffFile;
66878+
66879+
6680166880
/***/ }),
6680266881

6680366882
/***/ 1946:

dist/run/index.js

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66544,6 +66544,7 @@ const tmp_1 = __nccwpck_require__(8517);
6654466544
const util_1 = __nccwpck_require__(3837);
6654566545
const cache_1 = __nccwpck_require__(4810);
6654666546
const install_1 = __nccwpck_require__(1649);
66547+
const diffUtils_1 = __nccwpck_require__(3617);
6654766548
const version_1 = __nccwpck_require__(1946);
6654866549
const execShellCommand = (0, util_1.promisify)(child_process_1.exec);
6654966550
const writeFile = (0, util_1.promisify)(fs.writeFile);
@@ -66600,7 +66601,7 @@ function fetchPatch() {
6660066601
const tempDir = yield createTempDir();
6660166602
const patchPath = path.join(tempDir, "pull.patch");
6660266603
core.info(`Writing patch to ${patchPath}`);
66603-
yield writeFile(patchPath, patch);
66604+
yield writeFile(patchPath, (0, diffUtils_1.alterDiffFile)(patch));
6660466605
return patchPath;
6660566606
}
6660666607
catch (err) {
@@ -66669,10 +66670,6 @@ function runLint(lintPath, patchPath) {
6666966670
const workingDirectory = core.getInput(`working-directory`);
6667066671
const cmdArgs = {};
6667166672
if (workingDirectory) {
66672-
if (patchPath) {
66673-
// TODO: make them compatible
66674-
throw new Error(`options working-directory and only-new-issues aren't compatible`);
66675-
}
6667666673
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
6667766674
throw new Error(`working-directory (${workingDirectory}) was not a path`);
6667866675
}
@@ -66798,6 +66795,88 @@ function isValidEvent() {
6679866795
exports.isValidEvent = isValidEvent;
6679966796

6680066797

66798+
/***/ }),
66799+
66800+
/***/ 3617:
66801+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
66802+
66803+
"use strict";
66804+
66805+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
66806+
if (k2 === undefined) k2 = k;
66807+
var desc = Object.getOwnPropertyDescriptor(m, k);
66808+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
66809+
desc = { enumerable: true, get: function() { return m[k]; } };
66810+
}
66811+
Object.defineProperty(o, k2, desc);
66812+
}) : (function(o, m, k, k2) {
66813+
if (k2 === undefined) k2 = k;
66814+
o[k2] = m[k];
66815+
}));
66816+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
66817+
Object.defineProperty(o, "default", { enumerable: true, value: v });
66818+
}) : function(o, v) {
66819+
o["default"] = v;
66820+
});
66821+
var __importStar = (this && this.__importStar) || function (mod) {
66822+
if (mod && mod.__esModule) return mod;
66823+
var result = {};
66824+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
66825+
__setModuleDefault(result, mod);
66826+
return result;
66827+
};
66828+
Object.defineProperty(exports, "__esModule", ({ value: true }));
66829+
exports.alterDiffFile = void 0;
66830+
const core = __importStar(__nccwpck_require__(2186));
66831+
const path = __importStar(__nccwpck_require__(1017));
66832+
// If needed alter diff file to be compatible with working directory
66833+
function alterDiffFile(diffFile) {
66834+
let workingDirectory = core.getInput(`working-directory`);
66835+
if (workingDirectory) {
66836+
const workspace = process.env["GITHUB_WORKSPACE"] || "";
66837+
const relativeFile = path.relative(workspace, workingDirectory);
66838+
workingDirectory = relativeFile;
66839+
const diffLines = diffFile.split("\n");
66840+
let ignore = false;
66841+
const filteredDiffLines = [];
66842+
for (const line of diffLines) {
66843+
if (line.startsWith("diff --git")) {
66844+
if (line.includes(`a/${workingDirectory}/`)) {
66845+
ignore = false;
66846+
filteredDiffLines.push(line.replace(` a/${workingDirectory}/`, " a/").replace(` b/${workingDirectory}/`, " b/"));
66847+
}
66848+
else {
66849+
ignore = true;
66850+
}
66851+
}
66852+
else {
66853+
if (!ignore) {
66854+
if (line.startsWith(`--- a/${workingDirectory}/`)) {
66855+
filteredDiffLines.push(line.replace(`--- a/${workingDirectory}/`, "--- a/"));
66856+
}
66857+
else if (line.startsWith(`+++ a/${workingDirectory}/`)) {
66858+
filteredDiffLines.push(line.replace(`+++ a/${workingDirectory}/`, "+++ a/"));
66859+
}
66860+
else if (line.startsWith(`--- b/${workingDirectory}/`)) {
66861+
filteredDiffLines.push(line.replace(`--- b/${workingDirectory}/`, "--- b/"));
66862+
}
66863+
else if (line.startsWith(`+++ b/${workingDirectory}/`)) {
66864+
filteredDiffLines.push(line.replace(`+++ b/${workingDirectory}/`, "+++ b/"));
66865+
}
66866+
else {
66867+
filteredDiffLines.push(line);
66868+
}
66869+
}
66870+
}
66871+
}
66872+
// Join the modified lines back into a diff string
66873+
diffFile = filteredDiffLines.join("\n");
66874+
}
66875+
return diffFile;
66876+
}
66877+
exports.alterDiffFile = alterDiffFile;
66878+
66879+
6680166880
/***/ }),
6680266881

6680366882
/***/ 1946:

src/run.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { promisify } from "util"
88

99
import { restoreCache, saveCache } from "./cache"
1010
import { installLint, InstallMode } from "./install"
11+
import { alterDiffFile } from "./utils/diffUtils"
1112
import { findLintVersion } from "./version"
1213

1314
const execShellCommand = promisify(exec)
@@ -68,7 +69,7 @@ async function fetchPatch(): Promise<string> {
6869
const tempDir = await createTempDir()
6970
const patchPath = path.join(tempDir, "pull.patch")
7071
core.info(`Writing patch to ${patchPath}`)
71-
await writeFile(patchPath, patch)
72+
await writeFile(patchPath, alterDiffFile(patch))
7273
return patchPath
7374
} catch (err) {
7475
console.warn(`failed to save pull request patch:`, err)
@@ -157,10 +158,6 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
157158
const workingDirectory = core.getInput(`working-directory`)
158159
const cmdArgs: ExecOptions = {}
159160
if (workingDirectory) {
160-
if (patchPath) {
161-
// TODO: make them compatible
162-
throw new Error(`options working-directory and only-new-issues aren't compatible`)
163-
}
164161
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
165162
throw new Error(`working-directory (${workingDirectory}) was not a path`)
166163
}

src/utils/diffUtils.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as core from "@actions/core"
2+
import * as path from "path"
3+
4+
// If needed alter diff file to be compatible with working directory
5+
export function alterDiffFile(diffFile: string): string {
6+
let workingDirectory = core.getInput(`working-directory`)
7+
if (workingDirectory) {
8+
const workspace = process.env["GITHUB_WORKSPACE"] || ""
9+
const relativeFile = path.relative(workspace, workingDirectory)
10+
workingDirectory = relativeFile
11+
12+
const diffLines = diffFile.split("\n")
13+
let ignore = false
14+
const filteredDiffLines = []
15+
16+
for (const line of diffLines) {
17+
if (line.startsWith("diff --git")) {
18+
if (line.includes(`a/${workingDirectory}/`)) {
19+
ignore = false
20+
filteredDiffLines.push(line.replace(` a/${workingDirectory}/`, " a/").replace(` b/${workingDirectory}/`, " b/"))
21+
} else {
22+
ignore = true
23+
}
24+
} else {
25+
if (!ignore) {
26+
if (line.startsWith(`--- a/${workingDirectory}/`)) {
27+
filteredDiffLines.push(line.replace(`--- a/${workingDirectory}/`, "--- a/"))
28+
} else if (line.startsWith(`+++ a/${workingDirectory}/`)) {
29+
filteredDiffLines.push(line.replace(`+++ a/${workingDirectory}/`, "+++ a/"))
30+
} else if (line.startsWith(`--- b/${workingDirectory}/`)) {
31+
filteredDiffLines.push(line.replace(`--- b/${workingDirectory}/`, "--- b/"))
32+
} else if (line.startsWith(`+++ b/${workingDirectory}/`)) {
33+
filteredDiffLines.push(line.replace(`+++ b/${workingDirectory}/`, "+++ b/"))
34+
} else {
35+
filteredDiffLines.push(line)
36+
}
37+
}
38+
}
39+
}
40+
// Join the modified lines back into a diff string
41+
diffFile = filteredDiffLines.join("\n")
42+
}
43+
return diffFile
44+
}

0 commit comments

Comments
 (0)