Improve Discord API error handling and webhook checks#469
Improve Discord API error handling and webhook checks#469siddharthvaddem merged 1 commit intosiddharthvaddem:mainfrom
Conversation
Refactor error handling for Discord API responses and improve webhook secret checks.
📝 WalkthroughWalkthroughUpdated Discord workflow webhook response handling to conditionally parse JSON responses and made webhook-secret validation conditional based on event type ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 the current code and only fix it if needed.
Inline comments:
In @.github/workflows/discord.yaml:
- Around line 213-218: The strict-events set includes "workflow_dispatch" but
that check never runs because getPullRequest() returns null for manual runs and
causes an early return; either remove "workflow_dispatch" from the strictEvents
Set to avoid misleading enforcement, or if you do want manual runs to require a
webhook, move the webhook-secret check (the strictEvents/ctx.eventName logic) to
run before getPullRequest() is called so workflow_dispatch hits that branch;
update the Set or reorder the code accordingly while keeping references to
strictEvents, context.eventName, and getPullRequest().
- Around line 113-118: The current response-parsing branch silently returns {}
for non-JSON responses which hides missing channel_id for thread creation;
update the parser so callers that perform creations (discordPost called with
createPayload) require a JSON response: add a flag/parameter (e.g.,
requireJsonForCreate) or detect createPayload presence in discordPost and, when
set, avoid the fallback path and throw or return an error if contentType does
not include "application/json" (instead of returning {}); keep the permissive
warning+{} behavior for non-create calls. Ensure you modify the code path that
checks contentType.includes("application/json") and the callers
(discordPost/createPayload) so create requests enforce JSON and propagate the
error to fail the workflow rather than returning an empty object.
🪄 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: 80b4e45c-fa1d-451f-9c82-36590d68fd5f
📒 Files selected for processing (1)
.github/workflows/discord.yaml
Summary by CodeRabbit