|
1 | 1 | #!/usr/bin/env bun |
2 | 2 |
|
3 | 3 | import { Script } from "@opencode-ai/script" |
| 4 | +import { parseArgs } from "util" |
4 | 5 |
|
5 | 6 | interface PR { |
6 | 7 | number: number |
@@ -20,10 +21,10 @@ interface FailedPR { |
20 | 21 | reason: string |
21 | 22 | } |
22 | 23 |
|
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") |
| 24 | +async function postToDiscord(failures: FailedPR[], webhookUrl?: string) { |
| 25 | + const url = webhookUrl || process.env.DISCORD_ISSUES_WEBHOOK_URL |
| 26 | + if (!url) { |
| 27 | + console.log("Warning: No Discord webhook URL provided, skipping notification") |
27 | 28 | return |
28 | 29 | } |
29 | 30 |
|
@@ -37,7 +38,7 @@ Please resolve these conflicts manually.` |
37 | 38 |
|
38 | 39 | const content = JSON.stringify({ content: message }) |
39 | 40 |
|
40 | | - const response = await fetch(webhookUrl, { |
| 41 | + const response = await fetch(url, { |
41 | 42 | method: "POST", |
42 | 43 | headers: { "Content-Type": "application/json" }, |
43 | 44 | body: content, |
@@ -51,6 +52,15 @@ Please resolve these conflicts manually.` |
51 | 52 | } |
52 | 53 |
|
53 | 54 | async function main() { |
| 55 | + const { values } = parseArgs({ |
| 56 | + args: Bun.argv.slice(2), |
| 57 | + options: { |
| 58 | + "discord-webhook": { type: "string", short: "d" }, |
| 59 | + }, |
| 60 | + }) |
| 61 | + |
| 62 | + const discordWebhook = values["discord-webhook"] as string | undefined |
| 63 | + |
54 | 64 | console.log("Fetching open PRs from team members...") |
55 | 65 |
|
56 | 66 | const allPrs: PR[] = [] |
@@ -145,7 +155,7 @@ async function main() { |
145 | 155 | console.log(`Failed: ${failed.length} PRs`) |
146 | 156 | failed.forEach((f) => console.log(` - PR #${f.number}: ${f.reason}`)) |
147 | 157 |
|
148 | | - await postToDiscord(failed) |
| 158 | + await postToDiscord(failed, discordWebhook) |
149 | 159 |
|
150 | 160 | throw new Error(`${failed.length} PR(s) failed to merge. Check Discord for details.`) |
151 | 161 | } |
|