diff --git a/.gitignore b/.gitignore index 5aefa90..3387d5d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ Archive.zip package-lock.json .DS_Store Archive.zip -.DS_Store + diff --git a/pipeline.js b/pipeline.js index b268e62..253f8f6 100644 --- a/pipeline.js +++ b/pipeline.js @@ -6,6 +6,8 @@ const { request } = require('@octokit/request'); const label = require('./label'); const addVeracodeIssue = require('./issue').addVeracodeIssue; const addVeracodeIssueComment = require('./issue_comment').addVeracodeIssueComment; +const fs = require('fs'); +const path = require('path'); /* Map of files that contain flaws * each entry is a struct of {CWE, line_number} @@ -219,6 +221,48 @@ async function processPipelineFlaws(options, flawData) { continue; } + // new autorewrite file path + function searchFile(dir, filename) { + let result = null; + const files = fs.readdirSync(dir); + + for (const file of files) { + const fullPath = path.join(dir, file); + const stat = fs.statSync(fullPath); + + if (stat.isDirectory()) { + result = searchFile(fullPath, filename); + if (result) break; + } else if (file === filename) { + result = fullPath; + break; + } + } + console.log('Result: '+result) + return result; + } + + //newPath = path.replace(replaceValues[0], replaceValues[1]); + //console.log('new Path:' + newPath); + + + // Search for the file starting from the current directory + var filename = flaw.files.source_file.file + const currentDir = process.cwd(); + console.log('Current Directory: ' + currentDir); + const foundFilePath = searchFile(currentDir, path.basename(filename)); + + if (foundFilePath) { + filepath = foundFilePath; + console.log('Adjusted Filepath: ' + filepath); + } else { + filepath = filename; + console.log('File not found in the current directory or its subdirectories.'); + } + + +/* old rewrite path + //rewrite path function replacePath (rewrite, path){ @@ -253,6 +297,9 @@ async function processPipelineFlaws(options, flawData) { console.log('Filepath:'+filepath); } +old rewrite path */ + + linestart = eval(flaw.files.source_file.line-5) linened = eval(flaw.files.source_file.line+5)