Skip to content

Commit

Permalink
🐛 Fix parsing of boolean config options [skip-ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
BetaHuhn committed Jan 10, 2021
1 parent d8e4a79 commit b7e5310
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ require('dotenv').config()

const REPLACE_DEFAULT = true

const getVar = ({ key, default: dft, required = false, array = false }) => {
const getVar = ({ key, default: dft, required = false, type = 'string' }) => {
const coreVar = core.getInput(key)
const envVar = process.env[key]

if (required === false && (coreVar === false || envVar === 'false'))
if (key === 'PR_LABELS' && (coreVar === false || envVar === 'false'))
return undefined

if (coreVar !== undefined && coreVar.length >= 1)
return array ? coreVar.split('\n') : coreVar
if (coreVar !== undefined && coreVar.length >= 1) {
if (type === 'array') return coreVar.split('\n')

if (envVar !== undefined && envVar.length >= 1)
return array ? envVar.split(',') : envVar
return coreVar
}

if (envVar !== undefined && envVar.length >= 1) {
if (type === 'array') return envVar.split(',')
if (type === 'boolean') return envVar === 'true'

return envVar
}

if (required === true)
return core.setFailed(`Variable ${ key } missing.`)
Expand Down Expand Up @@ -47,25 +54,25 @@ const context = {
}),
COMMIT_EACH_FILE: getVar({
key: 'COMMIT_EACH_FILE',
type: 'boolean',
default: true
}),
PR_LABELS: getVar({
key: 'PR_LABELS',
default: [ 'sync' ],
required: false,
array: true
type: 'array'
}),
ASSIGNEES: getVar({
key: 'ASSIGNEES',
required: false,
array: true
type: 'array'
}),
TMP_DIR: getVar({
key: 'TMP_DIR',
default: `tmp-${ Date.now().toString() }`
}),
DRY_RUN: getVar({
key: 'DRY_RUN',
type: 'boolean',
default: false
}),
GITHUB_REPOSITORY: getVar({
Expand Down

0 comments on commit b7e5310

Please sign in to comment.