Skip to content

Conversation

@jcortes
Copy link
Collaborator

@jcortes jcortes commented Sep 9, 2025

WHY

Resolves #18278

Summary by CodeRabbit

  • New Features

    • Option to treat sheets as headered so new rows are emitted as objects keyed by column headers.
    • Configurable header row index (default: 1); when disabled, behavior unchanged.
    • Per-worksheet header caching to avoid repeated header reads.
  • Tests

    • Updated sample test event to demonstrate header-based output and adjusted range/row.
  • Chores

    • Bumped component and source package versions.

@jcortes jcortes self-assigned this Sep 9, 2025
@vercel
Copy link

vercel bot commented Sep 9, 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 9, 2025 9:39pm
pipedream-docs-redirect-do-not-edit Ignored Ignored Sep 9, 2025 9:39pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 9, 2025

Walkthrough

Adds optional header-aware processing to the Google Sheets “new row” trigger: introduces hasHeaders and headerRow props, per-worksheet header caching/fetching, a row-array → object transformer keyed by column headers, integrates header retrieval into processing, plus version and test-event updates.

Changes

Cohort / File(s) Summary
Header-based row transformation
components/google_sheets/sources/common/new-row-added.mjs
Adds hasHeaders (bool) and headerRow (int) props; implements per-worksheet header cache (_getHeaders, _setHeaders); header fetching (_fetchHeaders, _getOrFetchHeaders); row→object transformer (_transformRowToObject); integrates header retrieval and uses transformed rows when enabled.
Source version bump
components/google_sheets/sources/new-row-added/new-row-added.mjs
Bumped exported source version from 0.1.140.1.15.
Package version bump
components/google_sheets/package.json
Bumped package version from 0.8.70.8.8.
Test event update
components/google_sheets/sources/new-row-added/test-event.mjs
Example payload changed: newRow now an object (Name, Email, Age); range narrowed to Sheet1!2:2; rowNumber updated to 2.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User as User
  participant Trigger as New Row Trigger
  participant Sheets as Google Sheets API
  participant DB as Header Cache

  User->>Trigger: Configure trigger (hasHeaders?, headerRow)
  Trigger->>Sheets: List new rows (range)
  alt hasHeaders = true
    Trigger->>DB: get headers for worksheetId
    alt cache miss
      Trigger->>Sheets: fetch header row (headerRow)
      Sheets-->>Trigger: header values
      Trigger->>DB: store headers
    else cache hit
      DB-->>Trigger: header values
    end
    loop for each new row
      Trigger->>Trigger: transform row[] → {header: value}
      Trigger-->>User: emit event { newRow: object }
    end
  else hasHeaders = false
    loop for each new row
      Trigger-->>User: emit event { newRow: array }
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

"A rabbit hops with headers bright,
I fetch the names and set them right.
Rows once arrays, now labeled fair,
Carrot-keyed objects everywhere! 🥕"

