From 101b6de6881cf0ece7e5397a07c2153fe3c215d6 Mon Sep 17 00:00:00 2001 From: cdrx Date: Fri, 4 Dec 2020 11:42:05 +0000 Subject: [PATCH] feat: add options to configure the name/email of the account that commits back to the repo feat: add option to configure the commit message and the prefix added --- action.yml | 16 ++++++++++++++++ index.js | 11 ++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 9906815..e6dde9a 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,22 @@ inputs: token: description: github token to clone / push with required: false + committer_name: + description: name of the user that will push fixes back + required: false + default: 'pre-commit' + committer_email: + description: email address of the user that will push fixes back + required: false + default: 'pre-commit@example.com' + commit_prefix: + description: prefix added to message when fixes are made + required: false + default: '' + commit_message: + description: commit message when fixes are made + required: false + default: 'pre-commit fixes' runs: using: 'node12' main: 'dist/index.js' diff --git a/index.js b/index.js index 9adf9a1..670611d 100644 --- a/index.js +++ b/index.js @@ -53,6 +53,11 @@ async function main() { const cacheKey = `pre-commit-2-${hashString(py)}-${hashFile('.pre-commit-config.yaml')}`; const restored = await cache.restoreCache(cachePaths, cacheKey); const ret = await exec.exec('pre-commit', args, {ignoreReturnCode: push}); + const commitMessage = core.getInput('commit_message'); + const commitPrefix = core.getInput('commit_prefix'); + const committerEmail = core.getInput('committer_email'); + const committerName = core.getInput('committer_name'); + if (!restored) { await cache.saveCache(cachePaths, cacheKey); } @@ -68,15 +73,15 @@ async function main() { ); if (diff) { await core.group('push fixes', async () => { - await exec.exec('git', ['config', 'user.name', 'pre-commit']); + await exec.exec('git', ['config', 'user.name', committerName]); await exec.exec( - 'git', ['config', 'user.email', 'pre-commit@example.com'] + 'git', ['config', 'user.email', committerEmail] ); const branch = pr.head.ref; await exec.exec('git', ['checkout', 'HEAD', '-b', branch]); - await exec.exec('git', ['commit', '-am', 'pre-commit fixes']); + await exec.exec('git', ['commit', '-am', commitPrefix + commitMessage]); const url = addToken(pr.head.repo.clone_url, token); await exec.exec('git', ['push', url, 'HEAD']); });