-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[FEATURE] Include Column Names in Google Sheets Webhook Responses #18327
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
[FEATURE] Include Column Names in Google Sheets Webhook Responses #18327
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
WalkthroughAdds optional header-aware processing to the Google Sheets “new row” trigger: introduces Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Pre-merge checks (4 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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. Comment |
971f00e to
a56bac7
Compare
a56bac7 to
139d542
Compare
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: 3
🧹 Nitpick comments (4)
components/google_sheets/sources/common/new-row-added.mjs (4)
45-50: Return an array from_getHeadersto match downstream expectations.This method returns
{}when no cache exists, but consumers check.lengthand may treat headers as an array later. Return[]instead to keep types consistent and avoid accidental.reduce/.maperrors.- _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 underheaders_${worksheetId}can serve stale headers. IncludesheetIdandheaderRowin 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 headersso 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
📒 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
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!
WHY
Resolves #18278
Summary by CodeRabbit
New Features
Tests
Chores