* feat(list): bd list's remaining filters over http behind issues.list.filters Over http every `bd list` filter beyond the created bounds and the title, id and no-assignee scope refused (time bounds, priority range, text and external-ref matches, spec, label pattern/regex, exclude-type, no-parent, no-labels, empty-description, pinned/no-pinned, deferred, overdue, mol/wisp type). The library entry already applied all of them: issueops.Reader.List via workapi.BuildListFilter, shared by the CLI and the handler. This adds only the wire. - Server: GET /v0/beads/issues decodes 29 new optional parameters (listFilterParams, decode only; countIssues' names where it already spells the filter) into the existing ListRequest, behind one new behavior token, issues.list.filters. mol_type/wisp_type are closed enums refused by name (an empty value too). wire_revision stays 2; apigen and the wireshape golden are regenerated (additive only). - Every RFC 3339 bound the listing and count decode is normalized to UTC, so an offset-bearing bound selects what its Z twin does on a zone-less timestamp column. - workapi.BuildListFilter refuses PinnedFlag with NoPinnedFlag (ErrValidation, the CLI's own sentence) instead of letting PinnedFlag win; over http that is a 400 on no_pinned. - Client: the encoder sends the members (encode.ListFiltersMembers, one list read by the encoder, the pre-dial gate and a spec-parity test). Against a server not advertising the token, httpReader.List refuses before dialing with ErrUnsupported naming issues.list.filters. The 29 E-ListRequest ledger refusal rows retire; the ledger doc is updated; skew flag mappings added. - Tests: handler decode/parity/enum/UTC/malformed/pinned-pair tests; encode member/gate/spec parity and bound encoding; per-member ride-behind-token and pre-dial skew refusal; two new Reader contract cases on every leg (dolt, embedded, uow, served): the eight time bounds at exact boundaries (strict, whole-second truncation, NULL never matches, +02:00 equals UTC) and one in/out row per remaining family; three served Reader cases unparked; TestE2E_ListFilterParityOverHTTP (served == embedded, masked server refuses naming the token, no dial); five corpus shapes marked pending until the reference server profile advertises the token. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * feat(list): exclude_status on listIssues, the 30th issues.list.filters member issueops.ListRequest gains ExcludeStatus: statuses to leave out of a listing, appended to the default exclusions (never re-admitting what they hide), comma-separated or repeated, and validated against the workspace's statuses by the same rule CountRequest.ExcludeStatus uses (an unknown name is ErrValidation). The rule moves into one shared function, workapi.ParseExcludeStatus, called by both builders. With AllFlag it reads the active set without enumerating every status, so an http-backed caller can list O(active) rows instead of the whole history. - Server: listIssues decodes a repeatable `exclude_status` under the same issues.list.filters token (no new token); an unknown name is a 400 on exclude_status. apigen and the wireshape golden are regenerated (additive). - Client: the encoder sends it and it joins encode.ListFiltersMembers, so the pre-dial gate asks for the token. - It is refused together with ReadyFlag, like the other members the ready query cannot carry. - No `bd list --exclude-status` flag yet (it would need the CLI docs regenerated); the member is reachable through the library and the wire. Tests: builder unit test (append, AllFlag, comma split, unknown name); handler decode and 400; encoder, round-trip and gate; Reader contract cases on every leg (active set under AllFlag, repeated and comma values, adds to the defaults, narrows an explicit Status, unknown name refused). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(list): label_regex compile errors are 400s; review polish for list filters - An invalid `label_regex` on GET /v0/beads/issues, /v0/beads/ready and /v0/beads/ready:count is now `400 invalid_argument` (`invalid_value` on `label_regex`) instead of `500 internal`. The database still compiles the pattern in its own dialect; a request that sent a regex and earned the engine's "regular expression is invalid" refusal is attributed to the parameter (failRegexReadErr). The same text on a request with no regex stays a server fault. - mol_type and wisp_type refuse each other's vocabulary (tests pin `mol_type=heartbeat` and `wisp_type=swarm`), so the call-site allowlist, not just the spec enum, is covered. - exclude_status with a workspace custom status: leg tests on the embedded store and over the served wire (accepted and applied; a name in no vocabulary refused). ReaderFixture cannot configure custom statuses, so these sit beside the count's twin rather than in the contract. - The search e2e gains a positive arm: --desc-contains returns exactly the row whose description carries the token. - Docs: `all` plus `exclude_status` keeps every status not named (pinned, hooked and custom done/frozen included unless named), not "the active set"; label_regex documents its 400. A corpus source line is made neutral; a test message says 30. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(list): compose issues.list.filters with the --title-contains fold #7631, now on main, folds `bd list --title-contains` onto listIssues `title` and refuses the TitleContains left over from a --title and --title-contains pair that differs, because the listing then had one title parameter. This branch publishes `title_contains` behind issues.list.filters, so that leftover now rides it beside `title` and the server applies both. Neither half is dropped, and against a server without the token the pre-dial gate refuses, naming issues.list.filters. - encode.FoldTitleContains still runs first; its doc now says where a differing pair goes. - Tests: the fold table expects `title` plus `title_contains` for a differing pair, including the ſ/s pair strings.EqualFold would match; the differing-pair refusal names issues.list.filters; the list_filters_test sweep pairs its TitleContains probe with a differing TitleSearch, since a lone one asks only for issues.list.title; the e2e differing-pair refusal becomes a listFilterShapes row that answers exactly child-a over http and embedded, and refuses before dialing without the token. - The gc-polecat-closed-after corpus shape's pending reason also names issues.list.title. The CHANGELOG --title-contains entry no longer lists the differing pair and --closed-after as refused. Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * build(bazel): auto-sync BUILD files Applied from the bazel-sync-patch artifact of https://github.com/gastownhall/beads/actions/runs/39013611268 (`make bazel-sync`: gazelle, tools/bazel/go_srcs.py, bazel mod tidy). Only BUILD.bazel, MODULE.bazel and MODULE.bazel.lock are ever pushed; see scripts/bazel-autofix-push.sh. * fix(list): serve --priority-max in search parity, refuse the parent pair The proxied tier's search parity table still expected a remote `bd search --priority-max 1` to refuse, because listIssues could not carry it. This branch serves priority_max behind issues.list.filters, so the remote route answered and the dolt-race shard went red in TestProxiedServerSearchRoutesAgree. The row now expects the answer on every route. It was the last wireCan=false row; the branch stays, with a comment, for the next flag listIssues cannot carry. - ParentID with NoParent: a served listing now carries no_parent beside parent, and ANDing the two answered only the edge-less rows under the parent's dotted id. BuildListFilter refuses the pair with ErrValidation, in the sentence bd list and BuildCountFilter already use, so issueops.Reader.List refuses it on every backend and the listing answers 400 on no_parent. Pinned by a builder test, a reader conformance case (dolt, embedded, uow, served http) and two httpapi tests. - POST /v0/beads/issues:claimNext shares the ready listing's label_regex but answered a pattern the database cannot compile with 500. It now gives the listing's 400 invalid_value on label_regex, through the helper the listing's mapping is split into. - The descendant walk's ledger rows said listIssues publishes no parameter for members it now serves behind issues.list.filters. They now say the walk does not send them yet, and that --flat or --json asks listIssues directly. The ExcludeStatus, Pinned and ExcludeTypes rows, the parentwalk.go header, the walk table's doc and two walk test comments are corrected the same way, and the ledger doc is regenerated. parentWalkRefusals notes that a member moved off the list must check issues.list.filters itself, because the walk dials past the listing's pre-dial gate. - Spec: the listing's no_parent documents the pair's 400, the count's exclude_status no longer says it has no listing counterpart, and claimNext's label_regex documents its 400. types.gen.go is regenerated. Comment-only: countFilters, and readyScopeFields' ExcludeStatus entry. - CHANGELOG and README say the default `bd list --parent` tree view does not carry the new filters yet; the label_regex entry names claimNext, and a Changed entry records the parent-pair refusal. Second review pass: docs and comments only, no behavior change. - The prose copies of the issues.list.filters member set now match ListFiltersMembers: CapIssuesListFilters and wire.CapListFilters name the status exclusion, and the spec's capabilities text names label-regex. - Every time bound on the listing and the count goes through q.timestamp, which normalizes it to UTC, and sqlbuild compares it strictly at whole-second precision. listIssues' created_before and created_after, and countIssues' created, updated and closed bounds, now say so in the words the new listing bounds use. The count's updated bounds also say what they filter, and its closed bounds say that a NULL closed_at never matches. types.gen.go is regenerated. - README and CHANGELOG: `--flat` or `--json` applies the filters to the parent's direct children, not its whole subtree. - The 29 listRefusal rows this branch serves stay deleted rather than kept as retired rows, as #7550 deleted its TitleSearch, IDFilter and NoAssignee rows when it served them. The CHANGELOG now says the rows are removed, not retired. Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Eddie the Engineer <338826946+gascity-eddie[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
568 lines
19 KiB
Go
568 lines
19 KiB
Go
package workapi
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/steveyegge/beads/internal/config"
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
"github.com/steveyegge/beads/internal/storage/domain"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/internal/utils"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// DefaultListLimit is the default number of rows a list query returns when the
|
|
// caller does not ask for a specific limit. Every frontend registers its limit
|
|
// knob from this constant so the surfaces cannot drift apart; 0 still means
|
|
// unlimited.
|
|
const DefaultListLimit = 50
|
|
|
|
// PageLimit is the number of rows a list request asks to RECEIVE.
|
|
func PageLimit(in issueops.ListRequest) int {
|
|
return LimitOr(in.Limit, DefaultListLimit)
|
|
}
|
|
|
|
// SQLLimit is the row limit pushed into the query, which can differ from the
|
|
// page limit: `--sort id` needs natural-numeric comparison (bd-9 < bd-10) that
|
|
// SQL cannot express without a schema-side sort column, so that ordering
|
|
// fetches the whole result set and trims in Go afterwards.
|
|
//
|
|
// This lives beside the builder rather than in a caller because it is the
|
|
// second half of one decision — the first half is what the filter carries —
|
|
// and splitting a decision across a library and its callers is how the two
|
|
// halves drift.
|
|
func SQLLimit(in issueops.ListRequest) int {
|
|
if in.SortBy == "id" {
|
|
return 0
|
|
}
|
|
return PageLimit(in)
|
|
}
|
|
|
|
// ListConfig is the store-derived configuration BuildListFilter needs: the
|
|
// workspace's custom statuses and types, plus its infra-type set.
|
|
type ListConfig struct {
|
|
CustomStatuses []types.CustomStatus
|
|
CustomTypes []string
|
|
InfraSet map[string]bool
|
|
}
|
|
|
|
func (c ListConfig) CustomStatusNames() []string {
|
|
out := make([]string, len(c.CustomStatuses))
|
|
for i, s := range c.CustomStatuses {
|
|
out[i] = s.Name
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (c ListConfig) InfraTypes() []string {
|
|
if len(c.InfraSet) == 0 {
|
|
return domain.DefaultInfraTypes()
|
|
}
|
|
out := make([]string, 0, len(c.InfraSet))
|
|
for t := range c.InfraSet {
|
|
out = append(out, t)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (c ListConfig) IsInfra(t string) bool {
|
|
if len(c.InfraSet) == 0 {
|
|
return domain.IsInfraType(types.IssueType(t))
|
|
}
|
|
return c.InfraSet[t]
|
|
}
|
|
|
|
// ConfigSource reads the workspace configuration BuildListFilter depends on.
|
|
// It is the seam between the filter logic and however a given frontend reaches
|
|
// storage (a direct store handle, a unit of work, ...).
|
|
type ConfigSource interface {
|
|
GetCustomStatuses(ctx context.Context) ([]types.CustomStatus, error)
|
|
GetCustomTypes(ctx context.Context) ([]string, error)
|
|
GetInfraTypes(ctx context.Context) (map[string]bool, error)
|
|
}
|
|
|
|
type storeConfigSource struct{ store storage.DoltStorage }
|
|
|
|
// NewStoreConfigSource reads list configuration straight from a store handle.
|
|
func NewStoreConfigSource(store storage.DoltStorage) ConfigSource {
|
|
return storeConfigSource{store: store}
|
|
}
|
|
|
|
func (d storeConfigSource) GetCustomStatuses(ctx context.Context) ([]types.CustomStatus, error) {
|
|
return d.store.GetCustomStatusesDetailed(ctx)
|
|
}
|
|
func (d storeConfigSource) GetCustomTypes(ctx context.Context) ([]string, error) {
|
|
return d.store.GetCustomTypes(ctx)
|
|
}
|
|
func (d storeConfigSource) GetInfraTypes(ctx context.Context) (map[string]bool, error) {
|
|
return d.store.GetInfraTypes(ctx), nil
|
|
}
|
|
|
|
// UnitOfWork is the slice of an open unit of work this package reads through.
|
|
//
|
|
// It is declared here, structurally, rather than imported from
|
|
// internal/storage/uow: that package's provider implements the Reader role and
|
|
// therefore imports this one, so naming its interface here would close an
|
|
// import cycle. uow.UnitOfWork satisfies it without an adapter, which is what
|
|
// keeps the seam honest — this is the same object, described by what the
|
|
// queries need from it.
|
|
type UnitOfWork interface {
|
|
ConfigUseCase() domain.ConfigUseCase
|
|
IssueUseCase() domain.IssueUseCase
|
|
DependencyUseCase() domain.DependencyUseCase
|
|
LabelUseCase() domain.LabelUseCase
|
|
CommentUseCase() domain.CommentUseCase
|
|
}
|
|
|
|
type uowConfigSource struct{ uw UnitOfWork }
|
|
|
|
// NewUOWConfigSource reads list configuration through an open unit of work.
|
|
func NewUOWConfigSource(uw UnitOfWork) ConfigSource {
|
|
return uowConfigSource{uw: uw}
|
|
}
|
|
|
|
func (p uowConfigSource) GetCustomStatuses(ctx context.Context) ([]types.CustomStatus, error) {
|
|
return p.uw.ConfigUseCase().GetCustomStatuses(ctx)
|
|
}
|
|
func (p uowConfigSource) GetCustomTypes(ctx context.Context) ([]string, error) {
|
|
return p.uw.ConfigUseCase().GetCustomTypes(ctx)
|
|
}
|
|
func (p uowConfigSource) GetInfraTypes(ctx context.Context) (map[string]bool, error) {
|
|
return p.uw.ConfigUseCase().GetInfraTypes(ctx)
|
|
}
|
|
|
|
// LoadListConfig materializes the list configuration from a ConfigSource,
|
|
// falling back to the workspace YAML for custom types the store does not know.
|
|
func LoadListConfig(ctx context.Context, src ConfigSource) (ListConfig, error) {
|
|
var cfg ListConfig
|
|
|
|
statuses, err := src.GetCustomStatuses(ctx)
|
|
if err != nil {
|
|
return cfg, fmt.Errorf("load custom statuses: %w", err)
|
|
}
|
|
cfg.CustomStatuses = statuses
|
|
|
|
ct, err := src.GetCustomTypes(ctx)
|
|
if err != nil {
|
|
return cfg, fmt.Errorf("load custom types: %w", err)
|
|
}
|
|
if len(ct) > 0 {
|
|
cfg.CustomTypes = ct
|
|
} else {
|
|
cfg.CustomTypes = config.GetCustomTypesFromYAML()
|
|
}
|
|
|
|
infraSet, err := src.GetInfraTypes(ctx)
|
|
if err != nil {
|
|
return cfg, fmt.Errorf("load infra types: %w", err)
|
|
}
|
|
if len(infraSet) > 0 {
|
|
cfg.InfraSet = infraSet
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|
|
|
|
// LoadStoreListConfig loads the list configuration from a store handle. A nil
|
|
// store (no workspace open) still yields the YAML custom types.
|
|
func LoadStoreListConfig(ctx context.Context, store storage.DoltStorage) (ListConfig, error) {
|
|
if store == nil {
|
|
return ListConfig{CustomTypes: config.GetCustomTypesFromYAML()}, nil
|
|
}
|
|
return LoadListConfig(ctx, NewStoreConfigSource(store))
|
|
}
|
|
|
|
// LoadUOWListConfig loads the list configuration through an open unit of work.
|
|
func LoadUOWListConfig(ctx context.Context, uw UnitOfWork) (ListConfig, error) {
|
|
return LoadListConfig(ctx, NewUOWConfigSource(uw))
|
|
}
|
|
|
|
// BuildListFilter turns list parameters into the storage-level filter. It is
|
|
// the single definition of what `bd list` means: the closed/done/frozen status
|
|
// exclusions, the pinned and template defaults, and the gate, infra-type, and
|
|
// wisp suppression that make the default listing show durable work only.
|
|
func BuildListFilter(in issueops.ListRequest, cfg ListConfig) (types.IssueFilter, error) {
|
|
// The --ready arm reaches its query through ReadyFilterFromIssueFilter,
|
|
// which carries only part of what this filter can express. A request that
|
|
// asks --ready to honor something the projection drops is refused here,
|
|
// at the one point every frontend and every implementation of
|
|
// issueops.Reader passes through, rather than answered with the wider set.
|
|
// The drop set and the refusal text live beside the promise they enforce,
|
|
// in issueops.
|
|
if err := issueops.ValidateReadyFlagScope(in); err != nil {
|
|
return types.IssueFilter{}, err
|
|
}
|
|
// The pinned pair is a contradiction, refused here rather than in any one
|
|
// frontend so every route agrees: the CLI refuses it at flag parse, and a
|
|
// served listing carries both members (issues.list.filters), where the
|
|
// branch below used to let PinnedFlag win silently.
|
|
if in.PinnedFlag && in.NoPinnedFlag {
|
|
return types.IssueFilter{}, fmt.Errorf("--pinned and --no-pinned are mutually exclusive%.0w", issueops.ErrValidation)
|
|
}
|
|
// The parent pair likewise, in the sentence `bd list` and BuildCountFilter
|
|
// refuse it with: a served listing carries no_parent beside parent
|
|
// (issues.list.filters), and ANDing the two answered only the edge-less
|
|
// rows under the parent's dotted id instead of refusing.
|
|
if in.ParentID != "" && in.NoParent {
|
|
return types.IssueFilter{}, fmt.Errorf("--parent and --no-parent are mutually exclusive%.0w", issueops.ErrValidation)
|
|
}
|
|
|
|
filter := types.IssueFilter{
|
|
Limit: SQLLimit(in),
|
|
// The offset is carried for the callers that consume this filter as a
|
|
// VALUE and run their own query — `bd list --watch` and the proxied
|
|
// hierarchical --parent walk — where the seam beneath them renders it.
|
|
// Both implementations of issueops.Reader take it back off
|
|
// (WithRowsBeforeThePage) and skip in the shared page epilogue instead;
|
|
// FinishPageAt says why the role cannot leave it here.
|
|
Offset: in.Offset,
|
|
SortBy: in.SortBy,
|
|
SortDesc: in.Reverse,
|
|
AfterCreatedAt: in.AfterCreatedAt,
|
|
AfterID: in.AfterID,
|
|
AfterPriority: in.AfterPriority,
|
|
// The defensive cap travels ON the request, so this builder is the
|
|
// only writer of the filter's two cap fields. `bd list` used to stamp
|
|
// them onto the filter after the builder returned, which is the
|
|
// "build it, then reach in and change it" half-step the role exists to
|
|
// make unreachable — and it left the cap invisible to every
|
|
// implementation of Reader.List.
|
|
MaxRows: in.MaxRows,
|
|
MaxRowsSource: in.MaxRowsSource,
|
|
}
|
|
|
|
// The status selector is parsed once here; every consumer below — the
|
|
// "all" short-circuit, the default exclusions, the pinned default —
|
|
// works from the same parts so their readings cannot drift.
|
|
statusParts := splitStatusSelector(in.Status)
|
|
statusAll := len(statusParts) == 1 && statusParts[0] == "all"
|
|
|
|
// --ready defaults to open (the blocker-aware query's historical pin),
|
|
// but an explicit --status is an intersection, not an override. Dropping
|
|
// the selector used to answer `bd list --status X --ready` with the
|
|
// unfiltered ready set (GH#5832). `--status all` is the no-filter
|
|
// spelling, so the open default still applies there.
|
|
if in.ReadyFlag && (len(statusParts) == 0 || statusAll) {
|
|
s := types.StatusOpen
|
|
filter.Status = &s
|
|
} else if len(statusParts) > 0 && !statusAll {
|
|
if err := applyStatusParts(&filter, statusParts, cfg.CustomStatusNames()); err != nil {
|
|
return filter, err
|
|
}
|
|
}
|
|
|
|
if len(statusParts) == 0 && !in.AllFlag && !in.ReadyFlag && !in.PinnedFlag {
|
|
excludeStatuses := []types.Status{types.StatusClosed, types.StatusPinned}
|
|
for _, cs := range cfg.CustomStatuses {
|
|
if cs.Category == types.CategoryDone || cs.Category == types.CategoryFrozen {
|
|
excludeStatuses = append(excludeStatuses, types.Status(cs.Name))
|
|
}
|
|
}
|
|
filter.ExcludeStatus = excludeStatuses
|
|
}
|
|
// The caller's own exclusions (ListRequest.ExcludeStatus) are APPENDED to
|
|
// the defaults above, never in place of them: excluding `blocked` must not
|
|
// re-admit closed rows. They apply on every arm, AllFlag and an explicit
|
|
// Status included, which is what lets a caller drop closed history
|
|
// (AllFlag with ExcludeStatus "closed") without enumerating every status.
|
|
excluded, err := ParseExcludeStatus(in.ExcludeStatus, cfg.CustomStatusNames())
|
|
if err != nil {
|
|
return filter, err
|
|
}
|
|
filter.ExcludeStatus = append(filter.ExcludeStatus, excluded...)
|
|
|
|
if in.Priority != nil {
|
|
p := *in.Priority
|
|
filter.Priority = &p
|
|
}
|
|
if in.Assignee != "" {
|
|
a := in.Assignee
|
|
filter.Assignee = &a
|
|
}
|
|
if in.IssueType != "" {
|
|
t := types.IssueType(in.IssueType)
|
|
if !t.IsValidWithCustom(cfg.CustomTypes) {
|
|
validTypes := "bug, feature, task, epic, chore, decision"
|
|
if len(cfg.CustomTypes) > 0 {
|
|
validTypes += ", " + strings.Join(cfg.CustomTypes, ", ")
|
|
}
|
|
return filter, fmt.Errorf("invalid issue type %q (valid: %s)", in.IssueType, validTypes)
|
|
}
|
|
filter.IssueType = &t
|
|
}
|
|
|
|
if len(in.Labels) > 0 {
|
|
filter.Labels = in.Labels
|
|
}
|
|
if len(in.LabelsAny) > 0 {
|
|
filter.LabelsAny = in.LabelsAny
|
|
}
|
|
if len(in.ExcludeLabels) > 0 {
|
|
filter.ExcludeLabels = in.ExcludeLabels
|
|
}
|
|
if in.LabelPattern != "" {
|
|
filter.LabelPattern = in.LabelPattern
|
|
}
|
|
if in.LabelRegex != "" {
|
|
filter.LabelRegex = in.LabelRegex
|
|
}
|
|
if in.TitleSearch != "" {
|
|
filter.TitleSearch = in.TitleSearch
|
|
}
|
|
if in.IDFilter != "" {
|
|
ids := utils.NormalizeLabels(strings.Split(in.IDFilter, ","))
|
|
if len(ids) > 0 {
|
|
filter.IDs = ids
|
|
}
|
|
}
|
|
if in.SpecPrefix != "" {
|
|
filter.SpecIDPrefix = in.SpecPrefix
|
|
}
|
|
|
|
if in.TitleContains != "" {
|
|
filter.TitleContains = in.TitleContains
|
|
}
|
|
if in.DescContains != "" {
|
|
filter.DescriptionContains = in.DescContains
|
|
}
|
|
if in.NotesContains != "" {
|
|
filter.NotesContains = in.NotesContains
|
|
}
|
|
if in.ExternalContains != "" {
|
|
filter.ExternalRefContains = in.ExternalContains
|
|
}
|
|
if in.ExternalRef != "" {
|
|
filter.ExternalRef = &in.ExternalRef
|
|
}
|
|
|
|
filter.CreatedAfter = in.CreatedAfter
|
|
filter.CreatedBefore = in.CreatedBefore
|
|
filter.UpdatedAfter = in.UpdatedAfter
|
|
filter.UpdatedBefore = in.UpdatedBefore
|
|
filter.ClosedAfter = in.ClosedAfter
|
|
filter.ClosedBefore = in.ClosedBefore
|
|
|
|
if in.EmptyDesc {
|
|
filter.EmptyDescription = true
|
|
}
|
|
if in.NoAssignee {
|
|
filter.NoAssignee = true
|
|
}
|
|
if in.NoLabels {
|
|
filter.NoLabels = true
|
|
}
|
|
if in.SkipLabels {
|
|
filter.SkipLabels = true
|
|
}
|
|
if in.SkipCounts {
|
|
filter.SkipCounts = true
|
|
}
|
|
if in.Brief {
|
|
filter.Lite = true
|
|
}
|
|
|
|
if in.PriorityMin != nil {
|
|
p := *in.PriorityMin
|
|
filter.PriorityMin = &p
|
|
}
|
|
if in.PriorityMax != nil {
|
|
p := *in.PriorityMax
|
|
filter.PriorityMax = &p
|
|
}
|
|
|
|
if in.PinnedFlag {
|
|
pinned := true
|
|
filter.Pinned = &pinned
|
|
} else if in.NoPinnedFlag || (!statusSelectsPinned(statusParts, !in.ReadyFlag) && !in.AllFlag) {
|
|
pinned := false
|
|
filter.Pinned = &pinned
|
|
}
|
|
|
|
applyTypeSuppressions(in, cfg, &filter)
|
|
|
|
for _, raw := range in.ExcludeTypes {
|
|
for _, t := range strings.Split(raw, ",") {
|
|
t = strings.TrimSpace(t)
|
|
if t != "" {
|
|
filter.ExcludeTypes = append(filter.ExcludeTypes, types.IssueType(utils.NormalizeIssueType(t)))
|
|
}
|
|
}
|
|
}
|
|
|
|
if in.ParentID != "" {
|
|
pid := in.ParentID
|
|
filter.ParentID = &pid
|
|
}
|
|
if in.NoParent {
|
|
filter.NoParent = true
|
|
}
|
|
|
|
if in.MolType != nil {
|
|
filter.MolType = in.MolType
|
|
}
|
|
if in.WispType != nil {
|
|
filter.WispType = in.WispType
|
|
}
|
|
|
|
if in.DeferredFlag {
|
|
filter.Deferred = true
|
|
}
|
|
filter.DeferAfter = in.DeferAfter
|
|
filter.DeferBefore = in.DeferBefore
|
|
filter.DueAfter = in.DueAfter
|
|
filter.DueBefore = in.DueBefore
|
|
if in.OverdueFlag {
|
|
filter.Overdue = true
|
|
}
|
|
|
|
if len(in.MetadataFields) > 0 {
|
|
filter.MetadataFields = in.MetadataFields
|
|
}
|
|
if in.HasMetadataKey != "" {
|
|
filter.HasMetadataKey = in.HasMetadataKey
|
|
}
|
|
if err := ValidateMetadataFilters(in.MetadataFields, in.HasMetadataKey); err != nil {
|
|
return filter, err
|
|
}
|
|
|
|
return filter, nil
|
|
}
|
|
|
|
// applyTypeSuppressions applies every default suppression that hides a bead on
|
|
// account of WHAT IT IS, so that a "show everything" frontend has exactly one
|
|
// thing to skip. Two kinds live here: the type-level exclusions that make the
|
|
// default listing show durable work only (templates, gates, infra types), and
|
|
// the plane decision — whether the wisps TABLE is read at all, and for a named
|
|
// infra type whether only its ephemeral rows are.
|
|
//
|
|
// IncludeAllTypes lifts them ALL by skipping this function entirely, which is
|
|
// what makes it future-proof: a suppression added here is automatically lifted
|
|
// for frontends like `bd human list` without touching them.
|
|
func applyTypeSuppressions(in issueops.ListRequest, cfg ListConfig, filter *types.IssueFilter) {
|
|
if in.IncludeAllTypes {
|
|
return
|
|
}
|
|
|
|
if !in.IncludeTemplates {
|
|
isTemplate := false
|
|
filter.IsTemplate = &isTemplate
|
|
}
|
|
|
|
if !in.IncludeGates && in.IssueType != "gate" {
|
|
filter.ExcludeTypes = append(filter.ExcludeTypes, "gate")
|
|
}
|
|
|
|
if !in.IncludeInfra && !cfg.IsInfra(in.IssueType) {
|
|
for _, t := range cfg.InfraTypes() {
|
|
filter.ExcludeTypes = append(filter.ExcludeTypes, types.IssueType(t))
|
|
}
|
|
}
|
|
|
|
// The plane bit. Three requests admit the wisp table: an explicit
|
|
// IncludeEphemeral, IncludeInfra (which admits the plane AND drops the
|
|
// infra-type exclusions above), and naming an infra type (which narrows to
|
|
// its ephemeral rows, below). Everything else is the durable listing.
|
|
// IncludeAllTypes is a fourth, via the early return above — it is the union
|
|
// of these flags, so it must decide the plane too, not only the type
|
|
// exclusions.
|
|
if !in.IncludeEphemeral && !in.IncludeInfra && (in.IssueType == "" || !cfg.IsInfra(in.IssueType)) {
|
|
filter.SkipWisps = true
|
|
}
|
|
|
|
// Naming an infra type narrows the read to its EPHEMERAL rows alone, which
|
|
// is where creating one puts it. IncludeEphemeral lifts that narrowing,
|
|
// because it promises the durable answer PLUS the plane, never the plane
|
|
// instead: an infra-typed row can still be durable — a promoted wisp, an
|
|
// issue retyped after it was created, or one written before its type
|
|
// joined types.infra — and while the narrowing held, `bd search --type
|
|
// message` (whose scope sets the flag) dropped exactly those rows with exit
|
|
// 0. IncludeInfra alone keeps the narrowing, and BuildCountFilter's
|
|
// IncludeInfra arm mirrors both halves (GH#4387).
|
|
if cfg.IsInfra(in.IssueType) && !in.IncludeEphemeral {
|
|
ephemeral := true
|
|
filter.Ephemeral = &ephemeral
|
|
}
|
|
}
|
|
|
|
// splitStatusSelector splits a --status selector into its trimmed
|
|
// comma-separated parts. An empty selector yields nil. This is the only
|
|
// reading of the selector syntax; everything downstream works on the parts.
|
|
func splitStatusSelector(status string) []string {
|
|
if status == "" {
|
|
return nil
|
|
}
|
|
parts := strings.Split(status, ",")
|
|
for i := range parts {
|
|
parts[i] = strings.TrimSpace(parts[i])
|
|
}
|
|
return parts
|
|
}
|
|
|
|
// statusSelectsPinned reports whether a status selector asks for
|
|
// pinned-carrying beads: the pinned or hooked status, or — when the selector
|
|
// actually applies to the query — the "all" selector, which promises every
|
|
// status. The pinned default is not forced off for a filter that asks for
|
|
// those beads. allApplies is false under --ready: `--status all` (and the
|
|
// omitted selector) still pin open, so "all" must not lift the pinned
|
|
// default there. Explicit selectors are honored under --ready (GH#5832);
|
|
// pinned and hooked still return true regardless of allApplies.
|
|
func statusSelectsPinned(parts []string, allApplies bool) bool {
|
|
for _, part := range parts {
|
|
switch part {
|
|
case "pinned", "hooked":
|
|
return true
|
|
case "all":
|
|
if allApplies {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ValidStatusList renders the status names a filter accepts, for error text.
|
|
func ValidStatusList(customStatusNames []string) string {
|
|
validList := "open, in_progress, blocked, deferred, closed, pinned, hooked"
|
|
if len(customStatusNames) > 0 {
|
|
validList += ", " + strings.Join(customStatusNames, ", ")
|
|
}
|
|
return validList
|
|
}
|
|
|
|
// ApplyStatusFilter parses a status selector - one status, or a
|
|
// comma-separated OR set - onto the filter.
|
|
func ApplyStatusFilter(filter *types.IssueFilter, status string, customStatusNames []string) error {
|
|
parts := splitStatusSelector(status)
|
|
if len(parts) == 0 {
|
|
return fmt.Errorf("invalid status %q (valid: %s)", status, ValidStatusList(customStatusNames))
|
|
}
|
|
return applyStatusParts(filter, parts, customStatusNames)
|
|
}
|
|
|
|
func applyStatusParts(filter *types.IssueFilter, parts []string, customStatusNames []string) error {
|
|
if len(parts) == 1 {
|
|
s := types.Status(parts[0])
|
|
if !s.IsValidWithCustom(customStatusNames) {
|
|
return fmt.Errorf("invalid status %q (valid: %s)", parts[0], ValidStatusList(customStatusNames))
|
|
}
|
|
filter.Status = &s
|
|
return nil
|
|
}
|
|
|
|
for _, part := range parts {
|
|
s := types.Status(part)
|
|
if !s.IsValidWithCustom(customStatusNames) {
|
|
// "all" is a real selector on its own (every status), so failing
|
|
// it as merely "invalid" would contradict the flag help. A custom
|
|
// status literally named "all" passes validation above instead.
|
|
if part == "all" {
|
|
return fmt.Errorf(`status "all" cannot be combined with other statuses`)
|
|
}
|
|
return fmt.Errorf("invalid status %q in multi-status filter (valid: %s)", part, ValidStatusList(customStatusNames))
|
|
}
|
|
filter.Statuses = append(filter.Statuses, s)
|
|
}
|
|
return nil
|
|
}
|