GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(reconcile): prune merged branches as a second, separately switched job by rishitank · Pull Request #17 · TanksterAI/.github

Conversation

@rishitank

@rishitank rishitank commented Oct 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Why

settings.yml has declared maintenance.prune_merged_branches: false since 2 Sept, but repo-settings-reconcile.yml never reads it. Branches from PRs merged before delete_branch_on_merge landed are still sitting across the org.

This PR gives that switch a job that is safe to turn on. settings.yml stays at false here.

There was also an older branch-prune.yml that read the same switch. Flipping the switch to true would have armed two deleters, and the old one skips most of the rules below:

  • it deletes any branch with a merged PR, even if commits were pushed after the merge;
  • it ignores rulesets;
  • it stops at 200 PRs;
  • it never re-reads the tip before deleting.

It is removed here, in a separate commit, and replaced by the new job.

What changed

  • scripts/prune-merged-branches.sh (new).
    • The same file is also committed to rishitank/.github: blob 9360696e in both.
    • Its dependencies are gh and jq, and it fails loudly if either is missing.
  • .github/workflows/repo-settings-reconcile.yml:
    • New workflow_dispatch input prune, with choices dry-run (the default) or apply.
    • New job prune:
      • it does not need reconcile;
      • it has permissions: contents: read, used for checkout only;
      • it runs with GH_TOKEN set to ORG_ADMIN_TOKEN, on CI_RUNNER;
      • checkout is SHA-pinned with persist-credentials: false;
      • a concurrency group queues runs and never cancels them;
      • it uploads a branch-prune-report artifact.
  • .github/workflows/branch-prune.yml: deleted (superseded, see above).

Safety rules

A branch is deleted only if every rule below holds. Otherwise it is report-only.

  1. Repository R is not archived and is not a fork.
  2. Branch B is not R's default branch.
  3. B is not protected.
  4. No ruleset applies a deletion rule to B:
    • a 404, or a plan 403 on a Free private repo, counts as "no rules";
    • any other failure counts as "unknown", and the branch is kept.
  5. B does not match ^(main|master|develop|staging|test|gh-pages|v[0-9][0-9.]*|deploy-.*|release/.*)$.
  6. No OPEN PR uses B as its head or its base.
  7. At least one MERGED PR has head ref B and head repo R.
  8. B's tip equals that PR's head SHA, so nothing was pushed after the merge.
  9. The tip is re-read through the URL-encoded ref path immediately before acting, in dry-run too.

How apply mode deletes:

  • It calls DELETE repos/R/git/refs/heads/<urlencoded B>.
  • A 422 or 404 response means the branch was already gone.
  • Every outcome is read back, and a ref that still exists counts as a failure.

Report-only categories: keep/protected, open, no-pr, closed-unmerged, merged-but-moved. All listing is paginated.

When it deletes

Trigger Mode
Schedule (nightly) or a push to settings.yml apply only if maintenance.prune_merged_branches is literally true; otherwise dry-run
workflow_dispatch Follows the prune input; the default is dry-run

Dry run on this branch

Run 37881291312 succeeded with prune: dry-run and nothing was deleted.

  • It scanned 36 repositories, with 0 unreadable and no rules-unknown warnings.
  • All 19 candidates passed the live re-read through the encoded ref path.

19 deletable branches:

  • .github: add-lighthouse-ci, agent-pipeline/auto-merge, agent-pipeline/subscription-auth, tmp-move-tag
  • agent-os: curriculum/skill-acquisition-loop, sentinel/escalation-ladder-drift
  • drillwright: sync/part-1 … sync/part-9
  • evidence-reply: any-topic-robustness, latest-stable-versions
  • connector-readiness: docs/sample-report, feat/readiness-scanner

153 report-only branches:

Category Count
open 98
keep/protected 39
closed-unmerged 12
no-pr 3
merged-but-moved 1 (.github:ops/settings-as-yaml-and-dependabot)

This matches the 9 Oct branch inventory exactly: the inventory's MERGED-SAFE set, minus trading-agent-guard:v0.1, which the keep pattern catches.

How to run

  • Dry run:
    1. Go to Actions → repo-settings-reconcile → Run workflow, and choose prune: dry-run.
    2. Read the step summary, or download branch-prune-report. It lists each deletable branch, and each report-only branch with its reason and last commit date.
  • Apply: either set maintenance.prune_merged_branches: true in settings.yml and merge it (the push runs the job), or dispatch with prune: apply.
  • Token: ORG_ADMIN_TOKEN must also hold Contents: read & write and Pull requests: read on the org repos. Deleting refs needs Contents write. The dry run only proves read access.

