From 73d562aade427b304bdba58450d5156134e35237 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Tue, 16 Dec 2025 03:52:38 +0000 Subject: [PATCH] appview/models,appview/pages: refactor pipeline summary component move most of the logic from the html template into golang. this is just much more predictable. also add a short and long form summary. --- appview/models/pipeline.go | 38 ++++++++++++++++++++++++++++++++++++++ appview/pages/templates/repo/pipelines/fragments/pipelineSymbol.html | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------- appview/pages/templates/repo/pipelines/fragments/pipelineSymbolLong.html | 2 +- 3 file(s) changed, 99 insertion(s)(+), 70 deletion(s)(-) diff --git a/appview/models/pipeline.go b/appview/models/pipeline.go --- a/appview/models/pipeline.go +++ b/appview/models/pipeline.go @@ -3,6 +3,7 @@ import ( "fmt" "slices" + "strings" "time" "github.com/bluesky-social/indigo/atproto/syntax" @@ -56,6 +57,43 @@ } return 0 +} + +// produces short summary of successes: +// - "0/4" when zero successes of 4 workflows +// - "4/4" when all successes of 4 workflows +// - "0/0" when no workflows run in this pipeline +func (p Pipeline) ShortStatusSummary() string { + counts := make(map[spindle.StatusKind]int) + for _, w := range p.Statuses { + counts[w.Latest().Status] += 1 + } + + total := len(p.Statuses) + successes := counts[spindle.StatusKindSuccess] + + return fmt.Sprintf("%d/%d", successes, total) +} + +// produces a string of the form "3/4 success, 2/4 failed, 1/4 pending" +func (p Pipeline) LongStatusSummary() string { + counts := make(map[spindle.StatusKind]int) + for _, w := range p.Statuses { + counts[w.Latest().Status] += 1 + } + + total := len(p.Statuses) + + var result []string + // finish states first, followed by start states + states := append(spindle.FinishStates[:], spindle.StartStates[:]...) + for _, state := range states { + if count, ok := counts[state]; ok { + result = append(result, fmt.Sprintf("%d/%d %s", count, total, state.String())) + } + } + + return strings.Join(result, ", ") } func (p Pipeline) Counts() map[string]int { diff --git a/appview/pages/templates/repo/pipelines/fragments/pipelineSymbol.html b/appview/pages/templates/repo/pipelines/fragments/pipelineSymbol.html --- a/appview/pages/templates/repo/pipelines/fragments/pipelineSymbol.html +++ b/appview/pages/templates/repo/pipelines/fragments/pipelineSymbol.html @@ -1,74 +1,65 @@ {{ define "repo/pipelines/fragments/pipelineSymbol" }} -
- {{ $c := .Counts }} - {{ $statuses := .Statuses }} - {{ $total := len $statuses }} - {{ $success := index $c "success" }} - {{ $fail := index $c "failed" }} - {{ $timeout := index $c "timeout" }} - {{ $empty := eq $total 0 }} - {{ $allPass := eq $success $total }} - {{ $allFail := eq $fail $total }} - {{ $allTimeout := eq $timeout $total }} - - {{ if $empty }} -
- {{ i "hourglass" "size-4 text-gray-600 dark:text-gray-400 " }} - 0/{{ $total }} -
- {{ else if $allPass }} -
- {{ i "check" "size-4 text-green-600" }} - {{ $total }}/{{ $total }} -
- {{ else if $allFail }} -
- {{ i "x" "size-4 text-red-500" }} - 0/{{ $total }} -
- {{ else if $allTimeout }} -
- {{ i "clock-alert" "size-4 text-orange-500" }} - 0/{{ $total }} -
+
+ {{ template "symbol" .Pipeline }} + {{ if .ShortSummary }} + {{ .Pipeline.ShortStatusSummary }} {{ else }} - {{ $radius := f64 8 }} - {{ $circumference := mulf64 2.0 (mulf64 3.1416 $radius) }} - {{ $offset := 0.0 }} -
- - - - {{ range $kind, $count := $c }} - {{ $color := "" }} - {{ if or (eq $kind "pending") (eq $kind "running") }} - {{ $color = "#eab308" }} {{/* amber-500 */}} - {{ else if eq $kind "success" }} - {{ $color = "#10b981" }} {{/* green-500 */}} - {{ else if eq $kind "cancelled" }} - {{ $color = "#6b7280" }} {{/* gray-500 */}} - {{ else if eq $kind "timeout" }} - {{ $color = "#fb923c" }} {{/* orange-400 */}} - {{ else }} - {{ $color = "#ef4444" }} {{/* red-500 for failed or unknown */}} - {{ end }} - - {{ $percent := divf64 (f64 $count) (f64 $total) }} - {{ $length := mulf64 $percent $circumference }} - - - {{ $offset = addf64 $offset $length }} - {{ end }} - - {{ $success }}/{{ $total }} -
+ {{ .Pipeline.LongStatusSummary }} {{ end }}
+{{ end }} + +{{ define "symbol" }} + {{ $c := .Counts }} + {{ $statuses := .Statuses }} + {{ $total := len $statuses }} + {{ $success := index $c "success" }} + {{ $fail := index $c "failed" }} + {{ $timeout := index $c "timeout" }} + {{ $empty := eq $total 0 }} + {{ $allPass := eq $success $total }} + {{ $allFail := eq $fail $total }} + {{ $allTimeout := eq $timeout $total }} + + {{ if $empty }} + {{ i "hourglass" "size-4 text-gray-600 dark:text-gray-400 " }} + {{ else if $allPass }} + {{ i "check" "size-4 text-green-600 dark:text-green-500" }} + {{ else if $allFail }} + {{ i "x" "size-4 text-red-600 dark:text-red-500" }} + {{ else if $allTimeout }} + {{ i "clock-alert" "size-4 text-orange-500" }} + {{ else }} + {{ $radius := f64 8 }} + {{ $circumference := mulf64 2.0 (mulf64 3.1416 $radius) }} + {{ $offset := 0.0 }} + + + {{ range $kind, $count := $c }} + {{ $colorClass := "" }} + {{ if or (eq $kind "pending") (eq $kind "running") }} + {{ $colorClass = "stroke-yellow-600 dark:stroke-yellow-500" }} + {{ else if eq $kind "success" }} + {{ $colorClass = "stroke-green-600 dark:stroke-green-500" }} + {{ else if eq $kind "cancelled" }} + {{ $colorClass = "stroke-gray-600 dark:stroke-gray-500" }} + {{ else if eq $kind "timeout" }} + {{ $colorClass = "stroke-orange-600 dark:stroke-orange-500" }} + {{ else }} + {{ $colorClass = "stroke-red-600 dark:stroke-red-500" }} + {{ end }} + {{ $percent := divf64 (f64 $count) (f64 $total) }} + {{ $length := mulf64 $percent $circumference }} + + {{ $offset = addf64 $offset $length }} + {{ end }} + + {{ end }} {{ end }} diff --git a/appview/pages/templates/repo/pipelines/fragments/pipelineSymbolLong.html b/appview/pages/templates/repo/pipelines/fragments/pipelineSymbolLong.html --- a/appview/pages/templates/repo/pipelines/fragments/pipelineSymbolLong.html +++ b/appview/pages/templates/repo/pipelines/fragments/pipelineSymbolLong.html @@ -4,7 +4,7 @@
- {{ template "repo/pipelines/fragments/pipelineSymbol" .Pipeline }} + {{ template "repo/pipelines/fragments/pipelineSymbol" (dict "Pipeline" $pipeline "ShortSummary" true) }} {{ template "repo/pipelines/fragments/tooltip" $ }}
-- tangled.sh