-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Zendesk - adding "ticketData" property to emitted comments #18266
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
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
WalkthroughBumps component version and updates the Zendesk new-ticket-comment-added source: parsing of raw comment strings now captures an explicit value field and builds comment objects; emitEvent iterates ticketComments and emits each comment merged with remaining ticket data under a Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Z as Zendesk Webhook
participant S as Source:new-ticket-comment-added
participant P as Parser (convertCommentsToJson)
participant E as Event Bus / Workflow
Z->>S: HTTP payload (body.ticketComments, body.ticketId, ...)
S->>P: parse raw ticketComments string
rect rgba(230,240,255,0.5)
P->>S: [{id, ... , value?}, ...] %% parsed comment objects, value captured if present
S->>S: destructure { ticketComments, ...ticketData }
loop for each comment
S->>E: $emit({ ...comment, ticketData }, { id, summary, ts })
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changes(No out-of-scope functional changes detected.)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)components/zendesk/sources/new-ticket-comment-added/new-ticket-comment-added.mjs (1)
⏰ 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). (4)
🔇 Additional comments (3)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
components/zendesk/sources/new-ticket-comment-added/new-ticket-comment-added.mjs (1)
60-86
: Bug: comma-based splitting truncates/garbles comment.value when it contains commas or escaped quotes.This parser breaks on real-world comments (e.g., “Hi, team — see details...”), undermining the PR goal to emit the full comment text. Parse key/value pairs with a regex that respects quoted strings and escapes.
Apply this diff:
- convertCommentsToJson(raw) { - return [ - ...raw.matchAll(/#<Comment (.*?)>/g), - ].map((match) => { - const fields = match[1] - .split(",") - .map((part) => part.trim()) - .map((pair) => { - const [ - key, - value, - ] = pair.split(/:\s+/); - // Clean up values: remove extra quotes or cast to appropriate types - let cleaned = value; - if (cleaned === "nil") cleaned = null; - else if (cleaned === "true") cleaned = true; - else if (cleaned === "false") cleaned = false; - else if (/^\d+$/.test(cleaned)) cleaned = parseInt(cleaned, 10); - else if (/^".*"$/.test(cleaned)) cleaned = cleaned.slice(1, -1); - return [ - key, - cleaned, - ]; - }); - return Object.fromEntries(fields); - }); - }, + convertCommentsToJson(raw) { + return [...raw.matchAll(/#<Comment\s+([^>]+)>/g)].map((match) => { + const obj = {}; + const pairs = match[1]; + // Match: key: "string with commas, \"quotes\"", key: 123, key: true, key: nil + const kvRe = /(\w+):\s+("(?:(?:\\.|[^"\\])*)"|nil|true|false|-?\d+)/g; + let m; + while ((m = kvRe.exec(pairs)) !== null) { + const key = m[1]; + let val = m[2]; + if (val === "nil") val = null; + else if (val === "true") val = true; + else if (val === "false") val = false; + else if (/^-?\d+$/.test(val)) val = parseInt(val, 10); + else { + // Properly unescape quoted strings + try { val = JSON.parse(val); } catch { val = val.slice(1, -1); } + } + obj[key] = val; + } + return obj; + }); + },
🧹 Nitpick comments (2)
components/zendesk/sources/new-ticket-comment-added/new-ticket-comment-added.mjs (2)
106-109
: Stabilize event id to prevent collisions across comments created in the same second.If two comments share the same created_at second,
${ticketId}-${ts}
can collide and dedupe may drop one. Prefer using the comment’s own id when present.Apply this diff:
- const id = `${payload.ticketId}-${ts}`; + const id = comment.id + ? `${payload.ticketId}-${comment.id}` + : `${payload.ticketId}-${ts}`;
98-115
: Verify user-facing ticketId and timestamp parsing.
- Confirm payload.ticketId corresponds to the UI ticket ID (e.g., “32”), not an internal 14+ digit ID, to satisfy the issue’s requirement.
- Date.parse(comment.created_at) may return NaN depending on format. Consider a fallback to payload.updatedAt or guard against NaN when building id/ts.
Apply this defensive tweak if needed:
- const ts = Date.parse(comment.created_at); + const parsed = Date.parse(comment.created_at); + const ts = Number.isFinite(parsed) ? parsed : Date.parse(payload.updatedAt);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
components/zendesk/package.json
(1 hunks)components/zendesk/sources/new-ticket-comment-added/new-ticket-comment-added.mjs
(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
components/zendesk/sources/new-ticket-comment-added/new-ticket-comment-added.mjs (1)
components/zendesk/sources/common/webhook.mjs (3)
payload
(226-230)ts
(216-216)id
(217-217)
⏰ 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). (4)
- GitHub Check: pnpm publish
- GitHub Check: Verify TypeScript components
- GitHub Check: Publish TypeScript components
- GitHub Check: Lint Code Base
🔇 Additional comments (3)
components/zendesk/package.json (1)
3-3
: Semver bump aligns with additive change.Minor package bump to 0.9.0 matches the source’s new feature (added event payload field). LGTM.
components/zendesk/sources/new-ticket-comment-added/new-ticket-comment-added.mjs (2)
10-10
: Source version bump is appropriate.0.1.0 correctly reflects the added ticketData field in emitted events.
100-103
: Good: isolate ticketData and avoid duplicating comments array.Destructuring out ticketComments and bundling the rest under ticketData is clean and backward-compatible with existing comment fields.
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.
LGTM
/approve |
Closes #18260
This adds the remaining payload as a ticketData key to the original payload (thus not affecting existing workflows), and also fixes a number of issues that arised from the parsing of the unusual format the Zendesk webhook sends comments in.
I've added and tweaked RegExps to handle this. Edge cases included comments with commas, brackets and semicolons, which could be emitted with incomplete text content, missing properties, or not emitted at all.
Summary by CodeRabbit
New Features
Chores