Notes

  • This touches the tail of repo-settings-reconcile.yml, which feat: org rulesets (review-gate, ci-gate, auto-merge, long-lived-branches) reconciled from settings.yml, with no per-repo data #8 also rewrites. Expect a trivial conflict at the end of the file, whichever PR lands second.
  • The existing reconcile job's checkout is left as it is (pinned to a tag), to keep this diff focused and away from feat: org rulesets (review-gate, ci-gate, auto-merge, long-lived-branches) reconciled from settings.yml, with no per-repo data #8 and fix(workflows): harden rust-ci, security, workflows-lint and auto-merge-gate #16.
  • Lint: actionlint is clean over the workflows dir, and shellcheck is clean on the script.
  • The script was exercised against a stubbed gh, covering:
    • every category;
    • the 403 and 404 rule handling;
    • a tip that moves during the run;
    • 422 and 500 responses on delete;
    • an unreadable repository.

🤖 Generated with Claude Code

https://claude.ai/code/session_012rYJxu978iUSGFZ1UuqTsi

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
rishitank and others added 2 commits October 9, 2026 04:52
@rishitank @claude
feat(reconcile): prune merged branches as a second, separately switch…
0f3b95b
…ed job

settings.yml has declared maintenance.prune_merged_branches since 2 Sept,
but repo-settings-reconcile.yml never read it. Adds
scripts/prune-merged-branches.sh (merged-at-tip only, ruleset and
open-PR aware, re-reads the tip before acting, reports everything else)
and a `prune` job that applies only when settings.yml says true on
schedule/push, or when a hand-run picks prune=apply. Default: dry run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012rYJxu978iUSGFZ1UuqTsi
@rishitank @claude
ci: retire branch-prune.yml, superseded by the reconcile prune job
d115e06
branch-prune.yml read the same maintenance.prune_merged_branches switch, so
flipping it to true would have armed two deleters, and this one skips the
safety rules the new job enforces: it deletes any branch with a merged PR
even if commits were pushed after the merge, ignores rulesets, stops at 200
PRs, and does not re-read the tip before deleting.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012rYJxu978iUSGFZ1UuqTsi
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Review in Change Stack →

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Free
  • Run ID: ee89d05d-c6ee-4b2b-a5a6-1e3d1f94d36f

📥 Commits

Reviewing files that changed from the base of the PR and between c2c57a4 and d115e06.


📒 Files selected for processing (3)
  • .github/workflows/branch-prune.yml
  • .github/workflows/repo-settings-reconcile.yml
  • scripts/prune-merged-branches.sh

💤 Files with no reviewable changes (1)
  • .github/workflows/branch-prune.yml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.



📝 Summary

Summary by CodeRabbit

  • New Features

    • Merged-branch cleanup is now managed alongside repository settings and can be run manually in dry-run or apply mode.
    • Scheduled and policy-triggered runs apply cleanup only when the setting is enabled; otherwise, they run as dry runs.
    • Cleanup reports summarize results, including branches considered, skipped items, and any failures.
  • Bug Fixes

    • Branches are checked against current repository and pull request state before deletion, helping prevent removal when eligibility cannot be confirmed.

Walkthrough

The separate branch-pruning workflow was removed. A pruning script and job were added to the repository-settings reconciliation workflow. The job selects dry-run or apply mode from the manual input or policy. The script classifies branches, checks deletion conditions, and writes reports.

Changes

Merged Branch Pruning

Layer / File(s) Summary
Branch classification and pruning
scripts/prune-merged-branches.sh
The script filters repositories and branches, checks deletion rules and current refs, and supports dry-run or apply mode. It writes JSON and Markdown reports and returns failure statuses for incomplete sweeps or failed deletions.
Reconciliation workflow integration
.github/workflows/repo-settings-reconcile.yml, .github/workflows/branch-prune.yml
The reconciliation workflow adds a prune input and job. Manual runs use the selected mode; scheduled and push runs apply only when the policy value is true. The job uploads its report even after failure. The separate branch-pruning workflow was removed.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ReconcileWorkflow as repo-settings-reconcile.yml
  participant PruneScript as prune-merged-branches.sh
  participant GitHubAPI
  participant ReportUpload as Report upload
  ReconcileWorkflow->>PruneScript: Pass organisation and selected mode
  PruneScript->>GitHubAPI: Inspect branches and apply deletions when selected
  PruneScript-->>ReconcileWorkflow: Return status and write report
  ReconcileWorkflow->>ReportUpload: Upload report after the job
Loading

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Essentials by visiting https://app.coderabbit.ai/settings/billing.


Apprentice, the branches face review
The merged are weighed against the rules
A dry-run marks the paths to take
Apply removes refs, then checks the state
Reports record each sweep’s result
The pruning script completes its task

Comment @coderabbitai help to get the list of available commands.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Oct 9, 2026
feat(ci): nightly merged-branch prune across the account, dry run by default rishitank/.github#8
Merged
ops(rulesets): manage review-gate approvals from settings.yml, set to 0 #18
Merged
rishitank added 2 commits October 9, 2026 15:53
@rishitank
Merge branch 'main' into feat/prune-merged-branches
4eb53e0
@rishitank
Merge branch 'main' into feat/prune-merged-branches
c317712
rishitank
rishitank commented Oct 9, 2026
View reviewed changes

