Skip to content

Comments

fix(snippets): implement pagination for snippets list command#4879

Open
angeliski wants to merge 1 commit intosupabase:developfrom
angeliski:fix/snippets-list-pagination
Open

fix(snippets): implement pagination for snippets list command#4879
angeliski wants to merge 1 commit intosupabase:developfrom
angeliski:fix/snippets-list-pagination

Conversation

@angeliski
Copy link

@angeliski angeliski commented Feb 20, 2026

What kind of change does this PR introduce?

Bug fix - Implement pagination support for snippets list command

What is the current behavior?

The supabase snippets list command was not implementing pagination correctly, returning only the first page of results and not fetching subsequent pages via cursor-based pagination.

Related to #4858

I

What is the new behavior?

✅ Implemented cursor-based pagination that:

  • Fetches all snippets across multiple pages sequentially
  • Tracks cursor between API calls to fetch next pages
  • Properly terminates when no more pages are available
  • Supports JSON, TOML, and table output formats

Example usage:

# Fetches all snippets (pagination handled automatically)
supabase snippets list --project-ref <ref>

# With JSON output
supabase snippets list --project-ref <ref> -o json

Additional context

Design Decision - Pagination-Only Approach:

This PR intentionally focuses on implementing pagination without introducing additional filtering or sorting parameters (e.g., --limit, --sort-by, --sort-order). The rationale behind this approach:

Consistency: Follows the existing CLI pattern where pagination is handled transparently without user-exposed parameters
Simplicity: Reduces cognitive load - users simply run the command and get all results, without needing to understand pagination mechanics
API Alignment: Mirrors the behavior of similar Supabase CLI commands (databases list, functions list, etc.)
Scope: Keeps the fix focused on resolving the reported issue without scope creep
Future Improvements:

Sorting and limiting capabilities could be valuable additions in a subsequent PR if deemed necessary:

--limit could cap the number of results retrieved
--sort-by and --sort-order could organize results (though the API's cursor-based model makes client-side sorting more practical)
However, pagination (fetching all available results) was the primary blocker and is now fully functional.

@angeliski angeliski requested a review from a team as a code owner February 20, 2026 19:58
@coderabbitai
Copy link

coderabbitai bot commented Feb 20, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Snippet listing now automatically paginates to retrieve all results; outputs across table, JSON, and TOML formats are consolidated and consistent.
  • Tests

    • Added tests covering multi-page pagination and improved test isolation by capturing/restoring test output.

Walkthrough

Adds pagination to the snippets list: the list function now loops using a Limit (defaultLimit) and an optional Cursor, repeatedly calling the Snippets API and accumulating each response until no cursor is returned. Output rendering was changed to aggregate/flatten data across all responses for table and non-table formats. Numeric conversion uses strconv. Tests add a muteStdout helper, support project_ref in mock requests, and include a new test that simulates two-page pagination to validate aggregation of all items.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ListFunction as List Function
    participant API as Snippets API
    participant Renderer

    Client->>ListFunction: Invoke list (optional project_ref)
    ListFunction->>ListFunction: set currentCursor = ""
    ListFunction->>ListFunction: set Limit = defaultLimit

    loop while currentCursor != nil
        ListFunction->>API: GET /snippets?Limit=Limit&Cursor=currentCursor
        API-->>ListFunction: { data: [...], cursor: "next_page" }
        ListFunction->>ListFunction: append response to allResponses
        alt cursor present
            ListFunction->>ListFunction: update currentCursor = "next_page"
        else no cursor
            ListFunction->>ListFunction: set currentCursor = nil
        end
    end

    ListFunction->>Renderer: send flattened allResponses for output (table/JSON/TOML)
    Renderer-->>Client: display aggregated snippets
Loading

Comment @coderabbitai help to get the list of available commands and usage tips.

@coveralls
Copy link

coveralls commented Feb 20, 2026

Pull Request Test Coverage Report for Build 22239486744

Details

  • 42 of 44 (95.45%) changed or added relevant lines in 1 file are covered.
  • 5 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.04%) to 61.843%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/snippets/list/list.go 42 44 95.45%
Files with Coverage Reduction New Missed Lines %
internal/utils/git.go 5 57.14%
Totals Coverage Status
Change from base Build 22229841129: 0.04%
Covered Lines: 7731
Relevant Lines: 12501

💛 - Coveralls

- Add cursor-based pagination support to fetch all snippets across multiple pages
- Implement proper pagination loop with cursor tracking
- Add comprehensive unit tests for pagination and output formats
- Support JSON, TOML, and table output formats
- Simplify code to use native API types without unnecessary conversions
- All tests passing

Closes supabase#4858
@angeliski angeliski force-pushed the fix/snippets-list-pagination branch from 325bd0b to 91143fd Compare February 20, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants