From f125bbc1167ff2c3f2cc7d34cdacdf708535e349 Mon Sep 17 00:00:00 2001 From: Christopher Little-Savage Date: Wed, 11 Nov 2026 17:54:22 +0000 Subject: [PATCH] [ci] Dismiss stale Codeowners Plus bot approval when reviews are no longer satisfied (#16822) Co-authored-by: Claude Opus 5.5 --- .github/workflows/codeowners.yml | 22 ++++++++++++++++++++++ CODEOWNERS.md | 8 +++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeowners.yml b/.github/workflows/codeowners.yml index 407d0d25b1..3d6d2c14c7 100644 --- a/.github/workflows/codeowners.yml +++ b/.github/workflows/codeowners.yml @@ -52,6 +52,7 @@ jobs: GITHUB_TOKEN: "${{ secrets.CODEOWNERS_GITHUB_PAT }}" - name: "Codeowners Plus" + id: codeowners if: ${{ !(github.event.pull_request.user.login == 'workers-devprod' && github.event.pull_request.head.repo.full_name == github.repository && startsWith(github.event.pull_request.head.ref, 'changeset-release/')) }} uses: multimediallc/codeowners-plus@ff02aa993a92e8efe01642916d0877beb9439e9f # v1.9.0 with: @@ -59,3 +60,24 @@ jobs: pr: "${{ github.event.pull_request.number }}" verbose: true quiet: ${{ github.event.pull_request.draft }} + + # Codeowners Plus only withdraws its own approval when smart dismissal is + # enabled, and codeowners.toml disables that so human approvals survive + # new pushes. Without this step, an approval the bot gave earlier (e.g. + # while the PR briefly had no diff) stays valid after changes that need + # codeowner review are pushed. + - name: "Dismiss Stale Bot Approval" + if: ${{ steps.codeowners.outcome == 'success' && !fromJSON(steps.codeowners.outputs.data).success }} + env: + GH_TOKEN: "${{ secrets.CODEOWNERS_GITHUB_PAT }}" + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + bot_login=$(gh api user --jq .login) + review_ids=$(gh api --paginate "repos/${REPO}/pulls/${PR_NUMBER}/reviews" \ + --jq ".[] | select(.state == \"APPROVED\" and .user.login == \"${bot_login}\") | .id") + for review_id in $review_ids; do + gh api --method PUT "repos/${REPO}/pulls/${PR_NUMBER}/reviews/${review_id}/dismissals" \ + -f message="Codeowners reviews no longer satisfied" -f event=DISMISS + echo "Dismissed approval ${review_id} from ${bot_login}" + done diff --git a/CODEOWNERS.md b/CODEOWNERS.md index 77a6c54724..16c6b95139 100644 --- a/CODEOWNERS.md +++ b/CODEOWNERS.md @@ -48,7 +48,7 @@ PR opened/updated/reviewed | Multiple teams on a path | **OR** — any one team can approve | **AND** via `&` prefix — all listed teams must approve | | Path matching for `*.js` | Matches anywhere in repo | Matches only in the `.codeowners` file's directory; use `**/*.js` for recursive | | Per-directory config | Single file only | `.codeowners` file in any directory (rules are relative to that directory) | -| Stale review dismissal | All-or-nothing | Smart — only dismisses when reviewer's owned files change | +| Stale review dismissal | All-or-nothing | Smart — only dismisses when reviewer's owned files change (disabled here) | | Optional reviewers | Not supported | `?` prefix — CC without blocking | ## Configuration Files @@ -162,9 +162,11 @@ R2, Queues, AI, Hyperdrive, Vectorize, Pipelines, SSL/Secrets Store, WVPC. ## Stale Review Handling -Codeowners Plus uses **smart dismissal**: when new commits are pushed to a PR, it only dismisses an approval if the files owned by that reviewer were changed. This avoids the frustration of GitHub's all-or-nothing stale review dismissal. +Codeowners Plus supports **smart dismissal** (only dismissing an approval when files owned by that reviewer change), but this repo disables it with `disable_smart_dismissal = true` in `codeowners.toml`. Human approvals are therefore never dismissed when new commits are pushed. -For this to work, the branch protection setting **"Dismiss stale pull request approvals when new commits are pushed"** must be **disabled**. Codeowners Plus handles dismissal itself. +The branch protection setting **"Dismiss stale pull request approvals when new commits are pushed"** must also stay **disabled**, otherwise GitHub would dismiss every approval on each push. + +With smart dismissal disabled, Codeowners Plus also never withdraws its own approval. To stop an earlier bot approval (for example, one given while the PR briefly had no diff) from letting a PR merge after changes that need codeowner review are pushed, the **"Dismiss Stale Bot Approval"** step in `.github/workflows/codeowners.yml` runs after every check. If Codeowners Plus reports that reviews are no longer satisfied, the step dismisses any approvals from the `@workers-devprod` account with the message "Codeowners reviews no longer satisfied". The bot approves again once the required codeowner reviews are in. ## Troubleshooting