Skip to content

Conversation

pranav-new-relic
Copy link
Member

@pranav-new-relic pranav-new-relic commented Jul 4, 2025

(not urgent, drafting this PR for consideration sometime)

This PR adds a workflow to validate PRs from forks by authors with repository write access, and block them via the workflow, compelling them to shift to contributing via the actual repository by means of an automated comment.

TL;DR see "2" in Testing to see what I mean :)

Problem Statement

Currently, this repository receives pull requests from both internal collaborators and external contributors. Some internal collaborators who have write access to the repository occasionally create PRs from forks instead of using branches in the main repository. This is not intended, and creates the following problems:

  1. Limited CI/CD Pipeline Execution: When PRs come from forks, most integration tests and workflows don't run automatically due to security constraints and cost considerations, which is why we need such authors to contribute from the original repository and not the fork.
  2. Inefficient Review Process: Without complete test coverage, maintainers can't fully validate changes, leading to delayed merges or additional manual testing; which also explains why we need to tell them to not use the fork, and use the original repo instead.

Solution

This PR introduces a new GitHub Action workflow that automatically identifies when a PR from a fork is created by a user who already has write access to the repository. The workflow then:

  1. Detects if the PR author has write access (either directly or through team membership)
  2. Posts a helpful comment explaining the preferred contribution workflow
  3. Fails the check with a clear explanation

How the Workflow Functions

The fork-pr-author-validation.yml workflow:

  1. Triggers: Runs on pull_request_target events (opened, reopened, synchronize) specifically for PRs from forks
  2. Permission Check: Uses GitHub API to determine if the author has write access:
    • First checks direct collaborator permissions
    • Then checks team membership and associated repository permissions
  3. Notification: If write access is detected, posts a friendly comment explaining:
    • Why creating PRs from forks is problematic for internal contributors
    • The preferred workflow (creating branches directly in the main repository)
    • How this impacts testing and the review process

Testing

These changes have been tested on a different repository https://github.com/newrelic/test-oac-repository, to allow for flexible testing (without having to use this repository). While additional workflows also run on PRs in this repository allowing for extra automation, please ignore those comments - all details of changes tested are as follows.

1. When a PR is created on the original repo (not fork)

image

2. When a PR is created from a fork of the repo, and the author already has write access to the repo

image image

3. When a PR is created from a fork of the repo, and the author does not have write access to the repo

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant