|
1 | 1 | #!/usr/bin/env bun |
2 | 2 |
|
| 3 | +import { Script } from "@opencode-ai/script" |
| 4 | + |
3 | 5 | interface PR { |
4 | 6 | number: number |
5 | 7 | title: string |
| 8 | + author: { login: string } |
6 | 9 | } |
7 | 10 |
|
8 | 11 | interface RunResult { |
@@ -12,15 +15,29 @@ interface RunResult { |
12 | 15 | } |
13 | 16 |
|
14 | 17 | async function main() { |
15 | | - console.log("Fetching open contributor PRs...") |
16 | | - |
17 | | - const prsResult = await $`gh pr list --label contributor --state open --json number,title --limit 100`.nothrow() |
18 | | - if (prsResult.exitCode !== 0) { |
19 | | - throw new Error(`Failed to fetch PRs: ${prsResult.stderr}`) |
| 18 | + console.log("Fetching open PRs from team members...") |
| 19 | + |
| 20 | + const allPrs: PR[] = [] |
| 21 | + for (const member of Script.team) { |
| 22 | + const result = await $`gh pr list --state open --author ${member} --json number,title,author --limit 100`.nothrow() |
| 23 | + if (result.exitCode !== 0) continue |
| 24 | + const memberPrs: PR[] = JSON.parse(result.stdout) |
| 25 | + allPrs.push(...memberPrs) |
20 | 26 | } |
21 | 27 |
|
22 | | - const prs: PR[] = JSON.parse(prsResult.stdout) |
23 | | - console.log(`Found ${prs.length} open contributor PRs`) |
| 28 | + const seen = new Set<number>() |
| 29 | + const prs = allPrs.filter((pr) => { |
| 30 | + if (seen.has(pr.number)) return false |
| 31 | + seen.add(pr.number) |
| 32 | + return true |
| 33 | + }) |
| 34 | + |
| 35 | + console.log(`Found ${prs.length} open PRs from team members`) |
| 36 | + |
| 37 | + if (prs.length === 0) { |
| 38 | + console.log("No team PRs to merge") |
| 39 | + return |
| 40 | + } |
24 | 41 |
|
25 | 42 | console.log("Fetching latest dev branch...") |
26 | 43 | const fetchDev = await $`git fetch origin dev`.nothrow() |
@@ -35,17 +52,14 @@ async function main() { |
35 | 52 | } |
36 | 53 |
|
37 | 54 | const applied: number[] = [] |
38 | | - const skipped: Array<{ number: number; reason: string }> = [] |
39 | 55 |
|
40 | 56 | for (const pr of prs) { |
41 | 57 | console.log(`\nProcessing PR #${pr.number}: ${pr.title}`) |
42 | 58 |
|
43 | 59 | console.log(" Fetching PR head...") |
44 | 60 | const fetch = await run(["git", "fetch", "origin", `pull/${pr.number}/head:pr/${pr.number}`]) |
45 | 61 | if (fetch.exitCode !== 0) { |
46 | | - console.log(` Failed to fetch PR head: ${fetch.stderr}`) |
47 | | - skipped.push({ number: pr.number, reason: `Fetch failed: ${fetch.stderr}` }) |
48 | | - continue |
| 62 | + throw new Error(`Failed to fetch PR #${pr.number}: ${fetch.stderr}`) |
49 | 63 | } |
50 | 64 |
|
51 | 65 | console.log(" Merging...") |
@@ -55,34 +69,24 @@ async function main() { |
55 | 69 | await $`git merge --abort`.nothrow() |
56 | 70 | await $`git checkout -- .`.nothrow() |
57 | 71 | await $`git clean -fd`.nothrow() |
58 | | - skipped.push({ number: pr.number, reason: "Has conflicts" }) |
59 | | - continue |
| 72 | + throw new Error(`Failed to merge PR #${pr.number}: Has conflicts`) |
60 | 73 | } |
61 | 74 |
|
62 | 75 | const mergeHead = await $`git rev-parse -q --verify MERGE_HEAD`.nothrow() |
63 | 76 | if (mergeHead.exitCode !== 0) { |
64 | 77 | console.log(" No changes, skipping") |
65 | | - skipped.push({ number: pr.number, reason: "No changes" }) |
66 | 78 | continue |
67 | 79 | } |
68 | 80 |
|
69 | 81 | const add = await $`git add -A`.nothrow() |
70 | 82 | if (add.exitCode !== 0) { |
71 | | - console.log(" Failed to stage") |
72 | | - await $`git checkout -- .`.nothrow() |
73 | | - await $`git clean -fd`.nothrow() |
74 | | - skipped.push({ number: pr.number, reason: "Failed to stage" }) |
75 | | - continue |
| 83 | + throw new Error(`Failed to stage changes for PR #${pr.number}`) |
76 | 84 | } |
77 | 85 |
|
78 | 86 | const commitMsg = `Apply PR #${pr.number}: ${pr.title}` |
79 | 87 | const commit = await run(["git", "commit", "-m", commitMsg]) |
80 | 88 | if (commit.exitCode !== 0) { |
81 | | - console.log(` Failed to commit: ${commit.stderr}`) |
82 | | - await $`git checkout -- .`.nothrow() |
83 | | - await $`git clean -fd`.nothrow() |
84 | | - skipped.push({ number: pr.number, reason: `Commit failed: ${commit.stderr}` }) |
85 | | - continue |
| 89 | + throw new Error(`Failed to commit PR #${pr.number}: ${commit.stderr}`) |
86 | 90 | } |
87 | 91 |
|
88 | 92 | console.log(" Applied successfully") |
@@ -92,8 +96,6 @@ async function main() { |
92 | 96 | console.log("\n--- Summary ---") |
93 | 97 | console.log(`Applied: ${applied.length} PRs`) |
94 | 98 | applied.forEach((num) => console.log(` - PR #${num}`)) |
95 | | - console.log(`Skipped: ${skipped.length} PRs`) |
96 | | - skipped.forEach((x) => console.log(` - PR #${x.number}: ${x.reason}`)) |
97 | 99 |
|
98 | 100 | console.log("\nForce pushing beta branch...") |
99 | 101 | const push = await $`git push origin beta --force --no-verify`.nothrow() |
|