Support find .sarif files recursively
This commit is contained in:
parent
094554cf89
commit
55eae6652f
3 changed files with 24 additions and 15 deletions
19
lib/upload-lib.js
generated
19
lib/upload-lib.js
generated
|
|
@ -72,13 +72,18 @@ async function upload(sarifPath, repositoryNwo, commitOid, ref, analysisKey, ana
|
||||||
throw new Error(`Path does not exist: ${sarifPath}`);
|
throw new Error(`Path does not exist: ${sarifPath}`);
|
||||||
}
|
}
|
||||||
if (fs.lstatSync(sarifPath).isDirectory()) {
|
if (fs.lstatSync(sarifPath).isDirectory()) {
|
||||||
const paths = fs
|
const walkSarifFiles = (dir) => {
|
||||||
.readdirSync(sarifPath)
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||||
.filter((f) => f.endsWith(".sarif"))
|
for (const entry of entries) {
|
||||||
.map((f) => path.resolve(sarifPath, f));
|
if (entry.isFile() && entry.name.endsWith(".sarif")) {
|
||||||
for (const filepath of paths) {
|
sarifFiles.push(path.resolve(dir, entry.name));
|
||||||
sarifFiles.push(filepath);
|
}
|
||||||
}
|
else if (entry.isDirectory()) {
|
||||||
|
walkSarifFiles(path.resolve(dir, entry.name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
walkSarifFiles(sarifPath);
|
||||||
if (sarifFiles.length === 0) {
|
if (sarifFiles.length === 0) {
|
||||||
throw new Error(`No SARIF files found to upload in "${sarifPath}".`);
|
throw new Error(`No SARIF files found to upload in "${sarifPath}".`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -104,13 +104,17 @@ export async function upload(
|
||||||
throw new Error(`Path does not exist: ${sarifPath}`);
|
throw new Error(`Path does not exist: ${sarifPath}`);
|
||||||
}
|
}
|
||||||
if (fs.lstatSync(sarifPath).isDirectory()) {
|
if (fs.lstatSync(sarifPath).isDirectory()) {
|
||||||
const paths = fs
|
const walkSarifFiles = (dir: string) => {
|
||||||
.readdirSync(sarifPath)
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||||
.filter((f) => f.endsWith(".sarif"))
|
for (const entry of entries) {
|
||||||
.map((f) => path.resolve(sarifPath, f));
|
if (entry.isFile() && entry.name.endsWith(".sarif")) {
|
||||||
for (const filepath of paths) {
|
sarifFiles.push(path.resolve(dir, entry.name));
|
||||||
sarifFiles.push(filepath);
|
} else if (entry.isDirectory()) {
|
||||||
}
|
walkSarifFiles(path.resolve(dir, entry.name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
walkSarifFiles(sarifPath);
|
||||||
if (sarifFiles.length === 0) {
|
if (sarifFiles.length === 0) {
|
||||||
throw new Error(`No SARIF files found to upload in "${sarifPath}".`);
|
throw new Error(`No SARIF files found to upload in "${sarifPath}".`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue