Skip to content

Commit 95116db

Browse files
committed
fix(channel): filter list --name server-side
channel list --name matched names client-side on the returned page only, so with paging it missed channels on other pages, and it duplicated the server-side query filter. Send the escaped text as the server's query regex instead (same case-insensitive substring semantics, now also over the description), drop the separate --query flag, and print the server's total. Also list the valid --orderby values, and state precisely why the audit and alert-event cursor/order fields are not exposed.
1 parent eb61d76 commit 95116db

5 files changed

Lines changed: 16 additions & 23 deletions

File tree

‎internal/cli/channel.go‎

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package cli
22

33
import (
44
"fmt"
5+
"regexp"
56
"strconv"
6-
"strings"
77

88
"github.com/flashcatcloud/go-flashduty"
99
"github.com/spf13/cobra"
@@ -37,7 +37,7 @@ type channelRow struct {
3737
}
3838

3939
func newChannelListCmd() *cobra.Command {
40-
var name, channelName, query, orderby string
40+
var name, channelName, orderby string
4141
var teamIDs, channelIDs []int64
4242
var page, limit int
4343
var asc, isBrief, isMyManaged, isMyStarred, isMyTeam bool
@@ -48,17 +48,14 @@ func newChannelListCmd() *cobra.Command {
4848
Long: curatedLong("List channels in the account, optionally filtered by name or owning team.", "Channels", "ChannelList"),
4949
RunE: func(cmd *cobra.Command, args []string) error {
5050
return runCommand(cmd, args, func(ctx *RunContext) error {
51-
// Legacy parity: the hand-written SDK called /channel/list with an
52-
// empty body and applied the --name filter client-side as a
53-
// case-insensitive substring match. go-flashduty's ChannelName field
54-
// is an exact-match server filter, so we keep the client-side filter
55-
// to preserve behavior. --team-ids, by contrast, is a server-side
56-
// filter on the channel's owning team (empty = all teams, unchanged).
51+
// --name keeps its case-insensitive substring semantics by sending
52+
// the escaped text as the server's query regex, so the match runs
53+
// across every page instead of only the page returned.
5754
req := &flashduty.ListChannelsRequest{
5855
TeamIDs: teamIDs,
5956
ChannelIDs: channelIDs,
6057
ChannelName: channelName,
61-
Query: query,
58+
Query: regexp.QuoteMeta(name),
6259
Orderby: orderby,
6360
Asc: asc,
6461
IsBrief: isBrief,
@@ -79,9 +76,6 @@ func newChannelListCmd() *cobra.Command {
7976

8077
rows := make([]channelRow, 0, len(result.Items))
8178
for _, ch := range result.Items {
82-
if name != "" && !strings.Contains(strings.ToLower(ch.ChannelName), strings.ToLower(name)) {
83-
continue
84-
}
8579
rows = append(rows, channelRow{
8680
ChannelID: ch.ChannelID,
8781
ChannelName: ch.ChannelName,
@@ -102,20 +96,19 @@ func newChannelListCmd() *cobra.Command {
10296
{Header: "CREATOR", Field: func(v any) string { return v.(channelRow).CreatorName }},
10397
}
10498

105-
return ctx.PrintTotal(rows, cols, len(rows))
99+
return ctx.PrintTotal(rows, cols, int(result.Total))
106100
})
107101
},
108102
}
109103

110-
cmd.Flags().StringVar(&name, "name", "", "Search by name")
104+
cmd.Flags().StringVar(&name, "name", "", "Case-insensitive substring of the channel name or description, server-side")
111105
cmd.Flags().StringVar(&channelName, "channel-name", "", "Exact channel name, server-side")
112-
cmd.Flags().StringVar(&query, "query", "", "Case-insensitive regex over channel name and description, server-side")
113106
cmd.Flags().Int64SliceVar(&channelIDs, "channel-ids", nil, "Filter by channel ID(s) (repeatable or comma-separated)")
114107
cmd.Flags().BoolVar(&isMyTeam, "is-my-team", false, "Only channels owned by your teams (exclusive with --is-my-starred)")
115108
cmd.Flags().BoolVar(&isMyStarred, "is-my-starred", false, "Only channels you starred (exclusive with --is-my-team)")
116109
cmd.Flags().BoolVar(&isMyManaged, "is-my-managed", false, "Only channels you manage")
117110
cmd.Flags().BoolVar(&isBrief, "is-brief", false, "Return only id, name, description and status, all matches without pagination")
118-
cmd.Flags().StringVar(&orderby, "orderby", "", "Sort field (server default: created_at)")
111+
cmd.Flags().StringVar(&orderby, "orderby", "", "Sort field: ranking, created_at, updated_at, channel_name, or last_incident_at (server default: created_at)")
119112
cmd.Flags().BoolVar(&asc, "asc", false, "Sort in ascending order")
120113
cmd.Flags().IntVar(&page, "page", 1, "Page number")
121114
cmd.Flags().IntVar(&limit, "limit", 100, "Page size (server default 100)")

‎internal/cli/curated_fields_test.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var curatedFieldRoutes = map[string]map[string]string{
4848
"start_time": "--since",
4949
"end_time": "--until",
5050
"p": "--page",
51-
"orderby": "omit: event_time is the only supported value and the server default",
51+
"orderby": "omit: event_time is the server default and the only order the server's paging cursor supports",
5252
"search_after_ctx": "omit: cursor returned by the previous page; the curated list pages with --page and does not print the next-page cursor",
5353
},
5454
"incident merge": {
@@ -62,7 +62,7 @@ var curatedFieldRoutes = map[string]map[string]string{
6262
"end_time": "--until",
6363
"person_id": "--person",
6464
"operations": "--operation",
65-
"search_after_ctx": "omit: the cursor is managed by the command; --page walks it",
65+
"search_after_ctx": "omit: --page walks the cursor by re-sending each response's search_after_ctx",
6666
},
6767
"change list": {
6868
"start_time": "--since",
@@ -75,7 +75,8 @@ var curatedFieldRoutes = map[string]map[string]string{
7575
"data_source_ids": "omit: deprecated alias of integration_ids, which --integration sets",
7676
},
7777
"channel list": {
78-
"p": "--page",
78+
"p": "--page",
79+
"query": "--name",
7980
},
8081
"team list": {
8182
"p": "--page",

‎internal/cli/curated_misc_fields_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ func TestCuratedListFilterFlagsReachWireBody(t *testing.T) {
5959
},
6060
{
6161
name: "channel filters and paging",
62-
args: []string{"channel", "list", "--query", "^pay", "--channel-name", "payments", "--channel-ids", "1,2", "--is-my-team", "--is-my-managed", "--is-brief", "--orderby", "channel_name", "--asc", "--page", "2", "--limit", "10"},
62+
args: []string{"channel", "list", "--name", "pay.ments", "--channel-name", "payments", "--channel-ids", "1,2", "--is-my-team", "--is-my-managed", "--is-brief", "--orderby", "channel_name", "--asc", "--page", "2", "--limit", "10"},
6363
path: "/channel/list",
6464
want: map[string]any{
65-
"query": "^pay", "channel_name": "payments", "channel_ids": []any{float64(1), float64(2)},
65+
"query": `pay\.ments`, "channel_name": "payments", "channel_ids": []any{float64(1), float64(2)},
6666
"is_my_team": true, "is_my_managed": true, "is_brief": true,
6767
"orderby": "channel_name", "asc": true, "p": float64(2), "limit": float64(10),
6868
},

‎internal/cli/field.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func newFieldListCmd() *cobra.Command {
6666
}
6767

6868
cmd.Flags().StringVar(&name, "name", "", "Filter by field name")
69-
cmd.Flags().StringVar(&query, "query", "", "Regex over field_name, server-side")
69+
cmd.Flags().StringVar(&query, "query", "", "Case-insensitive regex over the field name, server-side")
7070
cmd.Flags().Int64Var(&creatorID, "creator-id", 0, "Filter by creator member ID")
7171
cmd.Flags().StringVar(&orderby, "orderby", "", "Sort key (server default: created_at)")
7272
cmd.Flags().BoolVar(&asc, "asc", false, "Sort in ascending order")

‎skills/flashduty/reference/channel.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ List channels
8989
- `--name` string
9090
- `--orderby` string
9191
- `--page` int
92-
- `--query` string
9392
- `--team-ids` int64Slice
9493
- response: TOP-LEVEL array — pipe `--json | jq '.[]'` (NOT `.items[]`) — fields: account_id (integer); active_incident_highest_severity (string); auto_resolve_mode (string); auto_resolve_timeout (integer); channel_id (integer); channel_name (string); created_at (string); creator_id (integer); creator_name (string); deleted_at (string); description (string); disable_auto_close (boolean); disable_outlier_detection (boolean); event_group (object); external_report_token (string); flapping (object); group (object); is_external_report_enabled (boolean); is_private (boolean); is_starred (boolean); last_incident_at (string); managing_team_ids (array<integer>); progress_to_incident_cnts (object); status (string); team_id (integer); team_name (string); updated_at (string)
9594

0 commit comments

Comments
 (0)