Skip to content

feat: Add support for all block types - #3

Merged
kris-hansen merged 3 commits into
mainfrom
feature/block-types
Mar 12, 2026
Merged

feat: Add support for all block types#3
kris-hansen merged 3 commits into
mainfrom
feature/block-types

Conversation

@kris-hansen

@kris-hansen kris-hansen commented Mar 12, 2026

Copy link
Copy Markdown
Owner

PR Type:

Enhancement


PR Description:

  • Introduces a new blocks subcommand to manage all Notion block types, achieving feature parity with the Python version.
  • Implements commands to list, add, and delete various block types.
  • Supports a wide range of block types including paragraphs, headings, lists, to-dos, toggles, quotes, callouts, dividers, and code blocks.
  • Ensures backward compatibility with existing to-do commands.
  • Adds comprehensive tests for new block type functionalities.
  • Updates documentation to reflect new command capabilities and usage examples.

PR Main Files Walkthrough:

files:
  • cmd/blocks.go: Added a new blocks command 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 blocks subcommand for working with all Notion block types, bringing the Go version to feature parity with the Python version.

New Commands

Command Description
notioncli blocks list List all blocks on the page
notioncli blocks list --type heading_1 Filter by block type
notioncli blocks add "text" Add a paragraph (default)
notioncli blocks add "Title" -t heading_1 Add a heading
notioncli blocks delete 5 Delete any block by index

Supported Block Types

paragraph, heading_1, heading_2, heading_3,
bulleted_list_item, numbered_list_item,
to_do, toggle, quote, callout, divider, code

Backward Compatibility

All existing commands work exactly the same:

  • notioncli list → lists to-dos only
  • notioncli add "task" → adds a to-do
  • notioncli check 3 → marks to-do complete
  • notioncli delete 2 → deletes to-do

Example Output

$ notioncli blocks list

   1 ☐  [to_do               ] Buy groceries (2024-01-01 12:00)
   2 ¶  [paragraph           ] Some notes here
   3 H1 [heading_1           ] Project Title
   4 •  [bulleted_list_item  ] First point

  4 blocks: 1 bulleted_list_item, 1 heading_1, 1 paragraph, 1 to_do

Tests

  • 8 new tests for block type functions
  • All existing tests still pass ✅

Files Changed

  • utils/block.go - Add block type support
  • utils/block_test.go - Add tests
  • cmd/blocks.go - New blocks subcommand
  • README.md - Documentation

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
@preston-ai preston-ai Bot added the enhancement New feature or request label Mar 12, 2026
@preston-ai

preston-ai Bot commented Mar 12, 2026

Copy link
Copy Markdown

PR Analysis

  • 🎯 Main theme: Add support for managing all Notion block types in the Go version of the CLI tool.
  • 📝 PR summary: This PR introduces a new blocks subcommand to the CLI tool, allowing users to manage various Notion block types. It includes commands to list, add, and delete blocks, supporting a wide range of block types. The PR ensures backward compatibility with existing to-do commands and adds comprehensive tests and documentation updates.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: Yes
  • Focused PR: Yes, because all changes are centered around adding support for managing Notion block types and are well-organized within the relevant files.
  • ⏱️ Estimated effort to review [1-5]: 3, because the PR introduces a significant amount of new functionality and requires understanding of both the CLI structure and Notion API interactions.
  • 🔒 Security concerns: No security concerns found

PR Feedback

  • 💡 General suggestions: The PR is well-structured and introduces comprehensive functionality for managing Notion block types. Ensure that the new commands are thoroughly tested in different environments to verify their robustness and compatibility with various Notion page configurations.

How to use

Instructions

To invoke the Preston AI, add a comment using one of the following commands:
/review: Request a review of your Pull Request.
/describe: Update the PR title and description based on the contents of the PR.
/improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
/ask <QUESTION>: Ask a question about the PR.
/add_docs: Generate docstring for new components introduced in the PR.
/generate_labels: Generate labels for the PR based on the PR's contents.

Comment thread cmd/blocks.go
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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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]

Comment thread utils/block.go Outdated
req.Header.Add("Notion-Version", "2022-06-28")
req.Header.Set("Authorization", "Bearer "+notionAPIKey)

resp, err := client.Do(req)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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]

Comment thread utils/block.go
"divider": map[string]interface{}{},
}
} else {
// Most blocks use rich_text

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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]

Comment thread utils/block.go
// 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, "")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.
@kris-hansen
kris-hansen merged commit 445af82 into main Mar 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant