Skip to content

Commit

Permalink
fix: skip on forks
Browse files Browse the repository at this point in the history
Close #153
  • Loading branch information
peaceiris committed Mar 14, 2020
1 parent ff31e77 commit c320668
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand Down
21 changes: 21 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}

0 comments on commit c320668

Please sign in to comment.