ci: auto-close PRs opened from a fork's default branch#477
Merged
Conversation
When a contributor opens a PR from their fork's default branch (a branch with the same name as upstream's default), it permanently diverges their fork from upstream and makes the PR awkward to iterate on: - Their fork's default branch can no longer fast-forward from upstream without losing the PR state, so syncing the fork breaks. - Any additional commits pushed to that branch on the fork get tacked onto the open PR, so the contributor can't work on multiple changes at once. - Maintainer pushes to the PR end up landing on the contributor's default branch, which is bad form even when GitHub allows it. - Local collaboration is awkward: in a checkout, the default branch name becomes ambiguous between upstream and the fork. This workflow auto-closes such PRs with a friendly comment that explains the issue and walks the contributor through resyncing their fork's default branch and re-opening from a feature branch. Pattern adopted from esphome/esphome#15957. - Triggers on `pull_request_target` (opened, reopened) so the workflow has write permission for forks but does not check out PR code. - Fires only when the PR head is in a fork AND `head.ref == repository.default_branch` — internal branches and PRs from feature branches are untouched. - `actions/github-script` pinned to a SHA per security best practice for `pull_request_target` workflows.
Codecov Report✅ All modified and coverable lines are covered by tests. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a GitHub Actions workflow that auto-closes pull requests opened from a fork's default branch (the PR's head branch shares the upstream default-branch name) and posts a friendly comment explaining the problem and how to move the work to a feature branch.
We've seen this come up several times recently (see e.g. #456, #430). When a contributor PRs from their fork's `master`:
How it works
Pattern adopted from esphome/esphome#15957.
Test plan