Label to workflow rules and a default workflow are the intake-routes resource: ordered, case-insensitive, first rule wins, seeded with bug to tdd, feature to feasibility, default triage. A write naming an undefined workflow or an empty label is refused. The daemon reads it through the workflow definitions client when pinning a task and at intake. The kind indirection only carried this routing, so it is removed: the per-kind NATS subjects (every consumer already bound archie.task.>) are one subject, the envelope and playbook triggers lose their kind, and x-intake-routes is dropped. The dashboard gets an Issue routing page under Automation; the trigger card reads the same setting.
73 lines
2.5 KiB
Go
73 lines
2.5 KiB
Go
package controlplanestore
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"maps"
|
|
"slices"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
)
|
|
|
|
const WorkflowDefinitionsKind = "workflow-definitions"
|
|
|
|
// stepRegistry returns the step vocabulary from the injected manager.
|
|
func stepRegistry(steps *workflow.Manager) (workflow.StepRegistry, error) {
|
|
if steps == nil {
|
|
return nil, errors.New("control plane: no workflow step vocabulary: the composition root must register the provider set (infrastructure/workflowsteps.NewManager) before the first resolution")
|
|
}
|
|
return steps.Registry(), nil
|
|
}
|
|
|
|
func workflowDefinitionsDefinition(steps workflow.StepRegistry, types map[string]workflow.StepType) Definition {
|
|
return Definition{
|
|
Kind: WorkflowDefinitionsKind,
|
|
Title: "Workflow definitions",
|
|
Document: workflow.WorkflowDefinitionCollection{},
|
|
ApplyMode: "live",
|
|
Seed: func(config.Config) any {
|
|
return workflow.ShippedDefinitions()
|
|
},
|
|
Defaults: func() any {
|
|
return workflow.ShippedDefinitions()
|
|
},
|
|
Validate: func(input []byte) error {
|
|
_, err := workflow.DecodeDefinitionCollection(input, steps)
|
|
return err
|
|
},
|
|
Repair: func(stored []byte) ([]byte, []string, error) {
|
|
collection, removed, err := workflow.RepairDefinitionCollection(stored, steps)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
value, err := json.Marshal(collection)
|
|
return value, removed, err
|
|
},
|
|
SchemaExtensions: map[string]any{"x-step-types": stepTypeVocabulary(steps, types)},
|
|
}
|
|
}
|
|
|
|
// stepTypeVocabulary is the registered step types as the dashboard editor
|
|
// reads them: each name, title, whether it needs a repository, and the schema
|
|
// of its settings (absent for a step that takes none).
|
|
func stepTypeVocabulary(steps workflow.StepRegistry, types map[string]workflow.StepType) []map[string]any {
|
|
vocabulary := make([]map[string]any, 0, len(steps))
|
|
for _, name := range slices.Sorted(maps.Keys(steps)) {
|
|
entry := map[string]any{"name": name, "title": types[name].Title, "needs_repository": workflow.NeedsRepository(name)}
|
|
if schema := settingsSchema(types[name].Settings); schema != nil {
|
|
entry["settings"] = schema
|
|
}
|
|
vocabulary = append(vocabulary, entry)
|
|
}
|
|
return vocabulary
|
|
}
|
|
|
|
func encodeWorkflowDefinitions(collection workflow.WorkflowDefinitionCollection, steps workflow.StepRegistry) ([]byte, error) {
|
|
if err := workflow.ValidateDefinitionCollection(collection, steps); err != nil {
|
|
return nil, fmt.Errorf("%w: %w", ErrValidation, err)
|
|
}
|
|
return json.Marshal(collection)
|
|
}
|