Skip to content

✨ add replace_or_create_from_records, list_worksheets, delete_worksheet#29

Merged
rafaelleinio merged 2 commits into
mainfrom
AGE-298
Jul 20, 2026
Merged

✨ add replace_or_create_from_records, list_worksheets, delete_worksheet#29
rafaelleinio merged 2 commits into
mainfrom
AGE-298

Conversation

@rafaelleinio

@rafaelleinio rafaelleinio commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Note

Low Risk
Additive API and tests only; delete_worksheet can remove remote tabs but behavior is explicit and documented.

Overview
Extends the Google Sheets client with worksheet lifecycle operations beyond the existing replace_from_records path (which still requires the tab to exist).

replace_or_create_from_records opens the spreadsheet, creates the named worksheet when WorksheetNotFound is raised (sized with min_rows and data length), otherwise resizes rows/cols as needed, then clears and writes header + records like replace_from_records—and returns the Worksheet (e.g. for its URL).

list_worksheets returns all Worksheet objects for a document via _open_document. delete_worksheet resolves the tab by name and calls del_worksheet (missing names still surface WorksheetNotFound).

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.

@rafaelleinio rafaelleinio self-assigned this Jul 20, 2026
@github-actions github-actions Bot added the feature New feature or request label Jul 20, 2026

@adaptcom adaptcom Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Re-run review · View in Adapt

Comment thread gcpde/sheets.py Outdated
def replace_or_create_from_records(
document_id: str,
sheet_name: str,
records: list[dict[str, Any]],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use the existing ListJsonType alias (identical to list[dict[str, Any]]) to stay consistent with replace_from_records.

Comment thread gcpde/sheets.py Outdated
cols=len(columns),
)

worksheet.resize(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

resize() also runs right after add_worksheet already sized the sheet, costing a redundant no-op API call; skip it on the create path.

@rafaelleinio
rafaelleinio merged commit 179cec9 into main Jul 20, 2026
4 checks passed
@rafaelleinio
rafaelleinio deleted the AGE-298 branch July 20, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Development

Successfully merging this pull request may close these issues.

1 participant