11#!/usr/bin/env bun
22
3+ import { $ } from "bun"
34import { Script } from "@opencode-ai/script"
45
56interface PR {
@@ -8,12 +9,6 @@ interface PR {
89 author : { login : string }
910}
1011
11- interface RunResult {
12- exitCode : number
13- stdout : string
14- stderr : string
15- }
16-
1712interface FailedPR {
1813 number : number
1914 title : string
@@ -55,10 +50,13 @@ async function main() {
5550
5651 const allPrs : PR [ ] = [ ]
5752 for ( const member of Script . team ) {
58- const result = await $ `gh pr list --state open --author ${ member } --json number,title,author --limit 100` . nothrow ( )
59- if ( result . exitCode !== 0 ) continue
60- const memberPrs : PR [ ] = JSON . parse ( result . stdout )
61- allPrs . push ( ...memberPrs )
53+ try {
54+ const stdout = await $ `gh pr list --state open --author ${ member } --json number,title,author --limit 100` . text ( )
55+ const memberPrs : PR [ ] = JSON . parse ( stdout )
56+ allPrs . push ( ...memberPrs )
57+ } catch {
58+ // Skip member on error
59+ }
6260 }
6361
6462 const seen = new Set < number > ( )
@@ -76,16 +74,10 @@ async function main() {
7674 }
7775
7876 console . log ( "Fetching latest dev branch..." )
79- const fetchDev = await $ `git fetch origin dev` . nothrow ( )
80- if ( fetchDev . exitCode !== 0 ) {
81- throw new Error ( `Failed to fetch dev branch: ${ fetchDev . stderr } ` )
82- }
77+ await $ `git fetch origin dev`
8378
8479 console . log ( "Checking out beta branch..." )
85- const checkoutBeta = await $ `git checkout -B beta origin/dev` . nothrow ( )
86- if ( checkoutBeta . exitCode !== 0 ) {
87- throw new Error ( `Failed to checkout beta branch: ${ checkoutBeta . stderr } ` )
88- }
80+ await $ `git checkout -B beta origin/dev`
8981
9082 const applied : number [ ] = [ ]
9183 const failed : FailedPR [ ] = [ ]
@@ -94,41 +86,52 @@ async function main() {
9486 console . log ( `\nProcessing PR #${ pr . number } : ${ pr . title } ` )
9587
9688 console . log ( " Fetching PR head..." )
97- const fetch = await run ( [ "git" , "fetch" , "origin" , `pull/${ pr . number } /head:pr/${ pr . number } ` ] )
98- if ( fetch . exitCode !== 0 ) {
99- console . log ( ` Failed to fetch: ${ fetch . stderr } ` )
89+ try {
90+ await $ `git fetch origin pull/${ pr . number } /head:pr/${ pr . number } `
91+ } catch ( err ) {
92+ console . log ( ` Failed to fetch: ${ err } ` )
10093 failed . push ( { number : pr . number , title : pr . title , reason : "Fetch failed" } )
10194 continue
10295 }
10396
10497 console . log ( " Merging..." )
105- const merge = await run ( [ "git" , "merge" , "--no-commit" , "--no-ff" , `pr/${ pr . number } ` ] )
106- if ( merge . exitCode !== 0 ) {
98+ try {
99+ await $ `git merge --no-commit --no-ff pr/${ pr . number } `
100+ } catch {
107101 console . log ( " Failed to merge (conflicts)" )
108- await $ `git merge --abort` . nothrow ( )
109- await $ `git checkout -- .` . nothrow ( )
110- await $ `git clean -fd` . nothrow ( )
102+ try {
103+ await $ `git merge --abort`
104+ } catch { }
105+ try {
106+ await $ `git checkout -- .`
107+ } catch { }
108+ try {
109+ await $ `git clean -fd`
110+ } catch { }
111111 failed . push ( { number : pr . number , title : pr . title , reason : "Merge conflicts" } )
112112 continue
113113 }
114114
115- const mergeHead = await $ `git rev-parse -q --verify MERGE_HEAD` . nothrow ( )
116- if ( mergeHead . exitCode !== 0 ) {
115+ try {
116+ await $ `git rev-parse -q --verify MERGE_HEAD` . text ( )
117+ } catch {
117118 console . log ( " No changes, skipping" )
118119 continue
119120 }
120121
121- const add = await $ `git add -A` . nothrow ( )
122- if ( add . exitCode !== 0 ) {
122+ try {
123+ await $ `git add -A`
124+ } catch {
123125 console . log ( " Failed to stage changes" )
124126 failed . push ( { number : pr . number , title : pr . title , reason : "Staging failed" } )
125127 continue
126128 }
127129
128130 const commitMsg = `Apply PR #${ pr . number } : ${ pr . title } `
129- const commit = await run ( [ "git" , "commit" , "-m" , commitMsg ] )
130- if ( commit . exitCode !== 0 ) {
131- console . log ( ` Failed to commit: ${ commit . stderr } ` )
131+ try {
132+ await $ `git commit -m ${ commitMsg } `
133+ } catch ( err ) {
134+ console . log ( ` Failed to commit: ${ err } ` )
132135 failed . push ( { number : pr . number , title : pr . title , reason : "Commit failed" } )
133136 continue
134137 }
@@ -151,10 +154,7 @@ async function main() {
151154 }
152155
153156 console . log ( "\nForce pushing beta branch..." )
154- const push = await $ `git push origin beta --force --no-verify` . nothrow ( )
155- if ( push . exitCode !== 0 ) {
156- throw new Error ( `Failed to push beta branch: ${ push . stderr } ` )
157- }
157+ await $ `git push origin beta --force --no-verify`
158158
159159 console . log ( "Successfully synced beta branch" )
160160}
@@ -163,31 +163,3 @@ main().catch((err) => {
163163 console . error ( "Error:" , err )
164164 process . exit ( 1 )
165165} )
166-
167- async function run ( args : string [ ] , stdin ?: Uint8Array ) : Promise < RunResult > {
168- const proc = Bun . spawn ( args , {
169- stdin : stdin ?? "inherit" ,
170- stdout : "pipe" ,
171- stderr : "pipe" ,
172- } )
173- const exitCode = await proc . exited
174- const stdout = await new Response ( proc . stdout ) . text ( )
175- const stderr = await new Response ( proc . stderr ) . text ( )
176- return { exitCode, stdout, stderr }
177- }
178-
179- function $ ( strings : TemplateStringsArray , ...values : unknown [ ] ) {
180- const cmd = strings . reduce ( ( acc , str , i ) => acc + str + ( values [ i ] ?? "" ) , "" )
181- return {
182- async nothrow ( ) {
183- const proc = Bun . spawn ( cmd . split ( " " ) , {
184- stdout : "pipe" ,
185- stderr : "pipe" ,
186- } )
187- const exitCode = await proc . exited
188- const stdout = await new Response ( proc . stdout ) . text ( )
189- const stderr = await new Response ( proc . stderr ) . text ( )
190- return { exitCode, stdout, stderr }
191- } ,
192- }
193- }
0 commit comments