Skip to content

Github Actions isFork False Positive #80

@tynes

Description

@tynes

I am observing an error running codechecks in Github Actions - Provider should never be in fork mode and not in PR mode!
It appears as if there is a false positive as the PR is not coming from a fork. The code is here:

const isFork = await ciProvider.isFork();
const pr = await ciProvider.getPullRequestID();
const projectSlug = await ciProvider.getProjectSlug();
if (!pr && isFork) {
throw new Error("Provider should never be in fork mode and not in PR mode!");
}

For Github actions, !pr is always true

getPullRequestID(): number | undefined {
return undefined;
}

And isFork is always true because GITHUB_HEAD_REF is set for PRs submitted from the same repo. See the docs here: https://docs.github.com/en/actions/reference/environment-variables

isFork(): boolean {
// This is only set for forked repositories
// @see https://help.github.com/en/articles/virtual-environments-for-github-actions#default-environment-variables
return !!this.env["GITHUB_HEAD_REF"];
}

GITHUB_HEAD_REF	Only set for pull request events. The name of the head branch.

Perhaps there is a better way to determine there the PR is coming from a fork, will update if I determine a good solution

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions