fix: skip on forks

Close #153
This commit is contained in:
peaceiris 2020-03-14 20:45:50 +00:00
parent ff31e77830
commit c320668126
2 changed files with 31 additions and 1 deletions

View File

@ -4,13 +4,22 @@ import {Inputs} from './interfaces';
import {showInputs, getInputs} from './get-inputs';
import {setTokens} from './set-tokens';
import {setRepo, setCommitAuthor, commit, push, pushTag} from './git-utils';
import {getWorkDirName, addNoJekyll, addCNAME} from './utils';
import {getWorkDirName, addNoJekyll, addCNAME, skipOnFork} from './utils';
export async function run(): Promise<void> {
try {
const inps: Inputs = getInputs();
showInputs(inps);
const isSkipOnFork = await skipOnFork(
inps.GithubToken,
inps.DeployKey,
inps.PersonalToken
);
if (isSkipOnFork) {
return;
}
const remoteURL = await setTokens(inps);
core.debug(`[INFO] remoteURL: ${remoteURL}`);

View File

@ -1,3 +1,4 @@
import {context} from '@actions/github';
import * as core from '@actions/core';
import * as io from '@actions/io';
import path from 'path';
@ -62,3 +63,23 @@ export async function addCNAME(
fs.writeFileSync(filepath, content + '\n');
core.info(`[INFO] Created ${filepath}`);
}
export async function skipOnFork(
githubToken: string,
deployKey: string,
personalToken: string
): Promise<boolean> {
const isForkRepository =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(context.payload as any).repository.fork.toUpperCase() === 'TRUE';
if (!isForkRepository || githubToken) {
return false;
}
if (isForkRepository && (deployKey || personalToken)) {
return false;
}
return true;
}