ci: collect all failed PR merges and notify Discord
parent
d35956fd92
commit
c9891fe071
|
|
@ -14,6 +14,42 @@ interface RunResult {
|
||||||
stderr: string
|
stderr: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface FailedPR {
|
||||||
|
number: number
|
||||||
|
title: string
|
||||||
|
reason: string
|
||||||
|
}
|
||||||
|
|
||||||
|
async function postToDiscord(failures: FailedPR[]) {
|
||||||
|
const webhookUrl = process.env.DISCORD_ISSUES_WEBHOOK_URL
|
||||||
|
if (!webhookUrl) {
|
||||||
|
console.log("Warning: DISCORD_ISSUES_WEBHOOK_URL not set, skipping Discord notification")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const message = `**Beta Branch Merge Failures**
|
||||||
|
|
||||||
|
The following team PRs failed to merge into the beta branch:
|
||||||
|
|
||||||
|
${failures.map((f) => `- **#${f.number}**: ${f.title} - ${f.reason}`).join("\n")}
|
||||||
|
|
||||||
|
Please resolve these conflicts manually.`
|
||||||
|
|
||||||
|
const content = JSON.stringify({ content: message })
|
||||||
|
|
||||||
|
const response = await fetch(webhookUrl, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: content,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
console.error("Failed to post to Discord:", await response.text())
|
||||||
|
} else {
|
||||||
|
console.log("Posted failures to Discord")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
console.log("Fetching open PRs from team members...")
|
console.log("Fetching open PRs from team members...")
|
||||||
|
|
||||||
|
|
@ -52,6 +88,7 @@ async function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const applied: number[] = []
|
const applied: number[] = []
|
||||||
|
const failed: FailedPR[] = []
|
||||||
|
|
||||||
for (const pr of prs) {
|
for (const pr of prs) {
|
||||||
console.log(`\nProcessing PR #${pr.number}: ${pr.title}`)
|
console.log(`\nProcessing PR #${pr.number}: ${pr.title}`)
|
||||||
|
|
@ -59,7 +96,9 @@ async function main() {
|
||||||
console.log(" Fetching PR head...")
|
console.log(" Fetching PR head...")
|
||||||
const fetch = await run(["git", "fetch", "origin", `pull/${pr.number}/head:pr/${pr.number}`])
|
const fetch = await run(["git", "fetch", "origin", `pull/${pr.number}/head:pr/${pr.number}`])
|
||||||
if (fetch.exitCode !== 0) {
|
if (fetch.exitCode !== 0) {
|
||||||
throw new Error(`Failed to fetch PR #${pr.number}: ${fetch.stderr}`)
|
console.log(` Failed to fetch: ${fetch.stderr}`)
|
||||||
|
failed.push({ number: pr.number, title: pr.title, reason: "Fetch failed" })
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(" Merging...")
|
console.log(" Merging...")
|
||||||
|
|
@ -69,7 +108,8 @@ async function main() {
|
||||||
await $`git merge --abort`.nothrow()
|
await $`git merge --abort`.nothrow()
|
||||||
await $`git checkout -- .`.nothrow()
|
await $`git checkout -- .`.nothrow()
|
||||||
await $`git clean -fd`.nothrow()
|
await $`git clean -fd`.nothrow()
|
||||||
throw new Error(`Failed to merge PR #${pr.number}: Has conflicts`)
|
failed.push({ number: pr.number, title: pr.title, reason: "Merge conflicts" })
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const mergeHead = await $`git rev-parse -q --verify MERGE_HEAD`.nothrow()
|
const mergeHead = await $`git rev-parse -q --verify MERGE_HEAD`.nothrow()
|
||||||
|
|
@ -80,13 +120,17 @@ async function main() {
|
||||||
|
|
||||||
const add = await $`git add -A`.nothrow()
|
const add = await $`git add -A`.nothrow()
|
||||||
if (add.exitCode !== 0) {
|
if (add.exitCode !== 0) {
|
||||||
throw new Error(`Failed to stage changes for PR #${pr.number}`)
|
console.log(" Failed to stage changes")
|
||||||
|
failed.push({ number: pr.number, title: pr.title, reason: "Staging failed" })
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const commitMsg = `Apply PR #${pr.number}: ${pr.title}`
|
const commitMsg = `Apply PR #${pr.number}: ${pr.title}`
|
||||||
const commit = await run(["git", "commit", "-m", commitMsg])
|
const commit = await run(["git", "commit", "-m", commitMsg])
|
||||||
if (commit.exitCode !== 0) {
|
if (commit.exitCode !== 0) {
|
||||||
throw new Error(`Failed to commit PR #${pr.number}: ${commit.stderr}`)
|
console.log(` Failed to commit: ${commit.stderr}`)
|
||||||
|
failed.push({ number: pr.number, title: pr.title, reason: "Commit failed" })
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(" Applied successfully")
|
console.log(" Applied successfully")
|
||||||
|
|
@ -97,6 +141,15 @@ async function main() {
|
||||||
console.log(`Applied: ${applied.length} PRs`)
|
console.log(`Applied: ${applied.length} PRs`)
|
||||||
applied.forEach((num) => console.log(` - PR #${num}`))
|
applied.forEach((num) => console.log(` - PR #${num}`))
|
||||||
|
|
||||||
|
if (failed.length > 0) {
|
||||||
|
console.log(`Failed: ${failed.length} PRs`)
|
||||||
|
failed.forEach((f) => console.log(` - PR #${f.number}: ${f.reason}`))
|
||||||
|
|
||||||
|
await postToDiscord(failed)
|
||||||
|
|
||||||
|
throw new Error(`${failed.length} PR(s) failed to merge. Check Discord for details.`)
|
||||||
|
}
|
||||||
|
|
||||||
console.log("\nForce pushing beta branch...")
|
console.log("\nForce pushing beta branch...")
|
||||||
const push = await $`git push origin beta --force --no-verify`.nothrow()
|
const push = await $`git push origin beta --force --no-verify`.nothrow()
|
||||||
if (push.exitCode !== 0) {
|
if (push.exitCode !== 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue