Skip to content

Commit 70a75ac

Browse files
committed
feat(core): support fork PRs.
Fixes #627
1 parent 043b322 commit 70a75ac

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ const DEFAULT_CODECLIMATE_DEBUG = 'false';
2424
const DEFAULT_COVERAGE_LOCATIONS = '';
2525
const DEFAULT_VERIFY_DOWNLOAD = 'true';
2626

27+
const SUPPORTED_GITHUB_EVENTS = [
28+
// Regular PRs.
29+
'pull_request',
30+
// PRs that were triggered on remote forks.
31+
'pull_request_target',
32+
];
33+
2734
function prepareEnv() {
2835
const env = process.env as { [key: string]: string };
2936

@@ -35,7 +42,10 @@ function prepareEnv() {
3542
if (env.GIT_BRANCH)
3643
env.GIT_BRANCH = env.GIT_BRANCH.replace(/^refs\/heads\//, ''); // Remove 'refs/heads/' prefix (See https://github.com/paambaati/codeclimate-action/issues/42)
3744

38-
if (process.env.GITHUB_EVENT_NAME === 'pull_request') {
45+
if (
46+
process.env.GITHUB_EVENT_NAME &&
47+
SUPPORTED_GITHUB_EVENTS.includes(process.env.GITHUB_EVENT_NAME)
48+
) {
3949
env.GIT_BRANCH = process.env.GITHUB_HEAD_REF || env.GIT_BRANCH; // Report correct branch for PRs (See https://github.com/paambaati/codeclimate-action/issues/86)
4050
env.GIT_COMMIT_SHA = context.payload.pull_request?.['head']?.['sha']; // Report correct SHA for the head branch (See https://github.com/paambaati/codeclimate-action/issues/140)
4151
}

0 commit comments

Comments
 (0)