Files
archie/internal/domain/workflow/finish_step.go
T
sam ca4b039cb4 feat(workflow): serve step type titles with the step vocabulary (#1961)
Each step type declares its title beside its factory and settings; the
control plane serves it in x-step-types, and the dashboard reads it instead
of a hand-written TYPE_TITLES table. Parallel and switch are YAML shapes, not
registered types, so their titles stay with the graph.
2026-11-13 20:26:27 +11:00

48 lines
1.5 KiB
Go

package workflow
import (
"context"
"fmt"
"gopkg.in/yaml.v3"
)
// FinishStepName is the step type that ends the workflow with a chosen outcome.
const FinishStepName = "workflow.finish"
// finishStatuses are the outcomes a workflow.finish step may choose.
var finishStatuses = map[string]string{
"completed": StatusCompleted,
"parked": StatusParked,
"waiting_approval": StatusWaitingApproval,
"declined": StatusClosedWontDo,
}
type finishSettings struct {
Status string `yaml:"status" enum:"completed,parked,waiting_approval,declined" doc:"How the run ends. Empty means completed."`
Detail string `yaml:"detail" doc:"What the operator reads about the outcome."`
}
// FinishStepType contributes the workflow.finish step type.
func FinishStepType() StepType {
return StepType{Name: FinishStepName, Title: "Finish", Factory: newFinishStage, Settings: finishSettings{}}
}
func newFinishStage(settings yaml.Node) (Stage, error) {
s, err := decodeSettings[finishSettings](FinishStepName, settings)
if err != nil {
return Stage{}, err
}
if s.Status == "" {
s.Status = "completed"
}
status, ok := finishStatuses[s.Status]
if !ok {
return Stage{}, fmt.Errorf("%s: settings.status is completed, parked, waiting_approval or declined, not %q", FinishStepName, s.Status)
}
return Stage{Name: FinishStepName, Run: func(_ context.Context, tc *TaskContext) error {
tc.Outcome = Outcome{Status: status, Detail: s.Detail}
return nil
}}, nil
}