Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ func init() {
channelCmd.AddCommand(channelListCmd, channelNewCmd, channelInviteCmd)

channelListCmd.Flags().String("user", "", "User ID, @handle, or email")
channelListCmd.Flags().Bool("all", false, "List all workspace conversations (auto-paginates unless --cursor is set)")
channelListCmd.Flags().Bool("all", false, "List all workspace conversations instead of just the ones the bot is a member of")
channelListCmd.Flags().Int("limit", 100, "Conversations per page fetched from Slack")
channelListCmd.Flags().String("cursor", "", "Resume from this pagination cursor instead of auto-paginating")
channelListCmd.Flags().String("cursor", "", "Resume from this pagination cursor instead of auto-paginating (applies with or without --all)")

channelNewCmd.Flags().String("name", "", "Channel name")
_ = channelNewCmd.MarkFlagRequired("name")
Expand Down
2 changes: 1 addition & 1 deletion internal/slack/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func ListChannels(ctx context.Context, client *api.Client, opts ListChannelsOpts
method = "conversations.list"
}

autoPaginate := opts.All && opts.Cursor == ""
autoPaginate := opts.Cursor == ""

result := &ChannelListResult{}
cursor := opts.Cursor
Expand Down
37 changes: 37 additions & 0 deletions internal/slack/channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ func TestListChannels_AllAutoPaginatesAcrossShardedPages(t *testing.T) {
}
}

func TestListChannels_MemberOnlyAlsoAutoPaginates(t *testing.T) {
srv := fakeConversationsList(t, [][]string{
{"general"},
{"nul-team", "internal-acme"},
})
defer srv.Close()

result, err := ListChannels(context.Background(), testClient(srv.URL), ListChannelsOpts{})
if err != nil {
t.Fatalf("ListChannels: %v", err)
}

if len(result.Channels) != 3 {
t.Fatalf("expected 3 channels merged across pages, got %d: %+v", len(result.Channels), result.Channels)
}
if result.NextCursor != "" {
t.Fatalf("expected no next_cursor after exhausting pages, got %q", result.NextCursor)
}
}

func TestListChannels_ExplicitCursorFetchesSinglePage(t *testing.T) {
srv := fakeConversationsList(t, [][]string{
{"general"},
Expand All @@ -102,6 +122,23 @@ func TestListChannels_ExplicitCursorFetchesSinglePage(t *testing.T) {
}
}

func TestListChannels_ExplicitCursorFetchesSinglePageWithoutAll(t *testing.T) {
srv := fakeConversationsList(t, [][]string{
{"general"},
{"internal-acme"},
})
defer srv.Close()

result, err := ListChannels(context.Background(), testClient(srv.URL), ListChannelsOpts{Cursor: "some-cursor"})
if err != nil {
t.Fatalf("ListChannels: %v", err)
}

if len(result.Channels) != 1 {
t.Fatalf("expected exactly 1 page of channels with explicit cursor, got %d", len(result.Channels))
}
}

func TestListChannels_TruncatesAtPageCap(t *testing.T) {
old := maxAutoPaginatePages
maxAutoPaginatePages = 2
Expand Down
Loading