Skip to content

Commit 64f71ca

Browse files
authored
Merge pull request #86 from alexyaroshuk/daily-pr-conflicts
update daily-pr-conflicts.ts
2 parents d353280 + 70155b4 commit 64f71ca

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

script/daily-pr-conflicts.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ interface PR {
1010
}
1111

1212
const 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

1422
async 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

4654
async 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

7994
async 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

Comments
 (0)