ci: prevent rate limit errors when fetching team PRs for beta releases

This commit is contained in:
Dax Raad
2026-02-01 19:26:21 -05:00
parent 7417e6eb38
commit d35956fd92

View File

@@ -1,8 +1,11 @@
#!/usr/bin/env bun #!/usr/bin/env bun
import { Script } from "@opencode-ai/script"
interface PR { interface PR {
number: number number: number
title: string title: string
author: { login: string }
} }
interface RunResult { interface RunResult {
@@ -12,15 +15,29 @@ interface RunResult {
} }
async function main() { async function main() {
console.log("Fetching open contributor PRs...") console.log("Fetching open PRs from team members...")
const prsResult = await $`gh pr list --label contributor --state open --json number,title --limit 100`.nothrow() const allPrs: PR[] = []
if (prsResult.exitCode !== 0) { for (const member of Script.team) {
throw new Error(`Failed to fetch PRs: ${prsResult.stderr}`) const result = await $`gh pr list --state open --author ${member} --json number,title,author --limit 100`.nothrow()
if (result.exitCode !== 0) continue
const memberPrs: PR[] = JSON.parse(result.stdout)
allPrs.push(...memberPrs)
} }
const prs: PR[] = JSON.parse(prsResult.stdout) const seen = new Set<number>()
console.log(`Found ${prs.length} open contributor PRs`) const prs = allPrs.filter((pr) => {
if (seen.has(pr.number)) return false
seen.add(pr.number)
return true
})
console.log(`Found ${prs.length} open PRs from team members`)
if (prs.length === 0) {
console.log("No team PRs to merge")
return
}
console.log("Fetching latest dev branch...") console.log("Fetching latest dev branch...")
const fetchDev = await $`git fetch origin dev`.nothrow() const fetchDev = await $`git fetch origin dev`.nothrow()
@@ -35,7 +52,6 @@ async function main() {
} }
const applied: number[] = [] const applied: number[] = []
const skipped: Array<{ number: number; reason: string }> = []
for (const pr of prs) { for (const pr of prs) {
console.log(`\nProcessing PR #${pr.number}: ${pr.title}`) console.log(`\nProcessing PR #${pr.number}: ${pr.title}`)
@@ -43,9 +59,7 @@ async function main() {
console.log(" Fetching PR head...") console.log(" Fetching PR head...")
const fetch = await run(["git", "fetch", "origin", `pull/${pr.number}/head:pr/${pr.number}`]) const fetch = await run(["git", "fetch", "origin", `pull/${pr.number}/head:pr/${pr.number}`])
if (fetch.exitCode !== 0) { if (fetch.exitCode !== 0) {
console.log(` Failed to fetch PR head: ${fetch.stderr}`) throw new Error(`Failed to fetch PR #${pr.number}: ${fetch.stderr}`)
skipped.push({ number: pr.number, reason: `Fetch failed: ${fetch.stderr}` })
continue
} }
console.log(" Merging...") console.log(" Merging...")
@@ -55,34 +69,24 @@ async function main() {
await $`git merge --abort`.nothrow() await $`git merge --abort`.nothrow()
await $`git checkout -- .`.nothrow() await $`git checkout -- .`.nothrow()
await $`git clean -fd`.nothrow() await $`git clean -fd`.nothrow()
skipped.push({ number: pr.number, reason: "Has conflicts" }) throw new Error(`Failed to merge PR #${pr.number}: Has conflicts`)
continue
} }
const mergeHead = await $`git rev-parse -q --verify MERGE_HEAD`.nothrow() const mergeHead = await $`git rev-parse -q --verify MERGE_HEAD`.nothrow()
if (mergeHead.exitCode !== 0) { if (mergeHead.exitCode !== 0) {
console.log(" No changes, skipping") console.log(" No changes, skipping")
skipped.push({ number: pr.number, reason: "No changes" })
continue continue
} }
const add = await $`git add -A`.nothrow() const add = await $`git add -A`.nothrow()
if (add.exitCode !== 0) { if (add.exitCode !== 0) {
console.log(" Failed to stage") throw new Error(`Failed to stage changes for PR #${pr.number}`)
await $`git checkout -- .`.nothrow()
await $`git clean -fd`.nothrow()
skipped.push({ number: pr.number, reason: "Failed to stage" })
continue
} }
const commitMsg = `Apply PR #${pr.number}: ${pr.title}` const commitMsg = `Apply PR #${pr.number}: ${pr.title}`
const commit = await run(["git", "commit", "-m", commitMsg]) const commit = await run(["git", "commit", "-m", commitMsg])
if (commit.exitCode !== 0) { if (commit.exitCode !== 0) {
console.log(` Failed to commit: ${commit.stderr}`) throw new Error(`Failed to commit PR #${pr.number}: ${commit.stderr}`)
await $`git checkout -- .`.nothrow()
await $`git clean -fd`.nothrow()
skipped.push({ number: pr.number, reason: `Commit failed: ${commit.stderr}` })
continue
} }
console.log(" Applied successfully") console.log(" Applied successfully")
@@ -92,8 +96,6 @@ async function main() {
console.log("\n--- Summary ---") console.log("\n--- Summary ---")
console.log(`Applied: ${applied.length} PRs`) console.log(`Applied: ${applied.length} PRs`)
applied.forEach((num) => console.log(` - PR #${num}`)) applied.forEach((num) => console.log(` - PR #${num}`))
console.log(`Skipped: ${skipped.length} PRs`)
skipped.forEach((x) => console.log(` - PR #${x.number}: ${x.reason}`))
console.log("\nForce pushing beta branch...") console.log("\nForce pushing beta branch...")
const push = await $`git push origin beta --force --no-verify`.nothrow() const push = await $`git push origin beta --force --no-verify`.nothrow()