@@ -30,6 +30,52 @@ Please resolve this issue to include this PR in the next beta release.` |
30 | 30 | } |
31 | 31 | } |
32 | 32 |
|
| 33 | +async function conflicts() { |
| 34 | + const out = await $`git diff --name-only --diff-filter=U`.text().catch(() => "") |
| 35 | + return out |
| 36 | + .split("\n") |
| 37 | + .map((x) => x.trim()) |
| 38 | + .filter(Boolean) |
| 39 | +} |
| 40 | + |
| 41 | +async function cleanup() { |
| 42 | + try { |
| 43 | + await $`git merge --abort` |
| 44 | + } catch {} |
| 45 | + try { |
| 46 | + await $`git checkout -- .` |
| 47 | + } catch {} |
| 48 | + try { |
| 49 | + await $`git clean -fd` |
| 50 | + } catch {} |
| 51 | +} |
| 52 | + |
| 53 | +async function fix(pr: PR, files: string[]) { |
| 54 | + console.log(` Trying to auto-resolve ${files.length} conflict(s) with opencode...`) |
| 55 | + const prompt = [ |
| 56 | + `Resolve the current git merge conflicts while merging PR #${pr.number} into the beta branch.`, |
| 57 | + `Only touch these files: ${files.join(", ")}.`, |
| 58 | + "Keep the merge in progress, do not abort the merge, and do not create a commit.", |
| 59 | + "When done, leave the working tree with no unmerged files.", |
| 60 | + ].join("\n") |
| 61 | + |
| 62 | + try { |
| 63 | + await $`opencode run ${prompt}` |
| 64 | + } catch (err) { |
| 65 | + console.log(` opencode failed: ${err}`) |
| 66 | + return false |
| 67 | + } |
| 68 | + |
| 69 | + const left = await conflicts() |
| 70 | + if (left.length > 0) { |
| 71 | + console.log(` Conflicts remain: ${left.join(", ")}`) |
| 72 | + return false |
| 73 | + } |
| 74 | + |
| 75 | + console.log(" Conflicts resolved with opencode") |
| 76 | + return true |
| 77 | +} |
| 78 | + |
33 | 79 | async function main() { |
34 | 80 | console.log("Fetching open PRs with beta label...") |
35 | 81 |
|
@@ -69,19 +115,22 @@ async function main() { |
69 | 115 | try { |
70 | 116 | await $`git merge --no-commit --no-ff pr/${pr.number}` |
71 | 117 | } catch { |
72 | | - console.log(" Failed to merge (conflicts)") |
73 | | - try { |
74 | | - await $`git merge --abort` |
75 | | - } catch {} |
76 | | - try { |
77 | | - await $`git checkout -- .` |
78 | | - } catch {} |
79 | | - try { |
80 | | - await $`git clean -fd` |
81 | | - } catch {} |
82 | | - failed.push({ number: pr.number, title: pr.title, reason: "Merge conflicts" }) |
83 | | - await commentOnPR(pr.number, "Merge conflicts with dev branch") |
84 | | - continue |
| 118 | + const files = await conflicts() |
| 119 | + if (files.length > 0) { |
| 120 | + console.log(" Failed to merge (conflicts)") |
| 121 | + if (!(await fix(pr, files))) { |
| 122 | + await cleanup() |
| 123 | + failed.push({ number: pr.number, title: pr.title, reason: "Merge conflicts" }) |
| 124 | + await commentOnPR(pr.number, "Merge conflicts with dev branch") |
| 125 | + continue |
| 126 | + } |
| 127 | + } else { |
| 128 | + console.log(" Failed to merge") |
| 129 | + await cleanup() |
| 130 | + failed.push({ number: pr.number, title: pr.title, reason: "Merge failed" }) |
| 131 | + await commentOnPR(pr.number, "Merge failed") |
| 132 | + continue |
| 133 | + } |
85 | 134 | } |
86 | 135 |
|
87 | 136 | try { |
|