Fix: allow action to work without head_commit

Ref: Issue #22
This commit is contained in:
Federico Grandi
2020-03-20 15:11:47 +01:00
parent 61d14d1bee
commit 7bd2b1ca10

View File

@@ -11,15 +11,17 @@ try {
function checkInputs() {
const eventPath = process.env.GITHUB_EVENT_PATH
if (eventPath) {
const { author } = require(eventPath).head_commit
const author = eventPath && require(eventPath)?.head_commit?.author
if (author) {
setDefault('author_name', author.name)
setDefault('author_email', author.email)
} else {
warning('No event path available, unable to fetch author info.')
warning(`Unable to fetch author info: couldn't find ${!eventPath ? 'event path' : !require(eventPath)?.head_commit ? 'commit' : 'commit author'}.`)
setDefault('author_name', 'Add & Commit Action')
setDefault('author_email', 'actions@github.com')
}
info(`Using '${getInput('author_name')} <${getInput('author_email')}>' as author.`)
}