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.
87 lines
3.1 KiB
Go
87 lines
3.1 KiB
Go
//go:build cgo
|
|
|
|
package embeddeddolt
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
storageissueops "github.com/steveyegge/beads/internal/storage/issueops"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// IssueLifecycle returns the guarded issue-lifecycle surface for this store.
|
|
func (s *EmbeddedDoltStore) IssueLifecycle() (issueops.Lifecycle, error) {
|
|
return NewIssueOperations(s)
|
|
}
|
|
|
|
// NewIssueOperations returns guarded issue operations backed by store.
|
|
func NewIssueOperations(store *EmbeddedDoltStore) (issueops.Lifecycle, error) {
|
|
if store == nil {
|
|
return nil, &storage.ErrUnsupported{Op: "NewIssueOperations", Backend: "nil"}
|
|
}
|
|
return &issueOperations{store: store}, nil
|
|
}
|
|
|
|
type issueOperations struct{ store *EmbeddedDoltStore }
|
|
|
|
// updateCommitMessage names the updated issue in the Dolt commit message.
|
|
func updateCommitMessage(issueID string) string {
|
|
if issueID == "" {
|
|
return "bd: update issue"
|
|
}
|
|
return "bd: update " + issueID
|
|
}
|
|
|
|
func (o *issueOperations) Create(ctx context.Context, request issueops.CreateRequest) (issueops.CreateResult, error) {
|
|
snapshot := storageissueops.CloneCreateRequest(request)
|
|
var result issueops.CreateResult
|
|
err := o.store.runIssueOperationTx(ctx, "bd: create issue", func(tx *sql.Tx) (storageissueops.ChangedTables, error) {
|
|
var err error
|
|
var tables storageissueops.ChangedTables
|
|
result, tables, err = storageissueops.ExecuteCreate(ctx, tx, snapshot)
|
|
return tables, err
|
|
})
|
|
return result, err
|
|
}
|
|
|
|
func (o *issueOperations) Update(ctx context.Context, request issueops.UpdateRequest) (issueops.UpdateResult, error) {
|
|
snapshot := storageissueops.CloneUpdateRequest(request)
|
|
var result issueops.UpdateResult
|
|
// Same ID-bearing commit message as the server-backed store, so `bd dolt
|
|
// log` reads the same on both backends.
|
|
err := o.store.runIssueOperationTx(ctx, updateCommitMessage(snapshot.IssueID), func(tx *sql.Tx) (storageissueops.ChangedTables, error) {
|
|
var err error
|
|
var tables storageissueops.ChangedTables
|
|
result, tables, err = storageissueops.ExecuteUpdate(ctx, tx, snapshot)
|
|
return tables, err
|
|
})
|
|
return result, err
|
|
}
|
|
|
|
func (o *issueOperations) Close(ctx context.Context, request issueops.CloseRequest) (issueops.CloseResult, error) {
|
|
snapshot := storageissueops.CloneCloseRequest(request)
|
|
var result issueops.CloseResult
|
|
err := o.store.runIssueOperationTx(ctx, "bd: close issue", func(tx *sql.Tx) (storageissueops.ChangedTables, error) {
|
|
var err error
|
|
var tables storageissueops.ChangedTables
|
|
result, tables, err = storageissueops.ExecuteClose(ctx, tx, snapshot)
|
|
return tables, err
|
|
})
|
|
return result, err
|
|
}
|
|
|
|
func (o *issueOperations) Reopen(ctx context.Context, request issueops.ReopenRequest) (issueops.ReopenResult, error) {
|
|
snapshot := storageissueops.CloneReopenRequest(request)
|
|
var result issueops.ReopenResult
|
|
err := o.store.runIssueOperationTx(ctx, "bd: reopen issue", func(tx *sql.Tx) (storageissueops.ChangedTables, error) {
|
|
var err error
|
|
var tables storageissueops.ChangedTables
|
|
result, tables, err = storageissueops.ExecuteReopen(ctx, tx, snapshot)
|
|
return tables, err
|
|
})
|
|
return result, err
|
|
}
|
|
|
|
var _ issueops.Lifecycle = (*issueOperations)(nil)
|