-
Notifications
You must be signed in to change notification settings - Fork 0
fix: derive event actions from @octokit/webhooks types #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis pull request adds compile-time and runtime utilities to derive and validate webhook action names from Octokit's emitter event names. It introduces Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (2)**/*.ts📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
🔇 Additional comments (5)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/types/events-api.ts(9 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
**/*.ts: Store context externally - maintain stateless bot architecture with no message history, thread context, or conversation memory
Use<@{userId}>for mentions in messages AND add mentions in sendMessage options - do not use @username format
Implement event handlers for onMessage, onSlashCommand, onReaction, onTip, and onInteractionResponse to respond to Towns Protocol events
Define slash commands in src/commands.ts as a const array with name and description properties, then register handlers using bot.onSlashCommand()
Set ID in interaction requests and match ID in responses to correlate form submissions, button clicks, and transaction/signature responses
Use readContract for reading smart contract state, writeContract for SimpleAccount operations, and execute() for external contract interactions
Fund bot.appAddress (Smart Account) for on-chain operations, not bot.botId (Gas Wallet/EOA)
Use bot.* handler methods directly (outside event handlers) for unprompted messages via webhooks, timers, or tasks - requires channelId, spaceId, or other context stored externally
Always check permissions using handler.hasAdminPermission() before performing admin operations like ban, redact, or pin
User IDs are hex addresses in format 0x..., not usernames - use them consistently throughout event handling and message sending
Slash commands do not trigger onMessage - register slash command handlers using bot.onSlashCommand() instead
Use getSmartAccountFromUserId() to retrieve a user's wallet address from their userId
Include required environment variables: APP_PRIVATE_DATA (bot credentials) and JWT_SECRET (webhook security token)
Files:
src/types/events-api.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Provide alt text for image attachments and use appropriate MIME types for chunked attachments (videos, screenshots)
Files:
src/types/events-api.ts
🪛 ESLint
src/types/events-api.ts
[error] 9-9: Unable to resolve path to module '@octokit/webhooks'.
(import-x/no-unresolved)
[error] 10-10: Unable to resolve path to module 'zod'.
(import-x/no-unresolved)
🪛 GitHub Actions: CI
src/types/events-api.ts
[warning] 12-12: tsdoc-characters-after-block-tag: The token "@octokit" looks like a TSDoc tag but contains an invalid character "/"; if it is not a tag, use a backslash to escape the "@"
🔇 Additional comments (4)
src/types/events-api.ts (4)
15-28: Excellent type-safe design!The compile-time
ActionsFor<TPrefix>and runtimeactionsFor()work together elegantly to derive actions from Octokit's event names. The type assertion is safe given the filtering and slicing logic.
30-39: LGTM!Exporting these action types improves discoverability and enables IDE hover inspection of the action unions.
81-81: LGTM! Consistent schema updates across all event types.All eight event payload schemas have been systematically updated to use the new
actionSchema()function. The consistent pattern of deriving actions from Octokit's type definitions improves maintainability and reduces the risk of drift between the codebase and upstream types.Also applies to: 110-110, 156-156, 180-180, 202-202, 230-230, 297-300, 335-335
41-51: Remove suggestion to usez.enum()— the currentrefine()approach is correct for this use case.The
actionSchemafunction validates against a runtime-determined array derived from@octokit/webhooks. Zod'sz.enum()requires a compile-time constant tuple (e.g.,z.enum(['action1', 'action2'] as const)), but theactionsarray is computed at runtime by filteringemitterEventNames. Thez.string().refine()approach with the type predicate is the idiomatic Zod solution for runtime validation and already provides appropriate error messages and type narrowing.Likely an incorrect or invalid review comment.
- Add ActionsFor<T> generic to extract action unions at compile-time - Export inspectable action types (PullRequestAction, IssuesAction, etc.) - Use actionsFor() to extract actions at runtime for Zod validation - Unknown actions now fail validation (rare since derived from Octokit)
068ab25 to
5f0dfd3
Compare
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.