generated from mathias/template-go-web
A strip of the last 12 runs (aggregate pass/fail/running per run) below the substrate ribbon, coloured, newest-first, run # on hover. Parsed from the same Gitea /actions/tasks fetch (RecentRuns, test-first; State refactored to share the aggregate). No new RBAC. Hidden when no live data. Verified: build/vet/lint(0)/test green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
69 lines
1.9 KiB
Go
69 lines
1.9 KiB
Go
package atlas
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
// Host is a substrate machine/entry (koala, iguana, …).
|
|
type Host struct {
|
|
Name string `json:"n"`
|
|
Spec string `json:"k"`
|
|
}
|
|
|
|
// Node is a card within a stage.
|
|
type Node struct {
|
|
Title string `json:"t"`
|
|
Desc string `json:"d,omitempty"`
|
|
Pill string `json:"pill,omitempty"`
|
|
Cls string `json:"cls,omitempty"`
|
|
Tags []string `json:"tags,omitempty"`
|
|
Risk bool `json:"risk,omitempty"`
|
|
Gate bool `json:"gate,omitempty"`
|
|
}
|
|
|
|
// Stage is one column of the pipeline. When Generate is set, its Nodes are
|
|
// derived from a source at Build time rather than taken from the authored data.
|
|
type Stage struct {
|
|
No string `json:"no"`
|
|
Title string `json:"title"`
|
|
Path string `json:"path,omitempty"`
|
|
Cls string `json:"cls,omitempty"`
|
|
Generate string `json:"generate,omitempty"`
|
|
Nodes []Node `json:"nodes"`
|
|
}
|
|
|
|
// Atlas is the full data model the frontend renders.
|
|
type Atlas struct {
|
|
Version string `json:"version,omitempty"`
|
|
Substrate []Host `json:"substrate"`
|
|
NS string `json:"ns,omitempty"`
|
|
Timeline []RunDot `json:"timeline,omitempty"`
|
|
Stages []Stage `json:"stages"`
|
|
}
|
|
|
|
// Build unmarshals the authored atlas JSON and overlays generated facts from
|
|
// real sources, so sourced parts can't drift. Currently: any stage marked
|
|
// `"generate":"ci-jobs"` gets its Nodes replaced by the workflow's job list.
|
|
func Build(atlasJSON, workflow []byte) (Atlas, error) {
|
|
var a Atlas
|
|
if err := json.Unmarshal(atlasJSON, &a); err != nil {
|
|
return Atlas{}, fmt.Errorf("parse atlas data: %w", err)
|
|
}
|
|
for i := range a.Stages {
|
|
if a.Stages[i].Generate != "ci-jobs" {
|
|
continue
|
|
}
|
|
jobs, err := JobsFromWorkflow(workflow)
|
|
if err != nil {
|
|
return Atlas{}, fmt.Errorf("stage %s: %w", a.Stages[i].No, err)
|
|
}
|
|
nodes := make([]Node, 0, len(jobs))
|
|
for _, j := range jobs {
|
|
nodes = append(nodes, Node{Title: j})
|
|
}
|
|
a.Stages[i].Nodes = nodes
|
|
}
|
|
return a, nil
|
|
}
|