Ignore comments and empty elements

This commit is contained in:
Henry Painter 2022-08-15 21:14:23 +01:00
parent 14827485d3
commit aeb7b41165
2 changed files with 15 additions and 4 deletions

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View file

@ -14,7 +14,9 @@ async function run(): Promise<void> {
process.chdir(workingDirectory)
}
const globalIgnore = core.getInput('global-ignore', {required: false})
const globalIgnoreArray: excludesFilter = globalIgnore ? getConfigFileContent(globalIgnore).split(/\r?\n/) : []
const globalIgnoreArray: excludesFilter = globalIgnore
? ignoreComments(getConfigFileContent(globalIgnore).split(/\r?\n/))
: []
const customfiles = core.getInput('files', {required: false})
const token = core.getInput('token', {required: false})
const ref = core.getInput('ref', {required: false})
@ -25,7 +27,7 @@ async function run(): Promise<void> {
const initialFetchDepth = parseInt(core.getInput('initial-fetch-depth', {required: false})) || 10
const files = customfiles
? parseFilesInput(customfiles.split(/\r?\n/))
? parseFilesInput(ignoreComments(customfiles.split(/\r?\n/)))
: await getChangedFiles(token, base, ref, initialFetchDepth)
if (!isExportFormat(listFiles)) {
@ -63,7 +65,6 @@ function parseFilesInput(customfiles: string[]): File[] {
} else {
throw new Error(`Line '${i + 1}' in custom file: '${customfiles[i]}' is not parseable.`)
}
files.push({
status: git.statusMap[filestatus],
filename: filename
@ -76,6 +77,16 @@ function isPathInput(text: string): boolean {
return !(text.includes('\n') || text.includes(':'))
}
function ignoreComments(stringArray: string[]): string[] {
const nocomments: string[] = []
for (let i = 0; i + 1 < stringArray.length; i += 1) {
if (!stringArray[i].startsWith('#')) {
nocomments.push(stringArray[i])
}
}
return nocomments
}
function getConfigFileContent(configPath: string): string {
if (!fs.existsSync(configPath)) {
throw new Error(`Configuration file '${configPath}' not found`)