@@ -10,6 +10,14 @@ interface PR {
1010}
1111
1212const REPO = "anomalyco/opencode"
13+ const UPSTREAM_URL = "https://github.com/anomalyco/opencode.git"
14+
15+ async function setupUpstream ( ) {
16+ try {
17+ await $ `git remote add upstream ${ UPSTREAM_URL } ` . nothrow ( ) . quiet ( )
18+ } catch { }
19+ await $ `git fetch upstream --quiet` . quiet ( )
20+ }
1321
1422async function getAuthor ( ) : Promise < string > {
1523 const envAuthor = process . env . GITHUB_ACTOR
@@ -44,13 +52,20 @@ async function checkPRStatus(pr: PR, retries = 3): Promise<{ updatable: boolean;
4452}
4553
4654async function updatePR ( pr : PR ) : Promise < { success : boolean ; error ?: string } > {
55+ const currentBranch = ( await $ `git branch --show-current` . quiet ( ) ) . stdout . toString ( ) . trim ( )
56+
4757 try {
48- await $ `gh pr update-branch ${ pr . number } --repo ${ REPO } ` . quiet ( )
58+ await $ `git fetch upstream --quiet` . quiet ( )
59+ await $ `git checkout ${ pr . headRefName } ` . quiet ( )
60+ await $ `git merge upstream/${ pr . baseRefName } --no-edit` . quiet ( )
61+ await $ `git push origin ${ pr . headRefName } ` . quiet ( )
62+ await $ `git checkout ${ currentBranch } ` . quiet ( )
4963 return { success : true }
5064 } catch ( e : any ) {
51- const stderr = e ?. stderr ?. toString ( ) || ""
52- const stdout = e ?. stdout ?. toString ( ) || ""
53- return { success : false , error : stderr || stdout || "Unknown error" }
65+ const error = e ?. stderr ?. toString ( ) || e ?. stdout ?. toString ( ) || "Update failed"
66+ await $ `git merge --abort` . nothrow ( ) . quiet ( )
67+ await $ `git checkout ${ currentBranch } ` . nothrow ( ) . quiet ( )
68+ return { success : false , error }
5469 }
5570}
5671
@@ -77,6 +92,9 @@ async function getConflictDetails(pr: PR) {
7792}
7893
7994async function main ( ) {
95+ console . log ( "Setting up upstream remote..." )
96+ await setupUpstream ( )
97+
8098 console . log ( "Fetching open PRs...\n" )
8199
82100 const prs = await fetchPRs ( )
0 commit comments