@@ -7,6 +7,8 @@ const label = require('./label');
77const addVeracodeIssue = require ( './issue' ) . addVeracodeIssue ;
88const addVeracodeIssueComment = require ( './issue_comment' ) . addVeracodeIssueComment ;
99const core = require ( '@actions/core' ) ;
10+ const fs = require ( 'fs' ) ;
11+ const path = require ( 'path' ) ;
1012
1113// sparse array, element = true if the flaw exists, undefined otherwise
1214var existingFlaws = [ ] ;
@@ -190,6 +192,52 @@ async function processPolicyFlaws(options, flawData) {
190192 continue ;
191193 }
192194
195+ // new auto rewrite path
196+ // new autorewrite file path
197+ function searchFile ( dir , filename ) {
198+ //console.log('Inside search: Directory: '+dir+' - Filename: '+filename)
199+ let result = null ;
200+ const files = fs . readdirSync ( dir ) ;
201+
202+ for ( const file of files ) {
203+ if ( file === '.git' ) continue ;
204+ const fullPath = path . join ( dir , file ) ;
205+ const stat = fs . statSync ( fullPath ) ;
206+
207+ if ( stat . isDirectory ( ) ) {
208+ result = searchFile ( fullPath , filename ) ;
209+ if ( result ) break ;
210+ } else if ( file === filename ) {
211+ console . log ( 'File found: ' + fullPath )
212+ result = fullPath ;
213+ break ;
214+ }
215+ }
216+ //console.log('Result: '+result)
217+ return result ;
218+ }
219+
220+ // Search for the file starting from the current directory
221+ var filename = flaw . finding_details . file_path
222+ const currentDir = process . cwd ( ) ;
223+ console . log ( 'Current Directory: ' + currentDir ) ;
224+ console . log ( 'Filename: ' + filename ) ;
225+ const foundFilePath = searchFile ( currentDir , path . basename ( filename ) ) ;
226+
227+ if ( foundFilePath ) {
228+ //filepath = foundFilePath;
229+ filepath = foundFilePath . replace ( process . cwd ( ) , '' )
230+ console . log ( 'Adjusted Filepath: ' + filepath ) ;
231+ } else {
232+ filepath = filename ;
233+ console . log ( 'File not found in the current directory or its subdirectories.' ) ;
234+ }
235+
236+
237+
238+
239+
240+ /* old rewrite path
193241 //rewrite path
194242 function replacePath (rewrite, path){
195243 replaceValues = rewrite.split(":")
@@ -236,6 +284,8 @@ async function processPolicyFlaws(options, flawData) {
236284 filepath = filename
237285 }
238286
287+ old rewrite path */
288+
239289 linestart = eval ( flaw . finding_details . file_line_number - 5 )
240290 linened = eval ( flaw . finding_details . file_line_number + 5 )
241291
0 commit comments