Skip to content

Commit

Permalink
Merge pull request #84 from Renato66/83-retro-compatibility
Browse files Browse the repository at this point in the history
fix: avoid repo path not available in container
  • Loading branch information
Renato66 authored Jun 25, 2024
2 parents 285e7bf + 5abd9ac commit ba078ed
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/domain/getLabelConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@ import JSON5 from 'json5'
const jsonTypes = ['json', 'jsonc', 'json5']

const getFilePath = (configurationPath: string): string | undefined => {
const repoPath = `./${configurationPath}`
.replace('//', '/')
.replace('././', './')
if (configurationPath.includes('.json') && fs.existsSync(repoPath))
return repoPath
if (!configurationPath.includes('.json')) {
const allFiles = fs.readdirSync(repoPath)
const files = allFiles.filter((elem) =>
jsonTypes.map((elem) => `auto-label.${elem}`).includes(elem)
try {
const repoPath = `./${configurationPath}`
.replace('//', '/')
.replace('././', './')
if (configurationPath.includes('.json') && fs.existsSync(repoPath))
return repoPath
if (!configurationPath.includes('.json')) {
const allFiles = fs.readdirSync(repoPath)

const expectedFilenames = jsonTypes.map((type) => `auto-label.${type}`)
const files = allFiles.filter((filename) =>
expectedFilenames.includes(filename)
)
if (!files.length) {
throw new Error('No default files located.')
}
return `${repoPath}/${files[0]}`.replace('//', '/')
}
} catch (error: any) {
core.warning(
`Could not read configuration file, configurationPath: "${configurationPath}", error: "${error.message}". Skipping.`
)
if (!files.length) return
return `${repoPath}/${files[0]}`.replace('//', '/')
return
}
}

Expand Down

0 comments on commit ba078ed

Please sign in to comment.