STORAGE LAYER ONLY, per CONTRIBUTING_PR_GUIDELINES.md. issueops.ListRequest and issueops.ReadyRequest gain Brief; no CLI flag and no HTTP parameter sets it yet, so no front door's payload changes. The wiring stacks on top. WHAT IT DROPS is the free-form text: description, design, acceptance_criteria, notes, payload and waiters are not selected, and the row comes back carrying types.Issue.IsLitePartial. #5546 measured a 16,051-issue store where `bd ready --json` returned 454,021 bytes and notes plus description were 76% of it, on the call an agent makes to decide what to work on. Measured through issueops.Reader on 100 rows sized from those per-row ratios: 362,301 bytes full, 24,001 brief, a 93.4% reduction. THE PRIMITIVE WAS HALF-BUILT AND UNREACHABLE. #3906 landed types.IssueFilter.Lite, IssueSelectColumnsLite, HeavyDropList, ScanIssueLiteFrom and Issue.IsLitePartial, then wired filter.Lite into exactly one place: SearchIssuesInTx, the UNCOUNTED store-backed search. Every read that answers with IssueWithCounts, which is every --json route of both commands, both implementations of issueops.Reader, and both HTTP reads, runs the counts mega-query instead and ignored the field. A request that set it would have come back correct, fully hydrated, and with nothing on it to say the projection had not happened. That silent no-op is what this closes. THE APPLICATION POINT IS THE COUNTS MEGA-QUERY, and it is one point rather than four because sqlbuild.SearchCountsSQL and issueops.ScanReadyWorkRowWithCounts are already the pair every counted read passes through: the store seam's list (search_counts.go) and ready (ready_work_counts.go), and the unit-of-work seam's list (issue_search_counts.go) and ready (ready_work_union.go, via fetchCountsByIDs). sqlbuild.CountsHydration is already the value that carries hydration opt-outs across that pair on both seams, so Lite is a third field on it rather than a new channel. IT CHANGES THE PROJECTION'S SHAPE, which SkipLabels and SkipCounts do not, and that is why ScanReadyWorkRowWithCounts now takes the whole hydration instead of a bool: the value that chose the SELECT list is the value that drives the scan, so the two cannot be given different answers. Substituting empty strings in the heavy positions would have kept one scan path and was rejected, because the row would carry blank text with IsLitePartial=false, which is indistinguishable from a genuinely textless row, the ambiguity ga-clgh and CommentsOmitted already record. WHERE IS INDEPENDENT OF SELECT, so this bounds the size of a row and never which rows match: DescContains, NotesContains and EmptyDesc keep selecting exactly what they select today, and no sort key, keyset cursor or wisp-merge dedup reads a dropped column (CompareIssuesBy orders on nine fields, none of them heavy). THE CLAIM REFUSES IT, which is not the same call the page makes and is the sharper case of the rule Limit and Offset already state. A claim does not read its row through the page's query at all: ExecuteClaimNext refetches the winning row whole with GetIssueInTx and hydrates its counts itself, so the projection has nothing to apply to. Accepting the field would answer a MUTATING request with a fully hydrated row carrying IsLitePartial=false, the caller's one signal that it did not get what it asked for, reporting that it did. The check lives in issueops.ValidateClaimNextRequest, which is the shared rule both ready claimers and BatchCloser's claim already run, so all four backends refuse it on the same line. BuildReadyCountFilter CARRIES it, which is the opposite treatment and the opposite reason. A count reads no field of any row, so the projection cannot make the number wrong, and the count is not always cheap enough for that to be the end of it: the unit-of-work seam has no COUNT(*) over the ready predicate and sizes the set by running the unbounded page and taking its length (uow/ready_counter.go), so dropping the field there would hydrate every heavy column of the whole ready set to answer `bd ready --brief`, a larger read than the page it was asked for. Carrying it also keeps that builder what its doc says it is: the listing's filter with the PAGE removed and nothing else. TWO ASYMMETRIES on the page path, both deliberate and both stated in code: - Brief IS carried onto the --ready arm (ReadyFilterFromIssueFilter) where SkipLabels and SkipCounts are dropped. Those two hide a number the ready renderings print; this drops a body no listing prints, so carrying it is what makes `bd list --ready` and `bd ready` answer one request one way. - types.WorkFilter carries Lite and neither of the other two, so the ready paths get readyHydrationFor rather than hydrationFor. Before this, both uow ready call sites passed a hardcoded CountsHydration{}, a literal that could not carry a filter's answer at all, which is how that path would have been missed. CONFORMANCE at all four registered sites, one Test per case, for the two page cases and for the claim refusal. Every field the cases assert stripped is seeded heavy first and the premise is checked, so a backend that never round-trips one of the six fails loudly instead of turning that clause into one that cannot fail. Identity is asserted too (ID, Title, Status, IssueType, Priority), or a body that stripped the row to its id would satisfy every emptiness clause. IsLitePartial is asserted in both directions. THE LITE COLUMN LIST IS PINNED BY ORDER, not only by membership. Both lists are scanned positionally, so two columns of the same SQL type can be transposed with no membership change at all: the pre-existing set-based parity test stays green, the scan succeeds, and every row silently carries one column's value in another's field. TestIssueSelectColumnsLite_IsFullMinusHeavyInOrder derives the expected list by deleting HeavyDropList from IssueSelectColumns in place, which makes the lite list a derivation rather than a second hand-maintained copy. RED BEFORE GREEN, five sabotages, each verified and reverted: - deleting the lite branch from CountsHydration.IssueColumns fails both page cases with "expected 58 destination arguments in Scan, not 52"; - accepting Brief without plumbing it to either filter, the silent no-op this change exists to close, fails both page cases on all six text fields and on IsLitePartial, which is the run that proves the assertions are load-bearing; - transposing created_by and owner in IssueSelectColumnsLite fails only the new order test, on IssueSelectColumnsLite[9] = owner, want created_by, while the set-based test stays green, which is the gap it was added for; - dropping the claim's refusal fails the claimer contract with "ClaimNext with brief: error = <nil>, want ErrValidation"; and - clearing Brief in BuildReadyCountFilter fails TestBuildReadyCountFilterIsTheUnboundedReadyFilter, which already existed to catch a ReadyRequest field the count builder forgets to carry and gains Brief in its fixture here. The recorded ready-filter golden gains "Lite": false in 62 cases because types.WorkFilter gained the field and the test compares marshaled JSON byte-for-byte. False is what a request that did not ask for the projection resolves that field to, so the replay stays exact; the test comment says so. Gates: go build ./..., go vet ./..., gofmt, internal/storage/... (dolt, embeddeddolt with BEADS_TEST_EMBEDDED_DOLT=1, uow, issueops, sqlbuild, domain/db), internal/workapi/..., backend/conformance/..., issueops/..., make api-check. Refs: #5546, #3906 Co-authored-by: sjarmak <t@t.co>
527 lines
17 KiB
Go
527 lines
17 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
|
|
}
|
|
|
|
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,
|
|
// 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"
|
|
|
|
if in.ReadyFlag {
|
|
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
|
|
}
|
|
|
|
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 cfg.IsInfra(in.IssueType) {
|
|
ephemeral := true
|
|
filter.Ephemeral = &ephemeral
|
|
}
|
|
|
|
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.
|
|
//
|
|
// 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 routed to
|
|
// the plane alone in BuildListFilter). 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
|
|
}
|
|
}
|
|
|
|
// 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, which forces status open
|
|
// and otherwise ignores the selector, so "all" must not lift the pinned
|
|
// default there.
|
|
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
|
|
}
|