Skip to content

Commit 95309c2

Browse files
committed
fix(beta): use local git rebase instead of gh pr update-branch
1 parent e9e8d97 commit 95309c2

2 files changed

Lines changed: 20 additions & 41 deletions

File tree

.github/workflows/beta.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: blacksmith-4vcpu-ubuntu-2404
1616
permissions:
1717
contents: write
18-
pull-requests: read
18+
pull-requests: write
1919
steps:
2020
- name: Checkout repository
2121
uses: actions/checkout@v4

script/beta.ts

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -41,53 +41,32 @@ async function main() {
4141
for (const pr of prs) {
4242
console.log(`\nProcessing PR #${pr.number}: ${pr.title}`)
4343

44-
// Try to update PR branch via GitHub API (rebase onto base branch)
45-
console.log(` Attempting to rebase PR #${pr.number} via GitHub API...`)
46-
const updateBranch = await $`gh pr update-branch ${pr.number} --rebase`.nothrow()
47-
if (updateBranch.exitCode !== 0) {
48-
console.log(` Rebase failed for PR #${pr.number} (has conflicts)`)
49-
console.log(` Error: ${updateBranch.stderr}`)
50-
skipped.push({ number: pr.number, reason: "Rebase failed (conflicts)" })
44+
// Fetch the PR
45+
const fetchPR = await $`git fetch origin pull/${pr.number}/head:pr-${pr.number}`.nothrow()
46+
if (fetchPR.exitCode !== 0) {
47+
console.log(` Failed to fetch PR #${pr.number}, skipping`)
48+
skipped.push({ number: pr.number, reason: "Failed to fetch" })
5149
continue
5250
}
5351

54-
console.log(` Rebase initiated for PR #${pr.number}`)
55-
56-
// Wait for rebase to complete by polling PR state
57-
console.log(` Waiting for rebase to complete...`)
58-
let rebaseComplete = false
59-
let attempts = 0
60-
const maxAttempts = 30
61-
62-
while (!rebaseComplete && attempts < maxAttempts) {
63-
await Bun.sleep(2000) // Wait 2 seconds
64-
attempts++
65-
66-
const prCheck = await $`gh pr view ${pr.number} --json mergeStateStatus,headRefOid`.nothrow()
67-
if (prCheck.exitCode === 0) {
68-
const prData = JSON.parse(prCheck.stdout)
69-
// mergeStateStatus will be "clean" when rebase is complete and no conflicts
70-
if (prData.mergeStateStatus === "clean") {
71-
rebaseComplete = true
72-
console.log(` Rebase completed for PR #${pr.number}`)
73-
}
74-
}
75-
}
76-
77-
if (!rebaseComplete) {
78-
console.log(` Timeout waiting for rebase on PR #${pr.number}`)
79-
skipped.push({ number: pr.number, reason: "Timeout waiting for rebase" })
52+
// Try to rebase onto current beta branch
53+
console.log(` Attempting to rebase PR #${pr.number}...`)
54+
const rebase = await $`git rebase beta pr-${pr.number}`.nothrow()
55+
if (rebase.exitCode !== 0) {
56+
console.log(` Rebase failed for PR #${pr.number} (has conflicts)`)
57+
await $`git rebase --abort`.nothrow()
58+
await $`git checkout beta`.nothrow()
59+
skipped.push({ number: pr.number, reason: "Rebase failed (conflicts)" })
8060
continue
8161
}
8262

83-
// Fetch the rebased PR
84-
const fetchPR = await $`git fetch origin pull/${pr.number}/head:pr-${pr.number}`.nothrow()
85-
if (fetchPR.exitCode !== 0) {
86-
console.log(` Failed to fetch PR #${pr.number} after rebase, skipping`)
87-
skipped.push({ number: pr.number, reason: "Failed to fetch after rebase" })
88-
continue
89-
}
63+
// Move rebased commits to pr-${pr.number} branch and checkout back to beta
64+
await $`git checkout -B pr-${pr.number}`.nothrow()
65+
await $`git checkout beta`.nothrow()
66+
67+
console.log(` Successfully rebased PR #${pr.number}`)
9068

69+
// Now squash merge the rebased PR
9170
const merge = await $`git merge --squash pr-${pr.number}`.nothrow()
9271
if (merge.exitCode !== 0) {
9372
console.log(` Squash merge failed for PR #${pr.number}`)

0 commit comments

Comments
 (0)