feat: Add Discord webhook notifications for key platform events (#226)#274
feat: Add Discord webhook notifications for key platform events (#226)#274zp6 wants to merge 1 commit into
Conversation
|
|
@zp6 is attempting to deploy a commit to the JSON Resume Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughA new Discord webhook notification service is added in ChangesDiscord Webhook Service
Sequence Diagram(s)N/A — Single-module service with straightforward sequential formatting and HTTP POST logic; no multi-component interaction flow to visualize. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/services/discord-webhook.jsParsing error: The keyword 'const' is reserved Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/services/discord-webhook.js`:
- Around line 13-19: The sendDiscordNotification function dereferences
event.type without guarding for null/undefined; update sendDiscordNotification
to defensively check that event and event.type exist (e.g., if (!event ||
!event.type) return false) before using getTitle(event.type),
getDescription(event) and EVENT_COLORS[event.type], and apply the same guard to
the later block that also reads event.type (the section around lines 42-49) so
the function fails closed instead of throwing.
- Around line 24-30: Wrap the fetch to DISCORD_WEBHOOK_URL in a try/catch and
use an AbortController with a 5-second timeout so network errors/timeouts don't
throw or hang; pass controller.signal to fetch and clear the timeout after
completion, and on any error or non-ok response return false to preserve the
function's boolean contract (ensure you still send the JSON payload with
username 'JSON Resume' and embeds: [embed]).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 68f30ce5-f4d2-445c-9504-ac19d073f635
📒 Files selected for processing (1)
src/services/discord-webhook.js
| async function sendDiscordNotification(event) { | ||
| if (!DISCORD_WEBHOOK_URL) return false; | ||
|
|
||
| const embed = { | ||
| title: getTitle(event.type), | ||
| description: getDescription(event), | ||
| color: EVENT_COLORS[event.type] || 0x808080, |
There was a problem hiding this comment.
Guard against malformed events before dereferencing event.type.
If event is null/undefined, this throws at runtime. Add a defensive guard and fail closed.
Suggested fix
async function sendDiscordNotification(event) {
if (!DISCORD_WEBHOOK_URL) return false;
+ if (!event || !event.type) return false;Also applies to: 42-49
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/services/discord-webhook.js` around lines 13 - 19, The
sendDiscordNotification function dereferences event.type without guarding for
null/undefined; update sendDiscordNotification to defensively check that event
and event.type exist (e.g., if (!event || !event.type) return false) before
using getTitle(event.type), getDescription(event) and EVENT_COLORS[event.type],
and apply the same guard to the later block that also reads event.type (the
section around lines 42-49) so the function fails closed instead of throwing.
| const response = await fetch(DISCORD_WEBHOOK_URL, { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ username: 'JSON Resume', embeds: [embed] }), | ||
| }); | ||
|
|
||
| return response.ok; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify whether there is already a shared HTTP client pattern in this repo
# (helps align this service with existing timeout/retry conventions).
rg -n --type=js -C2 "axios.create|from 'axios'|require\\('axios'\\)|fetch\\(" srcRepository: jsonresume/jsonresume.org
Length of output: 379
🏁 Script executed:
cat -n src/services/discord-webhook.jsRepository: jsonresume/jsonresume.org
Length of output: 2252
Harden webhook delivery with timeout and error handling.
fetch can reject and has no timeout, causing callers to crash or notification flows to hang under network faults. Wrap the call in try/catch and add an AbortController-based timeout (5 seconds) to return false on failure and preserve the function's boolean contract.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/services/discord-webhook.js` around lines 24 - 30, Wrap the fetch to
DISCORD_WEBHOOK_URL in a try/catch and use an AbortController with a 5-second
timeout so network errors/timeouts don't throw or hang; pass controller.signal
to fetch and clear the timeout after completion, and on any error or non-ok
response return false to preserve the function's boolean contract (ensure you
still send the JSON payload with username 'JSON Resume' and embeds: [embed]).
Feature for #226
Wallet: zp6
Summary by CodeRabbit