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:
parent
d0b0a000b5
commit
101b6de688
2 changed files with 24 additions and 3 deletions
16
action.yml
16
action.yml
|
|
@ -8,6 +8,22 @@ inputs:
|
||||||
token:
|
token:
|
||||||
description: github token to clone / push with
|
description: github token to clone / push with
|
||||||
required: false
|
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:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
|
|
||||||
11
index.js
11
index.js
|
|
@ -53,6 +53,11 @@ async function main() {
|
||||||
const cacheKey = `pre-commit-2-${hashString(py)}-${hashFile('.pre-commit-config.yaml')}`;
|
const cacheKey = `pre-commit-2-${hashString(py)}-${hashFile('.pre-commit-config.yaml')}`;
|
||||||
const restored = await cache.restoreCache(cachePaths, cacheKey);
|
const restored = await cache.restoreCache(cachePaths, cacheKey);
|
||||||
const ret = await exec.exec('pre-commit', args, {ignoreReturnCode: push});
|
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) {
|
if (!restored) {
|
||||||
await cache.saveCache(cachePaths, cacheKey);
|
await cache.saveCache(cachePaths, cacheKey);
|
||||||
}
|
}
|
||||||
|
|
@ -68,15 +73,15 @@ async function main() {
|
||||||
);
|
);
|
||||||
if (diff) {
|
if (diff) {
|
||||||
await core.group('push fixes', async () => {
|
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(
|
await exec.exec(
|
||||||
'git', ['config', 'user.email', 'pre-commit@example.com']
|
'git', ['config', 'user.email', committerEmail]
|
||||||
);
|
);
|
||||||
|
|
||||||
const branch = pr.head.ref;
|
const branch = pr.head.ref;
|
||||||
await exec.exec('git', ['checkout', 'HEAD', '-b', branch]);
|
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);
|
const url = addToken(pr.head.repo.clone_url, token);
|
||||||
await exec.exec('git', ['push', url, 'HEAD']);
|
await exec.exec('git', ['push', url, 'HEAD']);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue