All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-frontend (push) Has been skipped
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-go-pg (push) Successful in 2m51s
CI/CD / test-sqlite (push) Successful in 3m1s
CI/CD / build-and-deploy (push) Successful in 1m17s
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
26 lines
722 B
Go
26 lines
722 B
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
// ParseSnapshotStages parses a version snapshot into a slice of
|
|
// WorkflowStage. It handles both the wrapped format
|
|
// {"stages": [...], "workflow": {...}} and the legacy flat array [...].
|
|
func ParseSnapshotStages(raw json.RawMessage) ([]WorkflowStage, error) {
|
|
// Try wrapped format first
|
|
var wrapped struct {
|
|
Stages []WorkflowStage `json:"stages"`
|
|
}
|
|
if err := json.Unmarshal(raw, &wrapped); err == nil && len(wrapped.Stages) > 0 {
|
|
return wrapped.Stages, nil
|
|
}
|
|
// Fallback to flat array
|
|
var stages []WorkflowStage
|
|
if err := json.Unmarshal(raw, &stages); err != nil {
|
|
return nil, fmt.Errorf("corrupt version snapshot: %w", err)
|
|
}
|
|
return stages, nil
|
|
}
|