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
8 changes: 7 additions & 1 deletion internal/cli/incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func pastIncidentColumns() []output.Column {
}

func newIncidentListCmd() *cobra.Command {
var progress, severity, query, since, until, nums string
var progress, severity, query, title, since, until, nums string
var channelID int64
var limit, page int

Expand All @@ -101,6 +101,11 @@ func newIncidentListCmd() *cobra.Command {
EndTime: endTime,
Query: query,
}
// --title is a convenience alias for --query (same backend
// "query" field). --query stays authoritative when both are set.
if title != "" && query == "" {
req.Query = title
}
req.Page = page
req.Limit = limit
if channelID != 0 {
Expand All @@ -126,6 +131,7 @@ func newIncidentListCmd() *cobra.Command {
registerEnumFlag(cmd, "severity", severityEnum...)
cmd.Flags().Int64Var(&channelID, "channel", 0, "Filter by channel ID")
cmd.Flags().StringVar(&query, "query", "", "Free-text search across title/labels/content (also resolves a 24-char incident ID or 6-char incident num to a direct lookup)")
cmd.Flags().StringVar(&title, "title", "", "Search by title/content keyword (alias of --query; --query wins if both set)")
cmd.Flags().StringVar(&nums, "nums", "", "Comma-separated short incident ids (num, the 6-char id shown in the UI) to filter by")
cmd.Flags().StringVar(&since, "since", "24h", "Start time (duration, date, datetime, or unix timestamp; --since→--until window must be < 31 days)")
cmd.Flags().StringVar(&until, "until", "now", "End time")
Expand Down
29 changes: 29 additions & 0 deletions internal/cli/incident_short_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,35 @@ func TestIncidentListNumsReachesWire(t *testing.T) {
}
}

// TestIncidentListTitleReachesWireAsQuery: --title is sent as the query body field.
func TestIncidentListTitleReachesWireAsQuery(t *testing.T) {
saveAndResetGlobals(t)
stub := newGFStub(t)
stub.data = incidentListData()
if _, err := execCommand("incident", "list", "--title", "test create incident"); err != nil {
t.Fatalf("execCommand: %v", err)
}
if stub.lastPath != "/incident/list" {
t.Fatalf("path = %q, want /incident/list", stub.lastPath)
}
if got, _ := stub.lastBody["query"].(string); got != "test create incident" {
t.Errorf("query = %q, want %q", got, "test create incident")
}
}

// TestIncidentListQueryWinsOverTitle: when both --query and --title are set, --query is authoritative.
func TestIncidentListQueryWinsOverTitle(t *testing.T) {
saveAndResetGlobals(t)
stub := newGFStub(t)
stub.data = incidentListData()
if _, err := execCommand("incident", "list", "--query", "q", "--title", "t"); err != nil {
t.Fatalf("execCommand: %v", err)
}
if got, _ := stub.lastBody["query"].(string); got != "q" {
t.Errorf("query = %q, want %q (--query must win)", got, "q")
}
}

func equalStrings(a, b []string) bool {
if len(a) != len(b) {
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ flashduty incident list [flags]
| `--progress` | string | | Filter by state: `Triggered`, `Processing`, `Closed` |
| `--severity` | string | | Filter by severity: `Critical`, `Warning`, `Info` |
| `--channel` | int | | Filter by channel ID |
| `--title` | string | | Search by title keyword |
| `--query` | string | | Free-text search across title/labels/content |
| `--title` | string | | Search by title/content keyword (alias of `--query`; `--query` wins if both set) |
| `--since` | string | `24h` | Start time (duration like `24h`, date, datetime, or unix timestamp) |
| `--until` | string | `now` | End time |
| `--limit` | int | `20` | Max results (max 100) |
Expand Down
Loading