ci(pr-policy): add the maintainer takeover label

Merged
OK
2d ago
+323-22

What

A maintainer who decides to finish a community PR themselves adds the maintainer takeover label. The bot then:

  • comments once, tagging the author and naming the maintainer who took over
  • assigns the PR to that maintainer
  • drops needs:compliance and its comment, and neither the 72 hour close nor the stale sweep touches the PR

Removing the label deletes the comment, and the policy check applies again.

The comment the author gets:

@contributor, thanks for the work so far. @maintainer is taking over this PR and will finish it.

- You do not need to do anything else. Review comments and failing checks are on the maintainer from here.
- Please do not push more commits, so the work does not collide. If you have something to add, comment here.
- You keep the credit for the change.
- The automated checks will not close this PR.

If you would rather finish it yourself, say so here.

Dependabot PRs get only the dependencies label.

Why

When a maintainer finishes a contributor's PR, nothing on the PR says so. The author keeps pushing or waits for a review, and the policy bot can still flag the PR and close it after 72 hours, or close it as stale.

The dependabot.yml change belongs to a label cleanup done by hand in the repo settings. Dependabot's defaults add javascript and github_actions, which nothing reads, and would bring them back after they were deleted.

How it works

  1. pr-policy.yml also runs on labeled and unlabeled (.github/workflows/pr-policy.yml:12) and gets a second step, takeover.ts (:38).
  2. outstanding() returns no problems for a PR carrying the label (scripts/pr-policy/rules.ts:169). check.ts:51 and the sweep's settleFlagged (sweep.ts:118) both call it on the live PR, so their existing "nothing to fix" path clears the flag. A PR labeled between the sweep's listing and its turn is caught the same way.
  3. isStale skips a labeled PR (rules.ts:262).
  4. takeover.ts skips closed PRs and PRs from maintainers or bots, then reads the live labels, the bot's announcement, and who last added the label from the timeline (labeledBy, scripts/pr-policy/github.ts:108).
  5. takeoverChange() (rules.ts:203) decides from that state: post the announcement, rewrite it when another maintainer took over, withdraw it when the label is gone, or do nothing.
  6. announceTakeover posts or edits the comment and assigns the maintainer (github.ts:127). withdrawTakeover deletes the comment and leaves the assignee, because nothing records why someone was assigned (github.ts:138).
  7. CONTRIBUTING.md:62 documents the label for contributors.

Decision: both steps read the PR as it is and ignore which event fired. The workflow's concurrency group drops a queued run when a newer event arrives, so a step keyed on the labeled event could lose the announcement for good. For the same reason the job has no filter on the label's name: a skipped run would still evict a queued one.

Issue

Verified

Ran it locally: yes

  • Both scripts with --dry-run against a live fork PR (#2102), with its REST payload as the event. This exercises the live reads, including the new timeline query:
#2102: nothing to fix
#2102: the takeover announcement matches the label
labeledBy takeover: undefined
labeledBy size: [ 'github-actions' ]
  • Not run: the announce and withdraw writes on a real PR. Labeling a real community PR pings its author, and the workflow runs from main, so it cannot run before merge. takeoverChange, announceTakeover, and withdrawTakeover are covered by scripts/pr-policy/*.test.ts.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.