Conversation
📝 Walkthrough高层概述此PR为Webhook目标的自定义HTTP头部JSON验证添加了多语言错误消息,更新了通知设置和Webhook目标操作的类型签名,并增强了客户端验证逻辑以支持翻译错误消息和灵活的数据结构。 更改
预估代码审查工作量🎯 4 (Complex) | ⏱️ ~60 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
Summary of ChangesHello @ding113, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求旨在修复 CodeRabbit webhook 反馈中的多项问题,通过引入国际化错误信息、统一日志记录、标准化 Action 返回结果以及统一 Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
🧪 测试结果
总体结果: ✅ 所有测试通过 |
There was a problem hiding this comment.
Code Review
This pull request introduces enhanced validation and internationalization for custom headers and custom templates within webhook notification settings. New i18n error messages for invalid JSON, non-object JSON, and non-string header values have been added across multiple language files (English, Japanese, Russian, Simplified Chinese, Traditional Chinese). The parseCustomTemplate function was refactored to accept both JSON strings and direct objects, with its Zod schema updated to reflect this change. Correspondingly, the UI's parseHeadersJson and a new parseTemplateJson function now leverage these new i18n messages for improved error feedback. Additionally, several action functions and related hooks were refactored to consistently use a standardized ActionResult type for their return values, replacing success with ok and explicitly typing promises for better type safety. A logging statement was also updated to use a dedicated logger, and a test comment was clarified.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/app/api/actions/[...route]/route.ts (1)
907-915: Webhook 目标创建的 customTemplate 入参兼容 string 与对象
WebhookTargetCreateSchema的customTemplate改为z.union([z.string().trim(), z.record(z.string(), z.unknown())]).optional().nullable(),这与服务端CustomTemplateSchema/parseCustomTemplate的设计一致,既支持 API 客户端直接传对象,也兼容前端以 JSON 字符串形式提交,方便后续逐步统一为 JSON 对象形态。目前 schema 在 route 与 actions 中分别定义,未来如果有需要可以考虑在 actions 中导出公共 schema 以减少重复定义、避免演进时两处形状不一致的风险。
src/actions/notifications.ts (1)
14-61: 统一使用 ActionResult 返回通知设置更新结果
updateNotificationSettingsAction改为返回Promise<ActionResult<NotificationSettings>>,并在鉴权失败、更新异常等路径上统一返回{ ok: false, error },成功则返回{ ok: true, data },这与其他 admin actions 以及 API 文档说明的响应格式完全对齐,有利于前端复用同一套处理逻辑。可以考虑在
catch分支里补充一条logger.error日志(类似 webhook-targets actions 的做法),方便排查更新失败时的具体原因,但这属可选增强,不影响当前功能正确性。src/actions/webhook-targets.ts (1)
28-49: parseCustomTemplate 支持 string 与对象,但可考虑统一 JSON 解析报错信息当前
parseCustomTemplate:
- 接受
unknown,对null/undefined返回null;- 对 string:trim 后若为空返回
null,否则直接JSON.parse,再校验必须为“非数组对象”,否则抛出"自定义模板必须是 JSON 对象";- 对对象:若非数组则直接视为合法模板;
- 其他类型抛出同样的错误。
这样可以很好地兼容:
- API 客户端直接传 JSON 对象;
- 前端传 JSON 字符串(由 route schema 校验为 string)。
小建议:可以在
JSON.parse外包一层 try/catch,把语法错误也统一转换为"自定义模板必须是 JSON 对象",避免向调用方暴露底层SyntaxError文案,同时与形状校验失败时的错误消息保持一致:let parsed: unknown; try { parsed = JSON.parse(trimmed); } catch { throw new Error("自定义模板必须是 JSON 对象"); }这属于体验改进,不影响当前逻辑正确性,因为外层 action 已有 try/catch 包装。
src/app/[locale]/settings/notifications/_lib/hooks.ts (1)
171-227: updateSettings 统一构造 payload 并直接消费 ActionResult
updateSettings现在:
- 通过
type UpdatePayload = Parameters<typeof updateNotificationSettingsAction>[0];自动对齐后端UpdateNotificationSettingsInput形状,减少手写类型漂移的风险;- 仅在 patch 中字段存在时才写入 payload,避免无意义的覆盖;
- 对 Webhook URL 做
trim()并把空字符串归一为null,与后端存储类型兼容;- 把
costAlertThreshold从 number 转为 string 传递给后端,符合仓储层string | null约定;- 直接使用
updateNotificationSettingsAction的{ ok, data, error }返回值,失败路径返回自定义的ClientActionResult<void>,成功时用返回的最新配置更新本地settings。这让前端与后端的更新契约非常清晰,避免多处零散的字段更新调用。
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to Reviews > Disable Cache setting
📒 Files selected for processing (12)
messages/en/settings.jsonmessages/ja/settings.jsonmessages/ru/settings.jsonmessages/zh-CN/settings.jsonmessages/zh-TW/settings.jsonsrc/actions/notifications.tssrc/actions/webhook-targets.tssrc/app/[locale]/dashboard/_components/webhook-migration-dialog.tsxsrc/app/[locale]/settings/notifications/_components/webhook-target-dialog.tsxsrc/app/[locale]/settings/notifications/_lib/hooks.tssrc/app/api/actions/[...route]/route.tstests/unit/actions/internal-url-allowed.test.ts
🧰 Additional context used
📓 Path-based instructions (14)
**/*.{ts,tsx,js,jsx,json}
📄 CodeRabbit inference engine (CLAUDE.md)
Use 2-space indentation in all code files
Files:
tests/unit/actions/internal-url-allowed.test.tssrc/app/[locale]/dashboard/_components/webhook-migration-dialog.tsxmessages/zh-CN/settings.jsonmessages/en/settings.jsonmessages/ru/settings.jsonsrc/actions/webhook-targets.tssrc/actions/notifications.tsmessages/ja/settings.jsonmessages/zh-TW/settings.jsonsrc/app/[locale]/settings/notifications/_components/webhook-target-dialog.tsxsrc/app/api/actions/[...route]/route.tssrc/app/[locale]/settings/notifications/_lib/hooks.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{ts,tsx,js,jsx}: Use double quotes for strings instead of single quotes
Use trailing commas in multi-line structures
Enforce maximum line length of 100 characters
Use path alias@/*to reference files from./src/*directory
**/*.{ts,tsx,js,jsx}: Use Biome for linting and formatting with 2-space indent, double quotes, trailing commas, and 100 character max line length
Use path alias@/*to reference files in./src/*directory
Files:
tests/unit/actions/internal-url-allowed.test.tssrc/app/[locale]/dashboard/_components/webhook-migration-dialog.tsxsrc/actions/webhook-targets.tssrc/actions/notifications.tssrc/app/[locale]/settings/notifications/_components/webhook-target-dialog.tsxsrc/app/api/actions/[...route]/route.tssrc/app/[locale]/settings/notifications/_lib/hooks.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx}: Use TypeScript strict mode for type safety
Use readonly or const assertions for immutable data structures
Files:
tests/unit/actions/internal-url-allowed.test.tssrc/app/[locale]/dashboard/_components/webhook-migration-dialog.tsxsrc/actions/webhook-targets.tssrc/actions/notifications.tssrc/app/[locale]/settings/notifications/_components/webhook-target-dialog.tsxsrc/app/api/actions/[...route]/route.tssrc/app/[locale]/settings/notifications/_lib/hooks.ts
**/*.test.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use Vitest for unit testing with Node environment, coverage thresholds: 50% lines/functions, 40% branches
Files:
tests/unit/actions/internal-url-allowed.test.ts
**/*.test.ts
📄 CodeRabbit inference engine (AGENTS.md)
Ensure test database names contain 'test' keyword for safety validation
Files:
tests/unit/actions/internal-url-allowed.test.ts
src/**/*.{tsx,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
src/**/*.{tsx,jsx}: Uselucide-reactfor icons, no custom SVGs
Use React's automatic escaping to prevent XSS vulnerabilities
Files:
src/app/[locale]/dashboard/_components/webhook-migration-dialog.tsxsrc/app/[locale]/settings/notifications/_components/webhook-target-dialog.tsx
**/*.{tsx,json}
📄 CodeRabbit inference engine (AGENTS.md)
Use next-intl for internationalization with 5 locales: en, ja, ru, zh-CN, zh-TW
Files:
src/app/[locale]/dashboard/_components/webhook-migration-dialog.tsxmessages/zh-CN/settings.jsonmessages/en/settings.jsonmessages/ru/settings.jsonmessages/ja/settings.jsonmessages/zh-TW/settings.jsonsrc/app/[locale]/settings/notifications/_components/webhook-target-dialog.tsx
messages/**/*.json
📄 CodeRabbit inference engine (CLAUDE.md)
Support 5 locales via next-intl: en, ja, ru, zh-CN, zh-TW with messages in
messages/{locale}/*.jsonStore message translations in
messages/{locale}/*.jsonfiles
Files:
messages/zh-CN/settings.jsonmessages/en/settings.jsonmessages/ru/settings.jsonmessages/ja/settings.jsonmessages/zh-TW/settings.json
src/actions/**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
src/actions/**/*.ts: Validate all user inputs with Zod schemas before processing
Use Server Actions innext-safe-actionwith OpenAPI generation for admin API endpoints
Use Next.js API Routes and Server Actions for admin operations and REST endpoints
Files:
src/actions/webhook-targets.tssrc/actions/notifications.ts
src/**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
src/**/*.ts: Hash API keys using SHA-256 before storing in database, never store plaintext keys
Mask API keys and sensitive data in application logs
Validate required environment variables at startup with clear error messages
Files:
src/actions/webhook-targets.tssrc/actions/notifications.tssrc/app/api/actions/[...route]/route.tssrc/app/[locale]/settings/notifications/_lib/hooks.ts
src/{repository,actions}/**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
Avoid N+1 queries by using eager loading and batch queries for statistics
Files:
src/actions/webhook-targets.tssrc/actions/notifications.ts
src/app/api/actions/**/*.ts
📄 CodeRabbit inference engine (CLAUDE.md)
Server Actions in
src/app/api/actions/must auto-generate OpenAPI 3.1.0 spec from Zod schemas and expose as REST endpoints
Files:
src/app/api/actions/[...route]/route.ts
src/app/**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
Implement Content-Security-Policy headers for XSS prevention
Files:
src/app/api/actions/[...route]/route.tssrc/app/[locale]/settings/notifications/_lib/hooks.ts
src/app/api/**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
Implement health check endpoint returning database and Redis status
Files:
src/app/api/actions/[...route]/route.ts
🧠 Learnings (5)
📚 Learning: 2026-01-03T09:08:49.019Z
Learnt from: CR
Repo: ding113/claude-code-hub PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-03T09:08:49.019Z
Learning: Applies to src/components/**/*.{tsx,jsx} : Use shadcn/ui component library for high-quality, accessible UI components
Applied to files:
src/app/[locale]/dashboard/_components/webhook-migration-dialog.tsx
📚 Learning: 2026-01-03T09:08:20.573Z
Learnt from: CR
Repo: ding113/claude-code-hub PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-03T09:08:20.573Z
Learning: Applies to messages/**/*.json : Support 5 locales via next-intl: en, ja, ru, zh-CN, zh-TW with messages in `messages/{locale}/*.json`
Applied to files:
messages/zh-CN/settings.jsonmessages/en/settings.jsonmessages/ru/settings.jsonmessages/ja/settings.jsonmessages/zh-TW/settings.jsonsrc/app/[locale]/settings/notifications/_components/webhook-target-dialog.tsx
📚 Learning: 2026-01-03T09:08:49.019Z
Learnt from: CR
Repo: ding113/claude-code-hub PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-03T09:08:49.019Z
Learning: Applies to src/actions/**/*.ts : Validate all user inputs with Zod schemas before processing
Applied to files:
src/actions/webhook-targets.ts
📚 Learning: 2026-01-03T09:08:49.019Z
Learnt from: CR
Repo: ding113/claude-code-hub PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-03T09:08:49.019Z
Learning: Applies to src/actions/**/*.ts : Use Server Actions in `next-safe-action` with OpenAPI generation for admin API endpoints
Applied to files:
src/actions/notifications.tssrc/app/api/actions/[...route]/route.ts
📚 Learning: 2026-01-03T09:08:49.019Z
Learnt from: CR
Repo: ding113/claude-code-hub PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-03T09:08:49.019Z
Learning: Applies to src/actions/**/*.ts : Use Next.js API Routes and Server Actions for admin operations and REST endpoints
Applied to files:
src/app/api/actions/[...route]/route.ts
🧬 Code graph analysis (3)
src/app/[locale]/dashboard/_components/webhook-migration-dialog.tsx (1)
src/lib/logger.ts (1)
logger(168-187)
src/actions/notifications.ts (3)
src/actions/types.ts (1)
ActionResult(31-31)src/repository/notifications.ts (1)
NotificationSettings(11-34)src/lib/auth.ts (1)
getSession(116-128)
src/app/[locale]/settings/notifications/_lib/hooks.ts (4)
src/actions/notifications.ts (1)
updateNotificationSettingsAction(30-61)src/actions/webhook-targets.ts (4)
updateWebhookTargetAction(322-347)deleteWebhookTargetAction(349-363)NotificationType(79-79)testWebhookTargetAction(365-422)src/app/[locale]/settings/notifications/_lib/schemas.ts (1)
NotificationType(10-10)src/repository/notification-bindings.ts (1)
NotificationType(8-8)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: Greptile Review
- GitHub Check: pr-review
- GitHub Check: 🌐 API Tests
- GitHub Check: pr-label
- GitHub Check: pr-description
- GitHub Check: check-codex-status
- GitHub Check: Docker Build Test
- GitHub Check: dev-build-deploy
🔇 Additional comments (12)
tests/unit/actions/internal-url-allowed.test.ts (1)
39-46: 测试意图注释补充得当这条注释准确说明了用例关注的是“输入层允许内网 IP,但 provider 层因 hostname 不支持而失败”,方便后续维护理解测试语义,建议保留。
messages/zh-CN/settings.json (1)
1679-1685: 自定义 Headers 校验文案与多语言结构一致新增的
headersInvalidJson/headersMustBeObject/headersValueMustBeString语义清晰,位置在notifications.targetDialog.errors下也与其它 locale 对齐,有利于前端统一使用t("notifications.targetDialog.errors.*")进行提示。src/app/[locale]/dashboard/_components/webhook-migration-dialog.tsx (1)
25-27: 迁移到统一 logger 的改动合理将
console.warn替换为logger.warn并引入统一日志封装,既保持了“获取设置失败不阻塞用户”的语义,又让错误出现在集中日志通道中,符合集中化观测的方向。Also applies to: 137-140
messages/ja/settings.json (1)
423-427: Headers 校验日文文案与键结构正确
headersInvalidJson/headersMustBeObject/headersValueMustBeString的翻译准确表达了 JSON 解析与类型要求,且放在notifications.targetDialog.errors下,方便与其他语言保持一一对应。messages/zh-TW/settings.json (1)
423-427: 繁体 Headers 校验文案与其它语言对齐新增的三条錯誤訊息鍵名和語義均與其他語言版本一致,放置在
notifications.targetDialog.errors下也符合既有結構,方便前端統一使用與回退。messages/en/settings.json (1)
432-436: 自定义 Headers 错误文案与前端校验逻辑已对齐新增的
notifications.targetDialog.errors.*三个 key 与前端parseHeadersJson中使用的 key 完全一致,英文描述准确清晰,能覆盖 JSON 不合法 / 非对象 / value 非字符串三类错误场景,没有发现命名或含义问题。messages/ru/settings.json (1)
423-427: 俄文 Headers 错误文案与英文版语义一致
headersInvalidJson/headersMustBeObject/headersValueMustBeString三个俄文翻译与英文含义一致,能清楚区分 JSON 解析失败、结构不是对象以及 value 不是字符串三种情况,满足多语言一致性要求。src/app/api/actions/[...route]/route.ts (1)
790-841: 通知设置路由直接复用 ActionResult 风格的服务端 Action这里直接把
notificationActions.updateNotificationSettingsAction作为createActionRoute的执行函数,去掉了之前多余的包装层,统一使用{ ok, data, error }约定,和前端 hooks 以及其他通知相关 action 的返回结构保持一致,没有发现权限或类型上的问题。src/app/[locale]/settings/notifications/_components/webhook-target-dialog.tsx (1)
70-91: 本地 JSON 解析与 i18n 错误消息集成良好
parseTemplateJson:对空字符串直接返回null,非空时做JSON.parse并校验为“非数组对象”,错误统一抛出notifications.templateEditor.jsonInvalid,与已有文案 key 保持一致。parseHeadersJson:细分三类错误:
- 解析失败 →
notifications.targetDialog.errors.headersInvalidJson- 非对象 / 数组 →
...headersMustBeObject- value 非字符串 →
...headersValueMustBeString
与新加的 messages 中 key 完全一致,避免在组件里硬编码英文文案。submit中 payload 构造:
customTemplate仅在providerType === "custom"时使用parseTemplateJson得到Record<string, unknown> | null,与后端新的customTemplate类型对齐。customHeaders始终通过parseHeadersJson归一为Record<string, string> | null,在前端就能拦截形状错误,减少后端 400。整体上 JSON 校验责任前移到前端,并结合 i18n key 提供了清晰的错误提示,实现合理。
Also applies to: 93-121, 195-198
src/actions/webhook-targets.ts (1)
81-95: customTemplate 端到端类型统一与规范化逻辑合理
CustomTemplateSchema定义为string.trim() | record<string, unknown>,并在BaseTargetSchema.customTemplate中使用,确保:
- HTTP 层(route)和 server action 层(这里)对
customTemplate的形状约束一致;- 不会出现数组或其他基本类型混入。
normalizeTargetInput/normalizeTargetUpdateInput:
- 对
providerType === "custom"时统一通过parseCustomTemplate归一为Record<string, unknown> | null;- 使用两次
validateProviderConfig,第二次在providerType === "custom"时附带customTemplate,强制自定义 Webhook 必须配置模板(否则抛"自定义 Webhook 需要配置模板"),业务规则清晰;- 其它 providerType 分支合理设置
webhookUrl/telegramBotToken/dingtalkSecret/customHeaders的互斥和归一化(如 Telegram 忽略 webhookUrl,自定义 provider 才保留 customHeaders)。整体类型和归一化逻辑前后端一致,满足 PR 目标“customTemplate 在前后端统一为 JSON 对象(Record),server action 兼容 string 与 object 输入”的要求。
Also applies to: 105-157, 159-233
src/app/[locale]/settings/notifications/_lib/hooks.ts (2)
65-77: WebhookTargetCreateInput 的 customTemplate 类型与后端保持一致
WebhookTargetCreateInput.customTemplate从 string 变更为Record<string, unknown> | null,与:
- 前端
WebhookTargetDialog中parseTemplateJson的返回值;- 后端
normalizeTargetInput/WebhookTarget的customTemplate: Record<string, unknown> | null;保持一致,避免再把原始 JSON 字符串透传到 server action,有利于在前端统一完成 JSON 解析与错误提示。
251-307: 目标 CRUD / 测试回调现在直接透传 ClientActionResult
createTarget/updateTarget/deleteTarget/testTarget统一返回底层 action 的ClientActionResult<T>,并在ok时按需刷新:
createTarget:刷新 targets、所有 bindings 以及 settings,确保刚创建的目标和自动切换模式(legacy → 多目标)立刻反映在 UI 中。updateTarget/deleteTarget:刷新 targets 和所有 bindings,避免绑定列表与目标列表状态不一致。testTarget:在测试成功时刷新 targets,使lastTestResult/lastTestAt即时更新。这简化了调用方的错误判断逻辑(统一判断
ok),同时保证本地状态与服务端保持同步。
There was a problem hiding this comment.
Code Review Summary
No significant issues identified in this PR.
PR Size: M
- Lines changed: 258
- Files changed: 12
Review Coverage
- Logic and correctness - Clean
- Security (OWASP Top 10) - Clean
- Error handling - Clean
- Type safety - Clean
- Documentation accuracy - Clean
- Test coverage - Adequate
- Code clarity - Good
Automated review by Codex AI
There was a problem hiding this comment.
- Reviewed PR
#527(fix: 修复 CodeRabbit webhook 反馈) across the 12 changed files and the full diff. - Applied the size label
size/M(258 lines changed; 12 files). - Submitted a PR review comment with the “No significant issues identified in this PR” summary.
- No inline review comments were posted because no diff-line issues met the ≥80 confidence threshold.
There was a problem hiding this comment.
Code Review Summary
This PR successfully addresses code quality feedback from CodeRabbit reviews, focusing on type safety, i18n consistency, and logging standardization. After comprehensive analysis across all 6 review perspectives, no significant issues were identified.
PR Size: M
- Lines changed: 258 (167 additions + 91 deletions)
- Files changed: 12
Review Coverage
All changes have been validated against the following criteria:
- Logic and correctness - Clean. Type unification properly maintains backward compatibility.
- Security (OWASP Top 10) - Clean. No security vulnerabilities introduced.
- Error handling - Clean. All JSON.parse calls are properly wrapped in try-catch blocks with i18n error messages.
- Type safety - Improved. Successfully removed
as anytype assertion, unifiedActionResult<T>return types, and added flexiblestring | Recordsupport for customTemplate. - Documentation accuracy - Improved. Added test intent comment as requested.
- i18n consistency - Improved. Replaced hardcoded error messages with translation keys across 5 locales.
- Code clarity - Improved. Removed type assertions and simplified payload building in hooks.ts.
Analysis Details
Type Safety Improvements (src/actions/notifications.ts, src/app/[locale]/settings/notifications/_lib/hooks.ts):
- ✅ Return type unified from
{ success: boolean, data?, error? }toActionResult<T> - ✅ Removed
as anytype assertion in updateSettings callback - ✅ Properly typed payload construction instead of spreading with type assertion
i18n Consistency (webhook-target-dialog.tsx, messages/*/settings.json):
- ✅ parseHeadersJson and parseTemplateJson now accept translation function
- ✅ JSON parse errors properly wrapped in try-catch with i18n keys
- ✅ All 5 locales updated consistently
Type Flexibility (src/actions/webhook-targets.ts):
- ✅ parseCustomTemplate now handles both
string | Record<string, unknown>inputs - ✅ Validation logic properly handles all input types
- ✅ Backward compatible with existing string inputs
Logging Standardization (webhook-migration-dialog.tsx):
- ✅ Replaced console.warn with unified logger.warn() with structured logging
Error Handling Validation:
- ✅ All JSON.parse calls are wrapped in try-catch blocks
- ✅ Error messages are properly localized
- ✅ User feedback provided through toast notifications
- ✅ No silent failures identified
Automated review by Claude AI - No issues found
Summary
This PR addresses code quality feedback from CodeRabbit reviews on recent webhook-related PRs, focusing on type safety, i18n consistency, and test documentation.
Related PRs:
Problem
CodeRabbit identified several code quality and consistency issues in the recent webhook feature implementation:
console.warninstead of unified loggeras anyand inconsistent return typescustomTemplatehad frontend/backend type inconsistency (string vs Record)Solution
Fixes Applied
console.warnwith unifiedlogger.warn()webhook-migration-dialog.tsxwebhook-target-dialog.tsx,messages/*/settings.jsonas any, unifyupdateNotificationSettingsActionto returnActionResult<T>notifications.ts,route.ts,hooks.tscustomTemplateaccept bothstring | Record<string, unknown>in server actionwebhook-targets.ts,route.tsinternal-url-allowed.test.tsNew i18n Keys
Added to all 5 locales (en/ja/ru/zh-CN/zh-TW):
Type Safety Improvements
Before:
After:
Changes
Core Changes
src/actions/notifications.ts- Unify return type toActionResult<NotificationSettings>src/actions/webhook-targets.ts- Support both string and object forcustomTemplatesrc/app/[locale]/settings/notifications/_lib/hooks.ts- Removeas any, properly type all callbacksSupporting Changes
messages/*/settings.json(5 files) - Adderrorssection for webhook target validationsrc/app/[locale]/dashboard/_components/webhook-migration-dialog.tsx- Use unified loggersrc/app/[locale]/settings/notifications/_components/webhook-target-dialog.tsx- Use i18n for errorssrc/app/api/actions/[...route]/route.ts- Update schema to acceptstring | Recordfor customTemplatetests/unit/actions/internal-url-allowed.test.ts- Add test intent commentTesting
Validation
Coverage Improvement
Checklist
as any)Original Description (Chinese)
修复点:
验证:bun run lint/typecheck/test/build/test --coverage
覆盖率:All files(Stmts/Branch/Funcs/Lines)由 64.97/51.00/59.80/65.81 提升到 65.03/51.14/59.95/65.88
Description enhanced by Claude AI