···11package models
2233import (
44+ "fmt"
45 "slices"
66+ "strings"
57 "time"
6879 "github.com/bluesky-social/indigo/atproto/syntax"
···5052 }
51535254 return 0
5555+}
5656+5757+// produces short summary of successes:
5858+// - "0/4" when zero successes of 4 workflows
5959+// - "4/4" when all successes of 4 workflows
6060+// - "0/0" when no workflows run in this pipeline
6161+func (p Pipeline) ShortStatusSummary() string {
6262+ counts := make(map[spindle.StatusKind]int)
6363+ for _, w := range p.Statuses {
6464+ counts[w.Latest().Status] += 1
6565+ }
6666+6767+ total := len(p.Statuses)
6868+ successes := counts[spindle.StatusKindSuccess]
6969+7070+ return fmt.Sprintf("%d/%d", successes, total)
7171+}
7272+7373+// produces a string of the form "3/4 success, 2/4 failed, 1/4 pending"
7474+func (p Pipeline) LongStatusSummary() string {
7575+ counts := make(map[spindle.StatusKind]int)
7676+ for _, w := range p.Statuses {
7777+ counts[w.Latest().Status] += 1
7878+ }
7979+8080+ total := len(p.Statuses)
8181+8282+ var result []string
8383+ // finish states first, followed by start states
8484+ states := append(spindle.FinishStates[:], spindle.StartStates[:]...)
8585+ for _, state := range states {
8686+ if count, ok := counts[state]; ok {
8787+ result = append(result, fmt.Sprintf("%d/%d %s", count, total, state.String()))
8888+ }
8989+ }
9090+9191+ return strings.Join(result, ", ")
5392}
54935594func (p Pipeline) Counts() map[string]int {
+7-17
appview/models/pull.go
···171171 return syntax.ATURI(p.CommentAt)
172172}
173173174174-// func (p *PullComment) AsRecord() tangled.RepoPullComment {
175175-// mentions := make([]string, len(p.Mentions))
176176-// for i, did := range p.Mentions {
177177-// mentions[i] = string(did)
178178-// }
179179-// references := make([]string, len(p.References))
180180-// for i, uri := range p.References {
181181-// references[i] = string(uri)
182182-// }
183183-// return tangled.RepoPullComment{
184184-// Pull: p.PullAt,
185185-// Body: p.Body,
186186-// Mentions: mentions,
187187-// References: references,
188188-// CreatedAt: p.Created.Format(time.RFC3339),
189189-// }
190190-// }
174174+func (p *Pull) TotalComments() int {
175175+ total := 0
176176+ for _, s := range p.Submissions {
177177+ total += len(s.Comments)
178178+ }
179179+ return total
180180+}
191181192182func (p *Pull) LastRoundNumber() int {
193183 return len(p.Submissions) - 1