mirror of
https://github.com/pre-commit/action.git
synced 2025-11-09 03:26:56 +00:00
Add source and origin inputs
This commit is contained in:
parent
a10ca4ef27
commit
274174e015
2 changed files with 27 additions and 6 deletions
|
|
@ -4,6 +4,12 @@ inputs:
|
||||||
token:
|
token:
|
||||||
description: github token to clone / push with
|
description: github token to clone / push with
|
||||||
required: false
|
required: false
|
||||||
|
source:
|
||||||
|
description: The remote branch's commit_id when using `git push`.
|
||||||
|
required: false
|
||||||
|
origin:
|
||||||
|
description: The origin branch's commit_id when using `git push`.
|
||||||
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
|
|
||||||
27
index.js
27
index.js
|
|
@ -2,10 +2,6 @@ const core = require('@actions/core');
|
||||||
const exec = require('@actions/exec');
|
const exec = require('@actions/exec');
|
||||||
const github = require('@actions/github');
|
const github = require('@actions/github');
|
||||||
|
|
||||||
const ARGS = [
|
|
||||||
'run', '--all-files', '--show-diff-on-failure', '--color=always'
|
|
||||||
];
|
|
||||||
|
|
||||||
function addToken(url, token) {
|
function addToken(url, token) {
|
||||||
return url.replace(/^https:\/\//, `https://x-access-token:${token}@`)
|
return url.replace(/^https:\/\//, `https://x-access-token:${token}@`)
|
||||||
}
|
}
|
||||||
|
|
@ -17,14 +13,33 @@ async function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
const token = core.getInput('token');
|
const token = core.getInput('token');
|
||||||
|
const source = core.getInput('source');
|
||||||
|
const origin = core.getInput('origin');
|
||||||
|
|
||||||
|
var args = [
|
||||||
|
'run', '--show-diff-on-failure', '--color=always'
|
||||||
|
];
|
||||||
|
|
||||||
|
if (source) {
|
||||||
|
args.push('--source', source);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (origin) {
|
||||||
|
args.push('--origin', origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!!source && !!origin) {
|
||||||
|
args.push('--all-files');
|
||||||
|
}
|
||||||
|
|
||||||
const pr = github.context.payload.pull_request;
|
const pr = github.context.payload.pull_request;
|
||||||
const push = !!token && !!pr;
|
const push = !!token && !!pr;
|
||||||
const ret = await exec.exec('pre-commit', ARGS, {ignoreReturnCode: push});
|
const ret = await exec.exec('pre-commit', args, {ignoreReturnCode: push});
|
||||||
if (ret && push) {
|
if (ret && push) {
|
||||||
// actions do not run on pushes made by actions.
|
// actions do not run on pushes made by actions.
|
||||||
// need to make absolute sure things are good before pushing
|
// need to make absolute sure things are good before pushing
|
||||||
// TODO: is there a better way around this limitation?
|
// TODO: is there a better way around this limitation?
|
||||||
await exec.exec('pre-commit', ARGS);
|
await exec.exec('pre-commit', args);
|
||||||
|
|
||||||
const diff = await exec.exec(
|
const diff = await exec.exec(
|
||||||
'git', ['diff', '--quiet'], {ignoreReturnCode: true}
|
'git', ['diff', '--quiet'], {ignoreReturnCode: true}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue