@@ -14,6 +14,42 @@ interface RunResult { |
14 | 14 | stderr: string |
15 | 15 | } |
16 | 16 |
|
| 17 | +interface FailedPR { |
| 18 | + number: number |
| 19 | + title: string |
| 20 | + reason: string |
| 21 | +} |
| 22 | + |
| 23 | +async function postToDiscord(failures: FailedPR[]) { |
| 24 | + const webhookUrl = process.env.DISCORD_ISSUES_WEBHOOK_URL |
| 25 | + if (!webhookUrl) { |
| 26 | + console.log("Warning: DISCORD_ISSUES_WEBHOOK_URL not set, skipping Discord notification") |
| 27 | + return |
| 28 | + } |
| 29 | + |
| 30 | + const message = `**Beta Branch Merge Failures** |
| 31 | +
|
| 32 | +The following team PRs failed to merge into the beta branch: |
| 33 | +
|
| 34 | +${failures.map((f) => `- **#${f.number}**: ${f.title} - ${f.reason}`).join("\n")} |
| 35 | +
|
| 36 | +Please resolve these conflicts manually.` |
| 37 | + |
| 38 | + const content = JSON.stringify({ content: message }) |
| 39 | + |
| 40 | + const response = await fetch(webhookUrl, { |
| 41 | + method: "POST", |
| 42 | + headers: { "Content-Type": "application/json" }, |
| 43 | + body: content, |
| 44 | + }) |
| 45 | + |
| 46 | + if (!response.ok) { |
| 47 | + console.error("Failed to post to Discord:", await response.text()) |
| 48 | + } else { |
| 49 | + console.log("Posted failures to Discord") |
| 50 | + } |
| 51 | +} |
| 52 | + |
17 | 53 | async function main() { |
18 | 54 | console.log("Fetching open PRs from team members...") |
19 | 55 |
|
@@ -52,14 +88,17 @@ async function main() { |
52 | 88 | } |
53 | 89 |
|
54 | 90 | const applied: number[] = [] |
| 91 | + const failed: FailedPR[] = [] |
55 | 92 |
|
56 | 93 | for (const pr of prs) { |
57 | 94 | console.log(`\nProcessing PR #${pr.number}: ${pr.title}`) |
58 | 95 |
|
59 | 96 | console.log(" Fetching PR head...") |
60 | 97 | const fetch = await run(["git", "fetch", "origin", `pull/${pr.number}/head:pr/${pr.number}`]) |
61 | 98 | if (fetch.exitCode !== 0) { |
62 | | - throw new Error(`Failed to fetch PR #${pr.number}: ${fetch.stderr}`) |
| 99 | + console.log(` Failed to fetch: ${fetch.stderr}`) |
| 100 | + failed.push({ number: pr.number, title: pr.title, reason: "Fetch failed" }) |
| 101 | + continue |
63 | 102 | } |
64 | 103 |
|
65 | 104 | console.log(" Merging...") |
@@ -69,7 +108,8 @@ async function main() { |
69 | 108 | await $`git merge --abort`.nothrow() |
70 | 109 | await $`git checkout -- .`.nothrow() |
71 | 110 | await $`git clean -fd`.nothrow() |
72 | | - throw new Error(`Failed to merge PR #${pr.number}: Has conflicts`) |
| 111 | + failed.push({ number: pr.number, title: pr.title, reason: "Merge conflicts" }) |
| 112 | + continue |
73 | 113 | } |
74 | 114 |
|
75 | 115 | const mergeHead = await $`git rev-parse -q --verify MERGE_HEAD`.nothrow() |
@@ -80,13 +120,17 @@ async function main() { |
80 | 120 |
|
81 | 121 | const add = await $`git add -A`.nothrow() |
82 | 122 | if (add.exitCode !== 0) { |
83 | | - throw new Error(`Failed to stage changes for PR #${pr.number}`) |
| 123 | + console.log(" Failed to stage changes") |
| 124 | + failed.push({ number: pr.number, title: pr.title, reason: "Staging failed" }) |
| 125 | + continue |
84 | 126 | } |
85 | 127 |
|
86 | 128 | const commitMsg = `Apply PR #${pr.number}: ${pr.title}` |
87 | 129 | const commit = await run(["git", "commit", "-m", commitMsg]) |
88 | 130 | if (commit.exitCode !== 0) { |
89 | | - throw new Error(`Failed to commit PR #${pr.number}: ${commit.stderr}`) |
| 131 | + console.log(` Failed to commit: ${commit.stderr}`) |
| 132 | + failed.push({ number: pr.number, title: pr.title, reason: "Commit failed" }) |
| 133 | + continue |
90 | 134 | } |
91 | 135 |
|
92 | 136 | console.log(" Applied successfully") |
@@ -97,6 +141,15 @@ async function main() { |
97 | 141 | console.log(`Applied: ${applied.length} PRs`) |
98 | 142 | applied.forEach((num) => console.log(` - PR #${num}`)) |
99 | 143 |
|
| 144 | + if (failed.length > 0) { |
| 145 | + console.log(`Failed: ${failed.length} PRs`) |
| 146 | + failed.forEach((f) => console.log(` - PR #${f.number}: ${f.reason}`)) |
| 147 | + |
| 148 | + await postToDiscord(failed) |
| 149 | + |
| 150 | + throw new Error(`${failed.length} PR(s) failed to merge. Check Discord for details.`) |
| 151 | + } |
| 152 | + |
100 | 153 | console.log("\nForce pushing beta branch...") |
101 | 154 | const push = await $`git push origin beta --force --no-verify`.nothrow() |
102 | 155 | if (push.exitCode !== 0) { |
|