Pre-merge checks (4 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description only includes “Resolves #18278” under the WHY heading without any actual motivation or context, so it does not meet the repository template’s requirement to explain the rationale for the change. Please expand the WHY section with a clear explanation of the problem the feature addresses and the benefit of including column names in webhook responses.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed This title succinctly describes the primary change—adding column names to Google Sheets webhook responses—and directly aligns with the feature objective of issue #18278, making it clear and specific for future readers.
Linked Issues Check ✅ Passed The changes implement header‐based transformation of new rows into key‐value objects by adding hasHeaders/headerRow configuration, fetching and caching column headers, and mapping row arrays to objects when enabled, which directly fulfills the issue requirement to replace positional arrays with header‐keyed responses (#18278).
Out of Scope Changes Check ✅ Passed All changes—header transformation logic, test‐event adjustments, and metadata version bumps—directly support the implementation and release of header‐keyed webhook responses and do not introduce unrelated functionality.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch google-sheets-include-column-names-webhook-responses

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@jcortes jcortes force-pushed the google-sheets-include-column-names-webhook-responses branch from 971f00e to a56bac7 Compare September 9, 2025 21:30
@jcortes jcortes force-pushed the google-sheets-include-column-names-webhook-responses branch from a56bac7 to 139d542 Compare September 9, 2025 21:39
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: 3

🧹 Nitpick comments (4)
components/google_sheets/sources/common/new-row-added.mjs (4)

45-50: Return an array from _getHeaders to match downstream expectations.

This method returns {} when no cache exists, but consumers check .length and may treat headers as an array later. Return [] instead to keep types consistent and avoid accidental .reduce/.map errors.

-    _getHeaders(worksheetId) {
-      return this.db.get(`headers_${worksheetId}`) || {};
-    },
+    _getHeaders(worksheetId) {
+      return this.db.get(`headers_${worksheetId}`) || [];
+    },

60-72: Make header cache key sensitive to worksheet + headerRow (and sheet).

If headers move (user changes headerRow) or vary per sheet/worksheet, the cache under headers_${worksheetId} can serve stale headers. Include sheetId and headerRow in the key to avoid wrong mappings.

-    _getHeaders(worksheetId) {
-      return this.db.get(`headers_${worksheetId}`) || [];
-    },
-    _setHeaders(worksheetId, headers) {
-      this.db.set(`headers_${worksheetId}`, headers);
-    },
+    _getHeaders(worksheetId, headerRow, sheetId) {
+      return this.db.get(`headers_${sheetId}_${worksheetId}_${headerRow}`) || [];
+    },
+    _setHeaders(worksheetId, headerRow, sheetId, headers) {
+      this.db.set(`headers_${sheetId}_${worksheetId}_${headerRow}`, headers);
+    },
-    async _getOrFetchHeaders(sheetId, worksheetId, worksheetTitle) {
+    async _getOrFetchHeaders(sheetId, worksheetId, worksheetTitle) {
       if (!this.hasHeaders) {
         return [];
       }
 
-      let headers = this._getHeaders(worksheetId);
+      const headerRow = Math.max(1, parseInt(this.headerRow, 10) || 1);
+      let headers = this._getHeaders(worksheetId, headerRow, sheetId);
       if (!headers.length) {
-        headers = await this._fetchHeaders(sheetId, worksheetTitle);
-        this._setHeaders(worksheetId, headers);
+        headers = await this._fetchHeaders(sheetId, worksheetTitle);
+        this._setHeaders(worksheetId, headerRow, sheetId, headers);
       }
 
       return headers;
     },

216-218: Allow revalidation of headers when row shape changes.

Switch to let headers so you can refresh headers if incoming rows exceed cached header count (columns added).

-        const headers = await this._getOrFetchHeaders(sheetId, worksheetId, worksheetTitle);
+        let headers = await this._getOrFetchHeaders(sheetId, worksheetId, worksheetTitle);

Then, inside the row loop, consider re-fetch on mismatch:

// inside the for-of over newRowValues.values
if (this.hasHeaders && newRow.length > headers.length) {
  const fresh = await this._fetchHeaders(sheetId, worksheetTitle);
  if (fresh.length && fresh.length !== headers.length) {
    this._setHeaders(worksheetId, Math.max(1, parseInt(this.headerRow, 10) || 1), sheetId, fresh);
    headers = fresh;
  }
}

235-241: Consider emitting both shapes for smoother adoption.

When headers are enabled, emitting both the object and the raw array eases migration and debugging without breaking current consumers.

           this.$emit(
             {
-              newRow: transformedRow,
+              newRow: transformedRow,
+              // Optional: keep raw array for compatibility / inspection
+              newRowArray: newRow,
               range,
               worksheet,
               rowNumber,
             },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a56bac7 and 139d542.

📒 Files selected for processing (5)
  • components/google_sheets/package.json (1 hunks)
  • components/google_sheets/sources/common/new-row-added.mjs (4 hunks)
  • components/google_sheets/sources/new-row-added-polling/new-row-added-polling.mjs (1 hunks)
  • components/google_sheets/sources/new-row-added/new-row-added.mjs (1 hunks)
  • components/google_sheets/sources/new-row-added/test-event.mjs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • components/google_sheets/sources/new-row-added-polling/new-row-added-polling.mjs
🚧 Files skipped from review as they are similar to previous changes (3)
  • components/google_sheets/package.json
  • components/google_sheets/sources/new-row-added/new-row-added.mjs
  • components/google_sheets/sources/new-row-added/test-event.mjs
⏰ 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). (3)
  • GitHub Check: Lint Code Base
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Verify TypeScript components

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!

@vunguyenhung vunguyenhung merged commit 7977501 into master Sep 11, 2025
10 checks passed
@vunguyenhung vunguyenhung deleted the google-sheets-include-column-names-webhook-responses branch September 11, 2025 05:52
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.

[FEATURE] Include Column Names in Google Sheets Webhook Responses

4 participants