@rishitank rishitank left a comment

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review by Claude (head c317712, after the branch update onto 340ebb9). I read all 3 changed files in full.

scripts/prune-merged-branches.sh (blob 9360696e, the same blob that ran in apply mode in run 37945894623)

  • Arguments:
    • --mode accepts only dry-run or apply; anything else exits 2;
    • a missing value is caught by shift 2 || fail_usage;
    • gh, jq and credentials are checked up front.
  • An empty repository list fails rather than reporting a clean sweep. Branches, PRs (state=all) and repositories are all listed with --paginate.
  • Classification, in one jq pass:
    • order: default branch, then keep pattern, then protected, then open PR as head or base, then no PR, then closed-unmerged, then merged-but-moved, then candidate;
    • a candidate needs a merged PR with head_repo == R and head_sha == tip;
    • the open-PR test ignores head_repo, so it is conservative: it keeps more, never less.
  • Live checks on candidates:
    • the rules endpoint: 404 and the Free-plan 403 text count as "none"; any other failure counts as "unknown" and the branch is kept;
    • the tip is re-read through the @uri-encoded ref; gone or error means keep, and a moved tip means merged-but-moved.
  • The DELETE call:
    • 422 and 404 mean already gone;
    • every outcome is confirmed by reading the ref back;
    • a ref that is still present counts as failed and gives exit 1.
  • Loops read from fd 3 and fd 4, so gh cannot consume the list. The report and summary use cell escaping for the | and newline characters.

repo-settings-reconcile.yml

  • The prune choice input defaults to dry-run.
  • The new job:
    • does not need reconcile;
    • has contents: read only;
    • uses ORG_ADMIN_TOKEN, failing loudly if it is empty;
    • runs on CI_RUNNER;
    • pins checkout by SHA (3d3c42e = v7.0.1) with persist-credentials: false;
    • pins upload-artifact by SHA (043fb46, which I verified against tag v7.0.1);
    • uses a queued, non-cancelling concurrency group.
  • Schedule and push apply only when the setting is a literal true. settings.yml stays false here, so after merge the nightly and push runs are dry runs.

branch-prune.yml removal: correct. Leaving it would arm a second, weaker deleter on the same switch.

Evidence from the real apply run 37945894623: 36 repos scanned, 0 unreadable, 19 deletable, 19 deleted, 0 already gone, 0 failed.

Nit (body only, no code change): the Notes section says "#8 also rewrites" the reconcile tail. The conflicting PR is #18, which I am rebasing onto this next.

Result: no defects found and no fixes needed. CI and CodeRabbit are green.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@rishitank
rishitank merged commit 7fc3700 into main Oct 9, 2026
5 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@rishitank
rishitank deleted the feat/prune-merged-branches branch October 9, 2026 15:03
rishitank added a commit that referenced this pull request Oct 9, 2026
@rishitank @claude
chore(reconcile): take main's repo-settings-reconcile.yml before merg…
e89091f
…ing main

#17 and this branch both add a dispatch input and a job to this file, so the
merge of main conflicts. This commit makes the file identical to main
(7fc3700); the next one re-adds the rulesets input, job and header on top,
so the merge is clean and the rulesets change is reviewed against main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012rYJxu978iUSGFZ1UuqTsi
rishitank added a commit that referenced this pull request Oct 9, 2026
@rishitank @claude
ops(rulesets): re-add the rulesets job on top of #17; make the test's…
9f8cddf
… fake gh executable

repo-settings-reconcile.yml is main's version (with #17's `prune` input and
job) plus this PR's `rulesets` dispatch input, `rulesets` job and header
paragraph, which is now the THIRD JOB since prune is the second. Nothing else
in the file differs from main.

test/reconcile-rulesets/run.sh: git stores fake-gh as 100644 and run.sh copied
it to $bin/gh without the exec bit, so PATH lookup skipped it and the suite
called the REAL gh against acme/* (in this sandbox it was refused with 403, and
the run aborted at test 1). chmod +x after the copy; 17/17 pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012rYJxu978iUSGFZ1UuqTsi
rishitank added a commit that referenced this pull request Oct 9, 2026
@rishitank @claude
ops(rulesets): manage review-gate approvals from settings.yml, set to…
c90f610
… 0 (#18)

Adds rulesets.review_gate.required_approving_review_count: 0 to settings.yml, scripts/reconcile-rulesets.sh (changes only that number, reads every write back) with 17 tests, and a `rulesets` job and dispatch input in repo-settings-reconcile.yml alongside #17's prune job.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012rYJxu978iUSGFZ1UuqTsi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@rishitank
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.