Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions .github/workflows/discord.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,19 @@ jobs:
})
});

const contentType = (response.headers.get("content-type") || "").toLowerCase();
const text = await response.text();

if (!response.ok) {
const text = await response.text();
throw new Error(`Discord API error ${response.status}: ${text}`);
}

const text = await response.text();
return text ? JSON.parse(text) : {};
if (!text) return {};
if (contentType.includes("application/json")) return JSON.parse(text);

// Some proxy/CDN edge responses may return HTML with 2xx; avoid crashing on JSON parse.
core.warning(`Discord webhook returned non-JSON response (content-type: ${contentType || "unknown"}).`);
return {};
}

async function patchDiscordThread(threadId, patchBody) {
Expand Down Expand Up @@ -204,9 +210,15 @@ jobs:
}

if (!webhookUrl) {
core.setFailed(
"Missing Discord webhook secret. Set either DISCORD_WEBHOOK_URL or DISCORD_PR_FORUM_WEBHOOK in repository secrets, or pass it explicitly if using reusable workflows."
);
const strictEvents = new Set(["pull_request_target", "workflow_dispatch"]);
const msg =
`Discord sync skipped: webhook secret unavailable for event '${context.eventName}'. ` +
"Set either DISCORD_WEBHOOK_URL or DISCORD_PR_FORUM_WEBHOOK in repository secrets.";
if (strictEvents.has(context.eventName)) {
core.setFailed(msg);
} else {
core.warning(msg);
}
return;
}
Comment on lines 212 to 223
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

nit: workflow_dispatch in strictEvents is effectively dead code

getPullRequest() only returns a PR for pull_request_target, pull_request_review, and issue_comment. For workflow_dispatch it returns null, so we bail at the if (!pr) check on line 207-210 before ever reaching this webhook-missing branch. So in practice only pull_request_target can ever trigger setFailed here — workflow_dispatch will never hit it.

not a bug, just kinda misleading. either drop workflow_dispatch from the set, or (if the intent was "fail loudly on manual runs with misconfig") move a similar check earlier so it actually fires. totally fine to leave as-is too, just flagging.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/discord.yaml around lines 212 - 223, The set strictEvents
currently includes "workflow_dispatch" which is dead here because
getPullRequest()/pr-check runs earlier; remove "workflow_dispatch" from the
strictEvents Set (where strictEvents is defined and used with context.eventName)
so only events that can reach this branch (e.g., "pull_request_target") will
call core.setFailed, or alternatively move this webhook-missing early-fail logic
before the getPullRequest()/pr check if your intent is to fail on manual
workflow_dispatch runs—pick one approach and apply it to the block that
defines/uses strictEvents and the subsequent core.setFailed/core.warning calls.


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki" />
</a>
&nbsp;
<a href="https://discord.gg/yAQQhRaEeg">
<a href="https://discord.gg/8552rJwVRX">
<img src="https://img.shields.io/discord/pHAUbcqNd?logo=discord&label=Discord&color=5865F2" alt="Join Discord" />
</a>
</p>
Expand Down
Loading