Skip to content

Add workflow to enforce main branch target for external contributor PRs#37635

Open
Copilot wants to merge 4 commits intomainfrom
copilot/add-github-action-close-prs
Open

Add workflow to enforce main branch target for external contributor PRs#37635
Copilot wants to merge 4 commits intomainfrom
copilot/add-github-action-close-prs

Conversation

Copy link
Contributor

Copilot AI commented Feb 5, 2026

External contributors occasionally target release/* or feature/* branches instead of main, requiring manual intervention to redirect them.

Changes

  • New workflow: .github/workflows/validate-pr-target-branch.yml
    • Triggers on PR open/reopen/edit (when base branch changes)
    • Checks author permissions via GitHub API
    • Auto-closes PRs from external contributors (no write access) targeting non-main branches
    • Posts explanatory comment with link to contribution guidelines

Implementation Details

  • Uses pull_request_target for secure execution in base repo context
  • Differentiates between internal (write/admin) and external (read/none) contributors
  • Skips runs when PR edited but base unchanged (performance optimization)
  • Dynamic repo context for portability
  • Graceful error handling (no action if permission check fails)

Behavior

Scenario Action
External contributor → main ✅ Allow
Internal contributor → any branch ✅ Allow
External contributor → release/9.0 ❌ Close + comment
Original prompt

Create a Github action that closes PRs that were submitted by an external contributer (no push permission) if they target any branch other than main.
It should also post a comment on the PR telling them to resubmit it with the correct target branch.
If not possible to automate in this way, suggest alternatives.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 5, 2026 17:06
…utors

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
…mic repo URLs

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Add GitHub action to close non-main PRs from external contributors Add workflow to enforce main branch target for external contributor PRs Feb 5, 2026
Copilot AI requested a review from AndriySvyryd February 5, 2026 17:11
@AndriySvyryd AndriySvyryd marked this pull request as ready for review February 5, 2026 17:14
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner February 5, 2026 17:14
Copilot AI review requested due to automatic review settings February 5, 2026 17:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds automation to enforce that external contributors target the main branch for their pull requests, addressing a recurring issue where external PRs mistakenly target release or feature branches.

Changes:

  • Adds a new GitHub Actions workflow that validates PR target branches based on contributor permissions
  • Automatically closes PRs from external contributors that target non-main branches
  • Posts an explanatory comment directing contributors to the contribution guidelines

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

2 participants