5
0
Fork 0
mirror of https://github.com/pre-commit/action.git synced 2025-11-09 03:26:56 +00:00

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
This commit is contained in:
cdrx 2020-12-04 11:42:05 +00:00
parent d0b0a000b5
commit 101b6de688
2 changed files with 24 additions and 3 deletions

View file

@ -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'

View file

@ -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']);
});