@@ -49,33 +49,50 @@ async function main() {
4949 continue
5050 }
5151
52- // Try to squash merge the PR directly (allow unrelated histories since beta starts fresh from dev)
53- console . log ( ` Attempting to merge PR #${ pr . number } ...` )
54- const merge = await $ `git merge --squash --allow-unrelated-histories pr-${ pr . number } ` . nothrow ( )
55- if ( merge . exitCode !== 0 ) {
56- console . log ( ` Squash merge failed for PR #${ pr . number } ` )
57- console . log ( ` Error: ${ merge . stderr } ` )
58- await $ `git reset --hard HEAD` . nothrow ( )
59- skipped . push ( { number : pr . number , reason : `Squash merge failed: ${ merge . stderr } ` } )
52+ // Get diff from PR base to PR head and apply it
53+ console . log ( ` Getting diff for PR #${ pr . number } ...` )
54+ const diff = await $ `git diff HEAD...pr-${ pr . number } ` . nothrow ( )
55+ if ( diff . exitCode !== 0 ) {
56+ console . log ( ` Failed to get diff for PR #${ pr . number } ` )
57+ console . log ( ` Error: ${ diff . stderr } ` )
58+ skipped . push ( { number : pr . number , reason : `Failed to get diff: ${ diff . stderr } ` } )
6059 continue
6160 }
6261
62+ if ( ! diff . stdout . trim ( ) ) {
63+ console . log ( ` No changes in PR #${ pr . number } , skipping` )
64+ skipped . push ( { number : pr . number , reason : "No changes" } )
65+ continue
66+ }
67+
68+ // Apply the diff
69+ console . log ( ` Applying diff for PR #${ pr . number } ...` )
70+ const apply = await Bun . spawn ( [ "git" , "apply" ] , {
71+ stdin : new TextEncoder ( ) . encode ( diff . stdout ) ,
72+ stdout : "pipe" ,
73+ stderr : "pipe" ,
74+ } )
75+ const applyExit = await apply . exited
76+ const applyStderr = await Bun . readableStreamToText ( apply . stderr )
77+
78+ if ( applyExit !== 0 ) {
79+ console . log ( ` Failed to apply diff for PR #${ pr . number } ` )
80+ console . log ( ` Error: ${ applyStderr } ` )
81+ await $ `git checkout -- .` . nothrow ( )
82+ skipped . push ( { number : pr . number , reason : `Failed to apply diff: ${ applyStderr } ` } )
83+ continue
84+ }
85+
86+ // Stage all changes
6387 const add = await $ `git add -A` . nothrow ( )
6488 if ( add . exitCode !== 0 ) {
6589 console . log ( ` Failed to stage changes for PR #${ pr . number } ` )
66- await $ `git reset --hard HEAD ` . nothrow ( )
90+ await $ `git checkout -- . ` . nothrow ( )
6791 skipped . push ( { number : pr . number , reason : "Failed to stage" } )
6892 continue
6993 }
7094
71- const status = await $ `git status --porcelain` . nothrow ( )
72- if ( status . exitCode !== 0 || ! status . stdout . trim ( ) ) {
73- console . log ( ` No changes to commit for PR #${ pr . number } , skipping` )
74- await $ `git reset --hard HEAD` . nothrow ( )
75- skipped . push ( { number : pr . number , reason : "No changes to commit" } )
76- continue
77- }
78-
95+ // Commit
7996 const commitMsg = `Apply PR #${ pr . number } : ${ pr . title } `
8097 const commit = await Bun . spawn ( [ "git" , "commit" , "-m" , commitMsg ] , { stdout : "pipe" , stderr : "pipe" } )
8198 const commitExit = await commit . exited
@@ -84,7 +101,7 @@ async function main() {
84101 if ( commitExit !== 0 ) {
85102 console . log ( ` Failed to commit PR #${ pr . number } ` )
86103 console . log ( ` Error: ${ commitStderr } ` )
87- await $ `git reset --hard HEAD ` . nothrow ( )
104+ await $ `git checkout -- . ` . nothrow ( )
88105 skipped . push ( { number : pr . number , reason : `Commit failed: ${ commitStderr } ` } )
89106 continue
90107 }
0 commit comments