Skip to content

Commit 7bd2b1c

Browse files
committed
Fix: allow action to work without head_commit
Ref: Issue #22
1 parent 61d14d1 commit 7bd2b1c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/main.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ try {
1111

1212
function checkInputs() {
1313
const eventPath = process.env.GITHUB_EVENT_PATH
14-
if (eventPath) {
15-
const { author } = require(eventPath).head_commit
14+
const author = eventPath && require(eventPath)?.head_commit?.author
15+
16+
if (author) {
1617
setDefault('author_name', author.name)
1718
setDefault('author_email', author.email)
1819
} else {
19-
warning('No event path available, unable to fetch author info.')
20+
warning(`Unable to fetch author info: couldn't find ${!eventPath ? 'event path' : !require(eventPath)?.head_commit ? 'commit' : 'commit author'}.`)
2021
setDefault('author_name', 'Add & Commit Action')
2122
setDefault('author_email', '[email protected]')
2223
}
24+
2325
info(`Using '${getInput('author_name')} <${getInput('author_email')}>' as author.`)
2426
}
2527

0 commit comments

Comments
 (0)