Skip to content

Org-Wide Auto-Rebase Manager #1700

Org-Wide Auto-Rebase Manager

Org-Wide Auto-Rebase Manager #1700

name: Org-Wide Auto-Rebase Manager
on:
push:
branches: [main, master]
schedule:
- cron: '*/30 * * * *' # Every 30 minutes
workflow_dispatch: # Manual trigger
jobs:
manage-rebase:
name: Rebase All Org PRs
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Rebase Open PRs across Org
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_PAT_PLATFORM_MANAGER || secrets.GITHUB_TOKEN }}
script: |
const org = 'vindicta-platform';
// 1. List all repositories in the org
const { data: repos } = await github.rest.repos.listForOrg({
org,
type: 'all',
per_page: 100
});
core.info(`Managing ${repos.length} repositories for ${org}`);
for (const repoInfo of repos) {
const repo = repoInfo.name;
// 2. Get all open, non-draft PRs for this repo
const { data: prs } = await github.rest.pulls.list({
owner: org,
repo,
state: 'open'
});
if (prs.length === 0) continue;
core.info(`Checking ${prs.length} PRs in ${repo}...`);
for (const pr of prs) {
if (pr.draft) continue;
try {
// Use GitHub's native update branch API
// This brings the PR up to date with its base branch
await github.rest.pulls.updateBranch({
owner: org,
repo,
pull_number: pr.number
});
core.notice(`Updated PR #${pr.number} in ${repo}`);
} catch (error) {
// 422 usually means already up-to-date or has conflicts
if (error.status !== 422) {
core.warning(`Error updating PR #${pr.number} in ${repo}: ${error.message}`);
}
}
}
}