diff --git a/action.yml b/action.yml index 9421be0..41ab27d 100644 --- a/action.yml +++ b/action.yml @@ -5,11 +5,9 @@ inputs: author_name: description: The name of the user that will be displayed as the author of the commit required: false - default: Add & Commit GitHub Action author_email: description: The email of the user that will be displayed as the author of the commit required: false - default: actions@github.com force: description: Whether to use the force option on git add, in order to bypass eventual gitignores required: false diff --git a/src/entrypoint.sh b/src/entrypoint.sh index edb0e65..8e2946a 100755 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -14,8 +14,8 @@ git_setup() { EOF chmod 600 $HOME/.netrc - git config --global user.email "actions@github.com" - git config --global user.name "Add & Commit GitHub Action" + git config --global user.email "$INPUT_AUTHOR_EMAIL" + git config --global user.name "$INPUT_AUTHOR_NAME" } add() { diff --git a/src/main.ts b/src/main.ts index d264553..7b82545 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,7 +3,22 @@ import * as shell from 'shelljs' import * as path from 'path' try { + checkInputs() shell.exec(path.join(__dirname, '../src/entrypoint.sh')) } catch (e) { core.setFailed(e) } + +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 + } 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' + } + core.info(`Using '${process.env.INPUT_AUTHOR_NAME} <${process.env.INPUT_AUTHOR_EMAIL}>' as author.`) +}