Skip to content

Commit

Permalink
auto rewrite path
Browse files Browse the repository at this point in the history
  • Loading branch information
julz0815 committed Nov 18, 2024
1 parent 3dcb2d9 commit 1001ec5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Archive.zip
package-lock.json
.DS_Store
Archive.zip
.DS_Store

47 changes: 47 additions & 0 deletions pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 1001ec5

Please sign in to comment.