feat: Add support for all block types - #3
Conversation
Add new 'blocks' subcommand for working with all Notion block types while maintaining backward compatibility with existing to-do commands. New commands: - notioncli blocks list List all blocks on the page - notioncli blocks list --type X Filter by block type - notioncli blocks add "text" Add a paragraph (default) - notioncli blocks add "text" -t X Add block of type X - notioncli blocks delete N Delete block by index Supported block types: - paragraph, heading_1/2/3 - bulleted_list_item, numbered_list_item - to_do, toggle, quote, callout - divider, code Changes: - Add BlockTypeInfo and SupportedBlockTypes map - Add RichTextBlock struct for parsing various block types - Add GetAllBlocks() with optional type filter - Add GetBlockContent() for any block type - Add GetBlockIcon() with special to-do handling - Add FormatAllBlocks() for formatted output - Add AddBlock() for adding any block type - Add DeleteBlock() for deleting any block - Add cmd/blocks.go with list/add/delete subcommands - Add 8 new tests for block type functions - Update README with blocks command documentation
PR Analysis
PR Feedback
How to useInstructions
|
| Short: "List all blocks on the page", | ||
| Long: `List all blocks on the Notion page with their type and content.`, | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| notionAPIKey, pageID := utils.SetAPIConfig() |
There was a problem hiding this comment.
Consider adding a retry mechanism for network requests in the blocksListCmd, blocksAddCmd, and blocksDeleteCmd to handle transient network errors more gracefully. This can improve user experience in case of temporary connectivity issues. [medium]
| req.Header.Add("Notion-Version", "2022-06-28") | ||
| req.Header.Set("Authorization", "Bearer "+notionAPIKey) | ||
|
|
||
| resp, err := client.Do(req) |
There was a problem hiding this comment.
In GetAllBlocks, consider implementing pagination handling for the Notion API response to ensure that all blocks are retrieved if the page contains more than the API's limit per request. [important]
| "divider": map[string]interface{}{}, | ||
| } | ||
| } else { | ||
| // Most blocks use rich_text |
There was a problem hiding this comment.
In AddBlock, consider validating the text input to ensure it meets any necessary constraints (e.g., length, forbidden characters) before making the API request. This can prevent unnecessary API calls and provide immediate feedback to the user. [medium]
| // DeleteBlock deletes any block by its index (1-based) | ||
| func DeleteBlock(notionAPIKey, pageID string, order int) error { | ||
| // Get all blocks to find the one at the given index | ||
| blocks, err := GetAllBlocks(notionAPIKey, pageID, "") |
There was a problem hiding this comment.
In DeleteBlock, consider adding a confirmation prompt before deleting a block to prevent accidental deletions. This can be implemented as an optional flag that users can bypass if desired. [medium]
- Run tests on push to main and PRs - Build, test, and vet Go code
Handle Notion API pagination for pages with 100+ blocks. Uses start_cursor and has_more to fetch all pages. Addresses PR review feedback from Preston AI.
PR Type:
Enhancement
PR Description:
blockssubcommand to manage all Notion block types, achieving feature parity with the Python version.PR Main Files Walkthrough:
files:
cmd/blocks.go: Added a newblockscommand with subcommands for listing, adding, and deleting blocks. Supports filtering by block type and includes detailed examples and error handling.utils/block.go: Introduced new data structures and functions to handle various block types. Added support for retrieving, formatting, adding, and deleting blocks. Implemented utility functions for block type validation and content extraction.utils/block_test.go: Added tests for block type validation, supported block type retrieval, block content extraction, and block icon retrieval. Ensures correct functionality of new block type features.README.md: Updated documentation to include new block commands and examples. Detailed the supported block types and their usage. Clarified the distinction between task commands and block commands.User Description:
Summary
Adds a new
blockssubcommand for working with all Notion block types, bringing the Go version to feature parity with the Python version.New Commands
notioncli blocks listnotioncli blocks list --type heading_1notioncli blocks add "text"notioncli blocks add "Title" -t heading_1notioncli blocks delete 5Supported Block Types
Backward Compatibility
All existing commands work exactly the same:
notioncli list→ lists to-dos onlynotioncli add "task"→ adds a to-donotioncli check 3→ marks to-do completenotioncli delete 2→ deletes to-doExample Output
Tests
Files Changed
utils/block.go- Add block type supportutils/block_test.go- Add testscmd/blocks.go- New blocks subcommandREADME.md- Documentation