Skip to content
Merged
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 {};
Comment thread
siddharthvaddem marked this conversation as resolved.
}

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);
Comment thread
siddharthvaddem marked this conversation as resolved.
} else {
core.warning(msg);
}
return;
}

Expand Down
Loading