@@ -5,27 +5,29 @@ import JSON5 from 'json5'
5
5
const jsonTypes = [ 'json' , 'jsonc' , 'json5' ]
6
6
7
7
const getFilePath = ( configurationPath : string ) : string | undefined => {
8
- const repoPath = `./ ${ configurationPath } `
9
- . replace ( '//' , '/' )
10
- . replace ( './. /' , '. /' )
11
- if ( configurationPath . includes ( '.json' ) && fs . existsSync ( repoPath ) )
12
- return repoPath
13
- if ( ! configurationPath . includes ( '.json' ) ) {
14
- let allFiles
15
- try {
16
- allFiles = fs . readdirSync ( repoPath )
17
- } catch ( error : any ) {
18
- core . warning (
19
- `Could not read configuration file at ${ repoPath } : ${ error . message } . Skipping.`
8
+ try {
9
+ const repoPath = `./ ${ configurationPath } `
10
+ . replace ( '/ /' , '/' )
11
+ . replace ( '././' , './' )
12
+ if ( configurationPath . includes ( '.json' ) && fs . existsSync ( repoPath ) )
13
+ return repoPath
14
+ if ( ! configurationPath . includes ( '.json' ) ) {
15
+ const allFiles = fs . readdirSync ( repoPath )
16
+
17
+ const expectedFilenames = jsonTypes . map ( ( type ) => `auto-label. ${ type } ` )
18
+ const files = allFiles . filter ( ( filename ) =>
19
+ expectedFilenames . includes ( filename )
20
20
)
21
- return
21
+ if ( ! files . length ) {
22
+ throw new Error ( 'No default files located.' )
23
+ }
24
+ return `${ repoPath } /${ files [ 0 ] } ` . replace ( '//' , '/' )
22
25
}
23
- const expectedFilenames = jsonTypes . map ( ( type ) => `auto-label. ${ type } ` )
24
- const files = allFiles . filter ( ( filename ) =>
25
- expectedFilenames . includes ( filename )
26
+ } catch ( error : any ) {
27
+ core . warning (
28
+ `Could not read configuration file, configurationPath: " ${ configurationPath } ", error: " ${ error . message } ". Skipping.`
26
29
)
27
- if ( ! files . length ) return
28
- return `${ repoPath } /${ files [ 0 ] } ` . replace ( '//' , '/' )
30
+ return
29
31
}
30
32
}
31
33
0 commit comments