Skip to content

Require outside pull requests to close an open issue - #6189

Merged
ymichael merged 3 commits into
mainfrom
bb/define-contribution-guidelines-thr_zc5q95yveb
Oct 23, 2026
Merged

ymichael merged 3 commits into
mainfrom
bb/define-contribution-guidelines-thr_zc5q95yveb

Conversation

@ymichael

@ymichael ymichael commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

About two thirds of recent fork pull requests (47 of 72 since Oct 19) referenced no issue, including feature and UI changes that CONTRIBUTING.md says need sign-off on an issue first. Nothing enforced this: the PR gate checked only contributor approval and "Allow edits by maintainers". Its close comment for authors who weren't approved was also hard to follow ("now closes on its own", "can reopen"). The needs-approval label it tried to add does not exist in the repo, so that gh pr edit failed silently every time.

What changed

  • .github/workflows/pr-gate.yml: on opened and reopened, PRs from authors who are not OWNER/MEMBER and not bots must close an open issue in this repo (GraphQL closingIssuesReferences). Failing PRs are closed and labelled needs-issue. synchronize skips the issue check, so maintainers can push to contributor branches without closing them. A new edited trigger reopens a closed needs-issue PR once an approved author links an issue (retrying the lookup a few times for link lag). The close comment now lists each requirement the PR misses (approval, linked issue, maintainer edits), with the next step for each. The gate creates the needs-approval/needs-issue labels on first use.
  • CONTRIBUTING.md: lists the three requirements up front, adds a Linked Issue section that explains why the issue is required, and tells bug fixers to file and link an issue first.
  • .github/PULL_REQUEST_TEMPLATE.md: marks Fixes # as required for outside contributors.
  • packages/scripts/test/pr-approval-workflows.test.ts: follows the renamed gate step and new comment text, and adds a case table for the issue check (unlinked/linked, members, owners, synchronize, and the edited reopen path).

Open PRs that already lack an issue are only affected if someone reopens them. A PR the workflow reopens with GITHUB_TOKEN does not start new CI runs, but its existing head checks remain.

How you verified

pnpm exec turbo run test lint typecheck --filter=@bb/scripts passes (257 tests). Extracted the step script from the workflow with js-yaml and ran it with a stubbed gh through 12 scenarios: new author with and without an issue, approved author with and without an issue, synchronize (no issue check), member, bot, edits off, edited on an open PR (no-op), and edited on a closed needs-issue PR when the issue is now linked (reopens), still missing (four lookups, no action), and when the author is not approved (no action). Checked that the labels, the close/reopen calls, and the comment text matched in each case. The edited event on closed PRs has not been exercised on GitHub yet.

AGENT GENERATED

🤖 Generated with Claude Code

@ymichael
ymichael force-pushed the bb/define-contribution-guidelines-thr_zc5q95yveb branch 2 times, most recently from bf9e4d0 to 9a94dbd Compare October 23, 2026 22:14
ymichael and others added 3 commits October 23, 2026 15:46
The PR gate now closes pull requests from authors outside the bb team
that do not close an open issue in this repo, and reopens them once the
author links one. Its close comment lists each unmet requirement with the
next step, and CONTRIBUTING.md documents the requirement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/define-contribution-guidelines-thr_zc5q95yveb branch from 40dd850 to f41085e Compare October 23, 2026 22:46
@ymichael
ymichael merged commit d1bfe7a into main Oct 23, 2026
48 of 49 checks passed
@ymichael
ymichael deleted the bb/define-contribution-guidelines-thr_zc5q95yveb branch October 23, 2026 22:53
ymichael added a commit that referenced this pull request Oct 23, 2026
…#6197)

## Human comments

## What was wrong

The linked-issue check from #6189 exempts authors whose
`author_association` is `OWNER` or `MEMBER`. For an org member with
private membership, `pull_request_target` reports `COLLABORATOR`. So
maintainer pull requests from branches in this repository were closed
with `needs-issue`. #6195 was closed this way: run 40039656279 logged
`PR_ASSOCIATION: COLLABORATOR` and `HEAD_REPO: get-bb/bb`. Details in
#6196.

## What changed

`.github/workflows/pr-gate.yml` now runs the linked-issue check only
when the head repository is not this repository.
- **Same-repo pull requests:** only accounts with write access can push
branches here, so these are exempt whatever the author's membership
visibility.
- **Fork pull requests:** handled exactly as before. Approval,
maintainer edits and the issue requirement are unchanged.
- **Closed `needs-issue` same-repo pull requests:** an edit now reopens
them, because the `edited` path uses the same check. That covers #6195.

`CONTRIBUTING.md` already describes the rule as "pull requests from
outside the bb team", so it needs no change.

## How you verified

- **Cause:** confirmed from the gate run log for #6195: `PR_ASSOCIATION:
COLLABORATOR` and `HEAD_REPO: get-bb/bb`.
- **Org membership:** `gh api orgs/get-bb/memberships/ymichael` reports
an active admin, and `public_members` returns 404.
- **Workflow file:** it still parses as YAML. The change is one extra
condition on the existing `issue_missing` guard.

Fixes #6196

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Oct 24, 2026
… check (#6200)

## Human comments

## What was wrong

Maintainers had no way to exempt a pull request from the PR gate's
linked-issue requirement (#6189). Reopening one by hand sends a
`reopened` event, the gate runs again, finds no linked issue, and closes
it again. #6198 is an example.

Separately, GitHub reports `maintainer_can_modify: false` on every
closed pull request. #6198 had `MAINTAINER_CAN_MODIFY: true` in its
`opened` run (40040917882) and reports `false` now, and every closed
fork PR in the repo shows `false`. When the gate re-checked a closed
`needs-issue` PR after an edit, it read that stale value as "maintainer
edits off" and wouldn't reopen it. So "this pull request reopens on its
own once you save the description" probably never worked for PRs from
personal forks.

## What changed

`.github/workflows/pr-gate.yml`:
- **`skip-issue-check` label:** when the label is present, the
linked-issue check is skipped. The gate now also runs on `labeled`
events. Adding this label to a closed `needs-issue` PR goes through the
same re-check as editing its description: the gate reopens the PR if the
author is approved and maintainer edits were on. Other labels are
ignored. Only accounts with triage access or higher can add labels, so
contributors can't exempt themselves.
- **`needs-maintainer-edits` label:** when the gate closes a PR because
"Allow edits by maintainers" is off, it now adds this label. The
re-check after an edit or label reads this label instead of the stale
`maintainer_can_modify`. On `opened` and `reopened`, the gate still
reads `maintainer_can_modify` as before. PRs closed for edits-off before
this change don't have the label, so a re-check could reopen one of
them.

`CONTRIBUTING.md`: documents the maintainer exemption under "Linked
Issue".

I created the `skip-issue-check` label in the repo.

## How you verified

I pulled the `run` script out of the workflow, checked it with `bash
-n`, and ran it against a stubbed `gh` in eight scenarios. Each produced
the expected `gh pr` calls:
- opened with no issue → closed with `needs-issue`
- `skip-issue-check` added to a closed PR (with the stale
`maintainer_can_modify=false`) → reopened
- some other label added → no action
- description edited with `Fixes #N` on a closed PR (stale `false`) →
reopened
- `skip-issue-check` added, but the PR has `needs-maintainer-edits` →
stays closed
- reopened by hand with `skip-issue-check` → stays open
- `skip-issue-check` added, but the author is not approved → stays
closed
- opened with edits off → closed with `needs-maintainer-edits`

None of this has run on real GitHub events yet. `pull_request_target`
takes effect only after merge, and #6198 is the first real case.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
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