Adds issueops.Lifecycle — Create, Update, Close, Reopen — reached from the storage handle via store.IssueLifecycle(), implemented once and shared by the CLI and linked library consumers. Three backends implement it and a shared conformance suite asserts them against one spec. The bd CLI's create, update, close and reopen now route through it. Fixes several defects that predate this change and became visible once the write paths were forced to agree: swallowed metadata-edit failures, a claim applied before field validation, missing value validation on title/priority/estimate, silently dropped create edges to missing targets, infra-typed creates landing in the wrong table, a dropped SourceRepo, closed_by_session written but never read, and a compound update writing twice. Behavior changes needing release notes: create with an occupied explicit id now fails instead of silently overwriting; a compound update is one atomic operation with one hook and one version commit; reparenting replaces all parent edges; reopening something not closed reports nothing to do.
37 lines
1.5 KiB
Go
37 lines
1.5 KiB
Go
package storage
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// CreatePublicCreateDependencies returns the dependency snapshot described by
|
|
// a public create request after its issue ID is known.
|
|
//
|
|
// It is derived from the request rather than from the created issue because a
|
|
// reverse edge is not an outgoing edge of the new issue: it belongs to the
|
|
// target, whose own hooks still need to see it.
|
|
func CreatePublicCreateDependencies(issueID string, request issueops.CreateRequest) []*types.Dependency {
|
|
dependencies := make([]*types.Dependency, 0, len(request.Dependencies)+2)
|
|
if request.ParentID != "" {
|
|
dependencies = append(dependencies, &types.Dependency{IssueID: issueID, DependsOnID: request.ParentID, Type: types.DepParentChild})
|
|
}
|
|
if request.WaitsFor != nil {
|
|
gate := request.WaitsFor.Gate
|
|
if gate == "" {
|
|
gate = types.WaitsForAllChildren
|
|
}
|
|
metadata, _ := json.Marshal(types.WaitsForMeta{Gate: gate})
|
|
dependencies = append(dependencies, &types.Dependency{IssueID: issueID, DependsOnID: request.WaitsFor.SpawnerID, Type: types.DepWaitsFor, Metadata: string(metadata)})
|
|
}
|
|
for _, dependency := range request.Dependencies {
|
|
source, target := issueID, dependency.TargetID
|
|
if dependency.Reverse {
|
|
source, target = target, issueID
|
|
}
|
|
dependencies = append(dependencies, &types.Dependency{IssueID: source, DependsOnID: target, Type: dependency.Type, Metadata: dependency.Metadata, ThreadID: dependency.ThreadID})
|
|
}
|
|
return dependencies
|
|
}
|