Add setDefault function

This commit is contained in:
Federico Grandi
2020-02-03 16:53:01 +01:00
parent 925751a406
commit 6d08b4f153

View File

@@ -13,12 +13,18 @@ function checkInputs() {
const eventPath = process.env.GITHUB_EVENT_PATH
if (eventPath) {
const { author } = require(eventPath).head_commit
if (!process.env.INPUT_AUTHOR_NAME) process.env.INPUT_AUTHOR_NAME = author.name
if (!process.env.INPUT_AUTHOR_EMAIL) process.env.INPUT_AUTHOR_EMAIL = author.email
setDefault('author_name', author.name)
setDefault('author_email', author.email)
} else {
core.warning('No event path available, unable to fetch author info.')
if (!process.env.INPUT_AUTHOR_NAME) process.env.INPUT_AUTHOR_NAME = 'Add & Commit Action'
if (!process.env.INPUT_AUTHOR_EMAIL) process.env.INPUT_AUTHOR_EMAIL = 'actions@github.com'
setDefault('author_name', 'Add & Commit Action')
setDefault('author_email', 'actions@github.com')
}
core.info(`Using '${core.getInput('author_name')} <${core.getInput('author_email')}>' as author.`)
core.info(`Using '${process.env.INPUT_AUTHOR_NAME} <${process.env.INPUT_AUTHOR_EMAIL}>' as author.`)
}
function setDefault(input: string, value: string) {
const key = 'INPUT_' + input.toUpperCase()
if (!process.env[key]) process.env[key] = value
}