Skip to content

Commit 3ed32a1

Browse files
authored
Merge pull request #4 from ysyneu/fix/channel-ids-array-filter
fix: send channel_ids array to /incident/list and /change/list
2 parents d2b32ab + 09dbddf commit 3ed32a1

3 files changed

Lines changed: 45 additions & 23 deletions

File tree

changes.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ import (
1010

1111
// ListChangesInput contains parameters for listing changes
1212
type ListChangesInput struct {
13-
ChangeIDs []string // Direct lookup by change IDs
14-
ChannelID int64 // Filter by collaboration space ID
15-
StartTime int64 // Unix timestamp (seconds)
16-
EndTime int64 // Unix timestamp (seconds)
17-
Type string // Filter by change type
18-
Limit int // Max results (default 20)
19-
Page int // Page number (default 1)
13+
ChangeIDs []string // Direct lookup by change IDs
14+
ChannelIDs []int64 // Filter by collaboration space IDs
15+
// Deprecated: use ChannelIDs. The backend /change/list endpoint expects
16+
// channel_ids (array) — singular channel_id is silently ignored.
17+
ChannelID int64
18+
StartTime int64 // Unix timestamp (seconds)
19+
EndTime int64 // Unix timestamp (seconds)
20+
Type string
21+
Limit int
22+
Page int
2023
}
2124

2225
// ListChangesOutput contains the result of listing changes
@@ -44,8 +47,8 @@ func (c *Client) ListChanges(ctx context.Context, input *ListChangesInput) (*Lis
4447
if len(input.ChangeIDs) > 0 {
4548
requestBody["change_ids"] = input.ChangeIDs
4649
}
47-
if input.ChannelID > 0 {
48-
requestBody["channel_id"] = input.ChannelID
50+
if channelIDs := mergeChannelIDs(input.ChannelIDs, input.ChannelID); len(channelIDs) > 0 {
51+
requestBody["channel_ids"] = channelIDs
4952
}
5053
if input.StartTime > 0 {
5154
requestBody["start_time"] = input.StartTime

helpers.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ func parseCommaSeparatedStrings(s string) []string {
2020
return result
2121
}
2222

23+
// mergeChannelIDs combines a primary slice with a deprecated singular ChannelID
24+
// field. The slice wins when set; otherwise a non-zero singular value is wrapped
25+
// into a one-element slice. Used to migrate callers from ChannelID to ChannelIDs
26+
// without breaking existing code.
27+
func mergeChannelIDs(channelIDs []int64, channelID int64) []int64 {
28+
if len(channelIDs) > 0 {
29+
return channelIDs
30+
}
31+
if channelID > 0 {
32+
return []int64{channelID}
33+
}
34+
return nil
35+
}
36+
2337
func parseCommaSeparatedInts(s string) []int {
2438
if s == "" {
2539
return nil

incidents.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@ const defaultQueryLimit = 20
1212

1313
// ListIncidentsInput contains parameters for listing incidents
1414
type ListIncidentsInput struct {
15-
IncidentIDs []string // Direct lookup by IDs (if set, other filters are ignored)
16-
Progress string // Filter: Triggered, Processing, Closed (comma-separated for multiple)
17-
Severity string // Filter: Info, Warning, Critical
18-
ChannelID int64 // Filter by collaboration space ID
19-
StartTime int64 // Unix timestamp (seconds), required if no IncidentIDs
20-
EndTime int64 // Unix timestamp (seconds), required if no IncidentIDs
21-
Title string // Keyword search in incident title
22-
Limit int // Max results (default 20, max 100)
23-
Page int // Page number (default 1)
24-
IncludeAlerts bool // Whether to include alerts preview (default true)
15+
IncidentIDs []string // Direct lookup by IDs (if set, other filters are ignored)
16+
Progress string // Filter: Triggered, Processing, Closed (comma-separated for multiple)
17+
Severity string // Filter: Info, Warning, Critical
18+
ChannelIDs []int64 // Filter by collaboration space IDs
19+
// Deprecated: use ChannelIDs. If both are set, ChannelIDs wins; otherwise
20+
// a non-zero ChannelID is wrapped into a single-element ChannelIDs slice.
21+
// The backend /incident/list endpoint expects channel_ids (array) — singular
22+
// channel_id is silently ignored.
23+
ChannelID int64
24+
StartTime int64 // Unix timestamp (seconds), required if no IncidentIDs
25+
EndTime int64 // Unix timestamp (seconds), required if no IncidentIDs
26+
Title string
27+
Limit int
28+
Page int
29+
IncludeAlerts bool
2530
}
2631

2732
// ListIncidentsOutput contains the result of listing incidents
@@ -50,7 +55,7 @@ func (c *Client) ListIncidents(ctx context.Context, input *ListIncidentsInput) (
5055
if page <= 0 {
5156
page = 1
5257
}
53-
rawIncidents, err = c.fetchIncidentsByFilters(ctx, input.Progress, input.Severity, input.ChannelID, input.StartTime, input.EndTime, input.Title, limit, page)
58+
rawIncidents, err = c.fetchIncidentsByFilters(ctx, input.Progress, input.Severity, mergeChannelIDs(input.ChannelIDs, input.ChannelID), input.StartTime, input.EndTime, input.Title, limit, page)
5459
}
5560

5661
if err != nil {
@@ -441,7 +446,7 @@ func (c *Client) fetchIncidentsByIDs(ctx context.Context, incidentIDs []string)
441446
}
442447

443448
// fetchIncidentsByFilters fetches incidents by filters
444-
func (c *Client) fetchIncidentsByFilters(ctx context.Context, progress, severity string, channelID, startTime, endTime int64, title string, limit, page int) ([]RawIncident, error) {
449+
func (c *Client) fetchIncidentsByFilters(ctx context.Context, progress, severity string, channelIDs []int64, startTime, endTime int64, title string, limit, page int) ([]RawIncident, error) {
445450
requestBody := map[string]any{
446451
"p": page,
447452
"limit": limit,
@@ -455,8 +460,8 @@ func (c *Client) fetchIncidentsByFilters(ctx context.Context, progress, severity
455460
if severity != "" {
456461
requestBody["incident_severity"] = severity
457462
}
458-
if channelID > 0 {
459-
requestBody["channel_id"] = channelID
463+
if len(channelIDs) > 0 {
464+
requestBody["channel_ids"] = channelIDs
460465
}
461466
if title != "" {
462467
requestBody["title"] = title

0 commit comments

Comments
 (0)