Repository navigation
feat: implement issue #465 — Restrict auto-rebase fan-out to review-ready PRs (free, plan-independent mitigation) #468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ca0bf55
feat: implement issue #465 — Restrict auto-rebase fan-out to review-r…
donpetry-bot 89592a4
fix(reviews): address review comments [skip ci-relay]
donpetry-bot d103112
fix(bot): address bot feedback [skip ci-relay]
donpetry-bot 707afbc
Merge branch 'main' into dev-lead/issue-465-20260615-1642
don-petry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # auto-rebase scripts | ||
|
|
||
| Supporting logic for the org-level **auto-rebase** reusable workflow | ||
| (`.github/workflows/auto-rebase-reusable.yml`). All bash/jq decision logic | ||
| lives here so it can be unit-tested with bats | ||
| (`test/workflows/auto-rebase/`) instead of being trapped inline in YAML. | ||
|
|
||
| The reusable workflow checks this repo out at `inputs.tooling_ref` (default | ||
| `v1`) and sources `lib/eligibility.sh` to decide which behind PRs to update. | ||
|
|
||
| ## `lib/eligibility.sh` | ||
|
|
||
| Pure, side-effect-free predicates. Source the file, then call: | ||
|
|
||
| | Function | Input | Returns | | ||
| |----------|-------|---------| | ||
| | `auto_rebase_has_current_approval` | PR reviews JSON array on stdin (`GET /repos/{repo}/pulls/{n}/reviews`, oldest-first) | `0` if the PR has a current APPROVED review, else `1` | | ||
| | `auto_rebase_has_ready_label LABEL` | PR labels JSON array on stdin | `0` if a label named `LABEL` is present, else `1` | | ||
| | `auto_rebase_pr_eligible MODE IS_DRAFT IS_APPROVED HAS_LABEL` | mode + three `true`/`false` strings | `0` eligible, `1` not eligible, `2` unknown mode | | ||
|
|
||
| ### Approval semantics | ||
|
|
||
| `auto_rebase_has_current_approval` inspects the **actual review states**, not | ||
| `reviewDecision` (which is `null` on repos without required reviews). The most | ||
| recent *decision* review per reviewer wins — a later `CHANGES_REQUESTED` or | ||
| `DISMISSED` cancels an earlier `APPROVED`, while `COMMENTED`/`PENDING` reviews | ||
| do not change a reviewer's stance. | ||
|
|
||
| ### Eligibility modes (the tunable `eligibility` workflow input) | ||
|
|
||
| | Mode | Meaning | | ||
| |------|---------| | ||
| | `review-ready` (default) | non-draft **AND** (current approval **OR** carries the ready label) | | ||
| | `all` | every behind PR, including drafts — restores the original unrestricted fan-out | | ||
|
|
||
| New modes (e.g. a future "front-of-queue N") can be added here and selected by | ||
| callers via the `eligibility` input with no change to the workflow file. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #!/usr/bin/env bash | ||
| # Eligibility predicates for the auto-rebase reusable workflow. | ||
| # | ||
| # These are pure, side-effect-free functions so they can be unit-tested with | ||
| # bats (see test/workflows/auto-rebase/eligibility.bats). The reusable | ||
| # workflow sources this file and uses the predicate to decide which behind | ||
| # PRs to update-branch, instead of fanning out to every behind PR. | ||
| # | ||
| # Contract: see .github/scripts/auto-rebase/README.md | ||
|
|
||
| # auto_rebase_has_current_approval | ||
| # Reads a GitHub pull-request reviews JSON array on stdin (the response of | ||
| # `GET /repos/{repo}/pulls/{n}/reviews`, oldest-first) and returns 0 if the | ||
| # PR currently has at least one APPROVED review, else 1. | ||
| # | ||
| # "Current" means the reviewer's most recent decision review wins: a later | ||
| # CHANGES_REQUESTED or DISMISSED cancels an earlier APPROVED, while | ||
| # COMMENTED/PENDING reviews do not change a reviewer's stance. We check the | ||
| # real review states here rather than reviewDecision, which is null on repos | ||
| # without required reviews (issue #465 implementer note). | ||
| auto_rebase_has_current_approval() { | ||
| local result | ||
| result=$(jq -r ' | ||
| reduce (.[] | select(.state == "APPROVED" or .state == "CHANGES_REQUESTED" or .state == "DISMISSED")) as $r ({}; .[$r.user.login] = $r.state) | ||
| | any(. == "APPROVED") | ||
| ') | ||
| [[ "$result" == "true" ]] | ||
| } | ||
|
|
||
| # auto_rebase_has_ready_label LABEL | ||
| # Reads a PR labels JSON array on stdin (objects with a .name field) and | ||
| # returns 0 if a label named LABEL is present, else 1. | ||
| auto_rebase_has_ready_label() { | ||
| local label="$1" present | ||
| present=$(jq -r --arg L "$label" 'any(.[]; .name == $L)') | ||
| [[ "$present" == "true" ]] | ||
| } | ||
|
|
||
| # auto_rebase_pr_eligible MODE IS_DRAFT IS_APPROVED HAS_LABEL | ||
| # Decides whether a behind PR should be updated, given its draft/approval/ | ||
| # label state. IS_DRAFT, IS_APPROVED and HAS_LABEL are the strings "true" | ||
| # or "false". Returns 0 (eligible), 1 (not eligible), or 2 (unknown mode). | ||
| # | ||
| # Modes (the tunable `eligibility` workflow input): | ||
| # review-ready non-draft AND (approved OR carries the ready label). | ||
| # The default — restricts fan-out to review-ready PRs. | ||
| # all every behind PR, including drafts. Escape hatch that | ||
| # restores the original unrestricted fan-out behavior. | ||
| auto_rebase_pr_eligible() { | ||
| local mode="$1" is_draft="$2" is_approved="$3" has_label="$4" | ||
| case "$mode" in | ||
| all) | ||
| return 0 | ||
| ;; | ||
| review-ready) | ||
| [[ "$is_draft" == "true" ]] && return 1 | ||
| if [[ "$is_approved" == "true" || "$has_label" == "true" ]]; then | ||
| return 0 | ||
| fi | ||
| return 1 | ||
| ;; | ||
| *) | ||
| echo "auto_rebase_pr_eligible: unknown eligibility mode '$mode'" >&2 | ||
| return 2 | ||
| ;; | ||
| esac | ||
| } | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Quality gates for the reusable auto-rebase workflow and its supporting | ||
| # eligibility scripts. | ||
| # | ||
| # Triggered on any PR that touches: | ||
| # - .github/workflows/auto-rebase*.yml | ||
| # - .github/scripts/auto-rebase/** | ||
| # - test/workflows/auto-rebase/** | ||
| # - standards/workflows/auto-rebase.yml | ||
| # | ||
| # Gates (all must pass before merge): | ||
| # 1. shellcheck — static analysis for the eligibility lib | ||
| # 2. bats — unit tests for the eligibility predicate | ||
| # | ||
| # Standard: this workflow enforces the contract documented in | ||
| # .github/scripts/auto-rebase/README.md. | ||
|
|
||
| name: Auto-rebase Tests | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - '.github/workflows/auto-rebase*.yml' | ||
| - '.github/scripts/auto-rebase/**' | ||
| - 'test/workflows/auto-rebase/**' | ||
| - 'standards/workflows/auto-rebase.yml' | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - '.github/workflows/auto-rebase*.yml' | ||
| - '.github/scripts/auto-rebase/**' | ||
| - 'test/workflows/auto-rebase/**' | ||
| - 'standards/workflows/auto-rebase.yml' | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: auto-rebase-tests-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| jobs: | ||
| test: | ||
| name: Lint and bats | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | ||
| with: | ||
| fetch-depth: 1 | ||
|
|
||
| - name: Install bats, shellcheck, and jq | ||
| run: | | ||
| set -euo pipefail | ||
| sudo apt-get update -qq | ||
| sudo apt-get install -y --no-install-recommends bats shellcheck jq | ||
|
|
||
| - name: shellcheck | ||
| run: | | ||
| set -euo pipefail | ||
| shellcheck -x .github/scripts/auto-rebase/lib/eligibility.sh | ||
|
|
||
| - name: Run bats suite | ||
| run: bats --print-output-on-failure test/workflows/auto-rebase/ | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.