Skip to content

Conversation

GTFalcao
Copy link
Collaborator

@GTFalcao GTFalcao commented Sep 3, 2025

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

    • Comment events now include associated ticket details with each comment, and optional comment "value" fields are preserved for richer context in downstream workflows and integrations.
  • Chores

    • Version updates to reflect the latest enhancements.

Copy link

vercel bot commented Sep 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
pipedream-docs Ignored Ignored Sep 6, 2025 4:55am
pipedream-docs-redirect-do-not-edit Ignored Ignored Sep 6, 2025 4:55am

Copy link
Contributor

coderabbitai bot commented Sep 3, 2025

Walkthrough

Bumps 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 ticketData property. Exported source version incremented.

Changes

Cohort / File(s) Summary
Zendesk component versioning
components/zendesk/package.json
Version updated from 0.8.20.9.0.
Zendesk new-ticket-comment-added source
components/zendesk/sources/new-ticket-comment-added/new-ticket-comment-added.mjs
Exported version bumped 0.0.20.1.0. convertCommentsToJson regex extended to capture an optional value field and include it in parsed comment objects; emitEvent(payload) now destructures { ticketComments, ...ticketData }, iterates comments, and emits { ...comment, ticketData } with the same metadata shape as before.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Emit full, non-truncated comment value field (#18260)
Emit complete ticket comment data including correct ticket_id from body.ticketId (#18260) The code merges remaining payload into ticketData but does not map ticketData.ticketId to the top-level ticket_id expected by the issue.
Properly parse all relevant fields from webhook payload into emitted event (#18260) Comment parsing now captures an explicit value field, but it's unclear whether all other fields (and normalization of ticket ID) are consistently mapped to the exact keys consumers expect.

Assessment against linked issues: Out-of-scope changes

(No out-of-scope functional changes detected.)

"I nibble strings and stitch them right,\n> Values whole and ticket data tight.\n> Each comment hops into a bundled frame,\n> Merged with context — that’s my game.\n> Hooray, I thump: the webhook’s bright!" 🐇✨


📜 Recent 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.

📥 Commits

Reviewing files that changed from the base of the PR and between fbd6561 and e03fd3b.

📒 Files selected for processing (1)
  • components/zendesk/sources/new-ticket-comment-added/new-ticket-comment-added.mjs (4 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: Publish TypeScript components
  • GitHub Check: Lint Code Base
  • GitHub Check: Verify TypeScript components
🔇 Additional comments (3)
components/zendesk/sources/new-ticket-comment-added/new-ticket-comment-added.mjs (3)

10-10: Version bump looks good

Minor version bump aligns with an additive payload change (new ticketData). No concerns.


113-116: ticketData merge is good and additive

Spreading remaining payload into ticketData and emitting alongside each comment meets the PR goal without breaking existing consumers that rely on top-level comment fields.


117-126: Harden ts/id generation and sanitize summary

  • Guard against invalid dates and fall back to the trigger’s updatedAt timestamp:
    const parsed = Date.parse(comment.created_at);
    const ts = Number.isFinite(parsed) ? parsed : Number(payload.updatedAt);
  • Derive ticketId from ticketData if available, then build id:
    const ticketId = ticketData.ticketId ?? payload.ticketId;
    const id = `${ticketId}-${ts}`;
  • Normalize summary to a plain string to strip quotes/commas or handle non-string values:
    const summary =
      typeof comment.value === "string"
        ? comment.value
        : String(comment.value ?? "New ticket comment");
  • Please confirm that payload.ticketId corresponds to the user-facing ticket ID in your environment.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 18260-zendesk-adjustment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 56c6ec0 and fbd6561.

⛔ 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.

michelle0927
michelle0927 previously approved these changes Sep 4, 2025
Copy link
Collaborator

@michelle0927 michelle0927 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@GTFalcao
Copy link
Collaborator Author

GTFalcao commented Sep 6, 2025

/approve

@michelle0927 michelle0927 merged commit db457a5 into master Sep 9, 2025
10 checks passed
@michelle0927 michelle0927 deleted the 18260-zendesk-adjustment branch September 9, 2025 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] zendesk-new-ticket-comment-added returns incomplete data

2 participants