Add --id flag to bd list for filtering by specific issue IDs
- Add --id flag accepting comma-separated IDs - Implements ID filtering at CLI, RPC, and storage layers - Normalizes IDs (trim, dedupe, remove empty) like labels - Guards against excessive ID lists (max 1000) - Works with other filters (status, priority, etc.) Closes bd-200 Amp-Thread-ID: https://ampcode.com/threads/T-377464f2-1e7f-46f9-b23e-1e3cfd611061 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -93,6 +93,7 @@ type ListArgs struct {
|
||||
Label string `json:"label,omitempty"` // Deprecated: use Labels
|
||||
Labels []string `json:"labels,omitempty"` // AND semantics
|
||||
LabelsAny []string `json:"labels_any,omitempty"` // OR semantics
|
||||
IDs []string `json:"ids,omitempty"` // Filter by specific issue IDs
|
||||
Limit int `json:"limit,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
@@ -940,6 +940,21 @@ func (s *Server) handleList(req *Request) Response {
|
||||
if len(labelsAny) > 0 {
|
||||
filter.LabelsAny = labelsAny
|
||||
}
|
||||
if len(listArgs.IDs) > 0 {
|
||||
ids := normalizeLabels(listArgs.IDs)
|
||||
if len(ids) > 0 {
|
||||
filter.IDs = ids
|
||||
}
|
||||
}
|
||||
|
||||
// Guard against excessive ID lists to avoid SQLite parameter limits
|
||||
const maxIDs = 1000
|
||||
if len(filter.IDs) > maxIDs {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("--id flag supports at most %d issue IDs, got %d", maxIDs, len(filter.IDs)),
|
||||
}
|
||||
}
|
||||
|
||||
ctx := s.reqCtx(req)
|
||||
issues, err := store.SearchIssues(ctx, listArgs.Query, filter)
|
||||
|
||||
@@ -1705,6 +1705,16 @@ func (s *SQLiteStorage) SearchIssues(ctx context.Context, query string, filter t
|
||||
whereClauses = append(whereClauses, fmt.Sprintf("id IN (SELECT issue_id FROM labels WHERE label IN (%s))", strings.Join(placeholders, ", ")))
|
||||
}
|
||||
|
||||
// ID filtering: match specific issue IDs
|
||||
if len(filter.IDs) > 0 {
|
||||
placeholders := make([]string, len(filter.IDs))
|
||||
for i, id := range filter.IDs {
|
||||
placeholders[i] = "?"
|
||||
args = append(args, id)
|
||||
}
|
||||
whereClauses = append(whereClauses, fmt.Sprintf("id IN (%s)", strings.Join(placeholders, ", ")))
|
||||
}
|
||||
|
||||
whereSQL := ""
|
||||
if len(whereClauses) > 0 {
|
||||
whereSQL = "WHERE " + strings.Join(whereClauses, " AND ")
|
||||
|
||||
@@ -212,6 +212,7 @@ type IssueFilter struct {
|
||||
Labels []string // AND semantics: issue must have ALL these labels
|
||||
LabelsAny []string // OR semantics: issue must have AT LEAST ONE of these labels
|
||||
TitleSearch string
|
||||
IDs []string // Filter by specific issue IDs
|
||||
Limit int
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user