✨ add replace_or_create_from_records, list_worksheets, delete_worksheet#29
Merged
Conversation
There was a problem hiding this comment.
Confidence Score: 4/5
Summary
Adds three additive Google Sheets helpers (replace-or-create worksheet, list, delete) with unit tests; all 11 unit tests pass locally. No existing behavior changed; risk is low.
Important Files Changed
| File | Overview |
|---|---|
| gcpde/sheets.py | New replace_or_create_from_records, list_worksheets, delete_worksheet helpers |
| tests/unit/test_sheets.py | Autospec-based unit tests covering the three new functions |
| def replace_or_create_from_records( | ||
| document_id: str, | ||
| sheet_name: str, | ||
| records: list[dict[str, Any]], |
There was a problem hiding this comment.
Use the existing ListJsonType alias (identical to list[dict[str, Any]]) to stay consistent with replace_from_records.
| cols=len(columns), | ||
| ) | ||
|
|
||
| worksheet.resize( |
There was a problem hiding this comment.
resize() also runs right after add_worksheet already sized the sheet, costing a redundant no-op API call; skip it on the create path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Low Risk
Additive API and tests only;
delete_worksheetcan remove remote tabs but behavior is explicit and documented.Overview
Extends the Google Sheets client with worksheet lifecycle operations beyond the existing
replace_from_recordspath (which still requires the tab to exist).replace_or_create_from_recordsopens the spreadsheet, creates the named worksheet whenWorksheetNotFoundis raised (sized withmin_rowsand data length), otherwise resizes rows/cols as needed, then clears and writes header + records likereplace_from_records—and returns theWorksheet(e.g. for its URL).list_worksheetsreturns allWorksheetobjects for a document via_open_document.delete_worksheetresolves the tab by name and callsdel_worksheet(missing names still surfaceWorksheetNotFound).Unit tests add shared spreadsheet/worksheet mocks and cover create-on-miss, list, and delete wiring through
_open_document.Reviewed by Cursor Bugbot for commit 91ad634. Bugbot is set up for automated code reviews on this repo. Configure here.