-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: compatible working-directory+only-new-issues
- Loading branch information
1 parent
5e67631
commit 2408682
Showing
4 changed files
with
214 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |