BlueGit

timfa bluegit

Files

bluegit / internal / server / pipeline_page.go

pipeline_page.go

fix: start per sha geen dubbele push- en mr-pipeline
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
Passed 6a8f3828 History
pipeline_page.go 19.3 KiB Download Raw
1package server
2
3import (
4 "bytes"
5 "encoding/json"
6 "net/http"
7 "net/url"
8 "strconv"
9 "strings"
10 "time"
11
12 "gitlab.com/Timfa/bluegit/internal/access"
13 "gitlab.com/Timfa/bluegit/internal/ci"
14 "gitlab.com/Timfa/bluegit/internal/i18n"
15 "gitlab.com/Timfa/bluegit/internal/store"
16)
17
18// PipeRow is één rij in het pipeline-overzicht.
19type PipeRow struct {
20 ID int64
21 Status string
22 Label string
23 Duration string
24 When string
25 Title string
26 SHA string
27 Short string
28 Ref string
29 RefKind string
30 Source string
31 SourceLabel string
32 MRNumber int64
33 Actor string
34 Avatar string
35 Initial string
36 Stages []StageView
37}
38
39// StageView is één bolletje in de stages-kolom.
40type StageView struct {
41 Name string
42 Status string
43 Label string
44 Tip string
45 Jobs []JobLink
46}
47
48// JobLink is een job in een stage-popover of in de zijbalk.
49type JobLink struct {
50 ID int64
51 Name string
52 Status string
53 Label string
54 Queue string
55 Current bool
56 Stage string
57}
58
59// JobPage is de console van één job.
60type JobPage struct {
61 Job store.Job
62 Pipe store.Pipeline
63 Name string
64 Status string
65 Label string
66 Actor string
67 Avatar string
68 Initial string
69 When string
70 Duration string
71 Finished string
72 Queued string
73 Timeout string
74 Source string
75 Ref string
76 RefKind string
77 Short string
78 Title string
79 Stage string
80 PipeStatus string
81 PipeLabel string
82 Stages []string
83 Related []JobLink
84 Blocks []LogBlock
85 Running bool
86 LogBytes int
87 CanPlay bool
88 Environment string
89 EnvironmentURL string
90 EnvironmentLink string
91 Queue string
92}
93
94// LogBlock is een losse regel of een inklapbare sectie.
95type LogBlock struct {
96 Section bool
97 Title string
98 Duration string
99 Open bool
100 Lines []LogLine
101}
102
103// LogLine is één regel in de console.
104type LogLine struct {
105 N int
106 Time string
107 Text string
108 Spans []LogSpan
109}
110
111func (s *Server) fillPipelines(r *http.Request, v *View, repo store.Repo) {
112 lang := s.langOf(r)
113 list, _ := s.Store.ListPipelines(r.Context(), repo.ID)
114 q := strings.ToLower(strings.TrimSpace(r.URL.Query().Get("q")))
115 v.Query = r.URL.Query().Get("q")
116 ranks := s.queueRanks(r.Context())
117 users := map[string]store.User{}
118 for _, p := range list {
119 row := s.pipeRow(r, lang, repo, p, users, ranks)
120 if q != "" && !pipeMatches(row, q) {
121 continue
122 }
123 if rowLive(row) {
124 v.Live = true
125 }
126 v.PipeRows = append(v.PipeRows, row)
127 }
128 v.LiveURL = repoURL(repo) + "/-/pipelines"
129 if raw := strings.TrimSpace(r.URL.Query().Get("q")); raw != "" {
130 v.LiveURL += "?q=" + url.QueryEscape(raw)
131 }
132}
133
134func rowLive(row PipeRow) bool {
135 if row.Status == "pending" || row.Status == "running" {
136 return true
137 }
138 for _, st := range row.Stages {
139 if st.Status == "pending" || st.Status == "running" {
140 return true
141 }
142 for _, j := range st.Jobs {
143 if j.Status == "pending" || j.Status == "running" {
144 return true
145 }
146 }
147 }
148 return false
149}
150
151func (s *Server) pipeRow(r *http.Request, lang i18n.Lang, repo store.Repo, p store.Pipeline, users map[string]store.User, ranks map[int64]int) PipeRow {
152 jobs, _ := s.Store.JobsByPipeline(r.Context(), p.ID)
153 name, kind := ci.SplitRef(p.Ref)
154 status := displayStatus(p.Status, jobs)
155 actor, avatar := s.actorOf(r, p.Actor, users)
156 initial := ""
157 if actor != "" {
158 initial = strings.ToUpper(actor[:1])
159 }
160 sourceLabel, mrNumber := s.pipelineSourceLabel(r, repo, p)
161 return PipeRow{
162 ID: p.ID, Status: status, Label: s.tr(r, "pipe."+status),
163 Duration: pipelineClock(p), When: i18n.Ago(lang, p.CreatedAt.Unix()),
164 Title: p.CommitTitle, SHA: p.CommitSHA, Short: shortSHA(p.CommitSHA),
165 Ref: name, RefKind: kind, Source: p.Source, SourceLabel: sourceLabel, MRNumber: mrNumber,
166 Actor: actor, Avatar: avatar, Initial: initial,
167 Stages: stageViews(jobs, ranks, func(key string, args ...any) string { return s.tr(r, key, args...) }),
168 }
169}
170
171// pipelineSourceLabel benoemt een pipeline die bij een merge request hoort,
172// ook wanneer de rij als push is gestart en daarna gekoppeld is.
173// Een gewone push zonder merge request krijgt geen extra label.
174func (s *Server) pipelineSourceLabel(r *http.Request, repo store.Repo, p store.Pipeline) (string, int64) {
175 if p.MRID != 0 {
176 var number int64
177 if mr, err := s.Store.MergeRequest(r.Context(), repo.ID, p.MRID); err == nil {
178 number = mr.Number
179 }
180 return s.tr(r, "pipe.src.merge_request_event"), number
181 }
182 if p.Source == "" || p.Source == "push" {
183 return "", 0
184 }
185 key := "pipe.src." + p.Source
186 label := s.tr(r, key)
187 if label == key {
188 label = p.Source
189 }
190 return label, 0
191}
192
193func (s *Server) pipelineSourceText(r *http.Request, repo store.Repo, p store.Pipeline) string {
194 label, number := s.pipelineSourceLabel(r, repo, p)
195 if label == "" {
196 return ""
197 }
198 if number == 0 {
199 return label
200 }
201 return label + " !" + strconv.FormatInt(number, 10)
202}
203
204func (s *Server) actorOf(r *http.Request, name string, cache map[string]store.User) (string, string) {
205 name = strings.TrimSpace(name)
206 if name == "" {
207 return "", ""
208 }
209 u, ok := cache[name]
210 if !ok {
211 found, err := s.Store.UserByUsername(r.Context(), name)
212 if err == nil {
213 u = found
214 }
215 cache[name] = u
216 }
217 if u.ID == 0 {
218 return name, ""
219 }
220 return u.Username, u.AvatarURL
221}
222
223func pipeMatches(row PipeRow, q string) bool {
224 bits := []string{row.Label, row.Title, row.SHA, row.Short, row.Ref, row.Actor, row.SourceLabel, strconv.FormatInt(row.ID, 10), row.Status}
225 for _, st := range row.Stages {
226 bits = append(bits, st.Name)
227 for _, j := range st.Jobs {
228 bits = append(bits, j.Name)
229 }
230 }
231 for _, b := range bits {
232 if strings.Contains(strings.ToLower(b), q) {
233 return true
234 }
235 }
236 return false
237}
238
239func displayStatus(pipe string, jobs []store.Job) string {
240 switch pipe {
241 case "failed":
242 return "failed"
243 case "running":
244 return "running"
245 case "manual":
246 return "manual"
247 case "queued":
248 return "pending"
249 case "canceled":
250 return "canceled"
251 }
252 warn := false
253 for _, j := range jobs {
254 if j.Status == "failed" && j.AllowFailure {
255 warn = true
256 }
257 }
258 if warn {
259 return "warning"
260 }
261 if pipe == "success" {
262 return "passed"
263 }
264 if pipe == "" {
265 return "pending"
266 }
267 return pipe
268}
269
270func stageViews(jobs []store.Job, ranks map[int64]int, tr func(string, ...any) string) []StageView {
271 var order []string
272 by := map[string][]store.Job{}
273 for _, j := range jobs {
274 if _, ok := by[j.Stage]; !ok {
275 order = append(order, j.Stage)
276 }
277 by[j.Stage] = append(by[j.Stage], j)
278 }
279 var out []StageView
280 for _, name := range order {
281 group := by[name]
282 status := stageStatus(group)
283 label := tr("pipe." + status)
284 var links []JobLink
285 for _, j := range group {
286 st := jobDisplay(j)
287 links = append(links, JobLink{
288 ID: j.ID, Name: j.Name, Status: st, Label: tr("pipe." + st), Stage: j.Stage,
289 Queue: queueText(tr, ranks, j.ID),
290 })
291 }
292 out = append(out, StageView{Name: name, Status: status, Label: label, Tip: name + ": " + strings.ToLower(label), Jobs: links})
293 }
294 return out
295}
296
297func stageStatus(jobs []store.Job) string {
298 pending, failed, warning, running, canceled := false, false, false, false, false
299 seen := false
300 for _, j := range jobs {
301 seen = true
302 switch {
303 case j.Status == "running":
304 running = true
305 case j.Status == "failed" && !j.AllowFailure:
306 failed = true
307 case j.Status == "canceled" && !j.AllowFailure:
308 canceled = true
309 case j.Status == "failed" && j.AllowFailure:
310 warning = true
311 case j.Status == "queued" || j.Status == "manual":
312 pending = true
313 }
314 }
315 if !seen {
316 return "skipped"
317 }
318 if running {
319 return "running"
320 }
321 if failed {
322 return "failed"
323 }
324 if canceled {
325 return "canceled"
326 }
327 if warning {
328 return "warning"
329 }
330 if pending {
331 return "pending"
332 }
333 allSkip := true
334 for _, j := range jobs {
335 if j.Status != "skipped" {
336 allSkip = false
337 }
338 }
339 if allSkip {
340 return "skipped"
341 }
342 return "passed"
343}
344
345func jobDisplay(j store.Job) string {
346 if j.Status == "failed" && j.AllowFailure {
347 return "warning"
348 }
349 switch j.Status {
350 case "success":
351 return "passed"
352 case "queued":
353 return "pending"
354 case "":
355 return "pending"
356 default:
357 return j.Status
358 }
359}
360
361func pipelineClock(p store.Pipeline) string {
362 end := p.FinishedAt
363 if end.IsZero() {
364 end = time.Now()
365 }
366 start := p.StartedAt
367 if start.IsZero() {
368 start = p.CreatedAt
369 }
370 if start.IsZero() {
371 return ""
372 }
373 return formatClock(end.Sub(start))
374}
375
376func formatClock(d time.Duration) string {
377 if d < 0 {
378 d = 0
379 }
380 s := int(d.Seconds())
381 return pad2(s/3600) + ":" + pad2((s%3600)/60) + ":" + pad2(s%60)
382}
383
384func pad2(n int) string {
385 if n < 10 {
386 return "0" + strconv.Itoa(n)
387 }
388 return strconv.Itoa(n)
389}
390
391func shortSHA(sha string) string {
392 if len(sha) > 8 {
393 return sha[:8]
394 }
395 return sha
396}
397
398func (s *Server) showJob(w http.ResponseWriter, r *http.Request) {
399 _, repo, role, ok := s.guard(w, r, access.RoleReadonly)
400 if !ok {
401 return
402 }
403 p, job, ok := s.jobFromRequest(w, r, repo)
404 if !ok {
405 return
406 }
407 v := s.repoView(w, r, repo, role, job.Name)
408 v.Wide = true
409 v.Page = "pipelines"
410 v.Pipe = &p
411 v.JobPage = s.jobPage(r, repo, p, job, role)
412 s.render(w, "job", v)
413}
414
415func (s *Server) jobLog(w http.ResponseWriter, r *http.Request) {
416 _, repo, _, ok := s.guard(w, r, access.RoleReadonly)
417 if !ok {
418 return
419 }
420 _, job, ok := s.jobFromRequest(w, r, repo)
421 if !ok {
422 return
423 }
424 if r.URL.Query().Get("raw") == "1" {
425 w.Header().Set("Content-Type", "text/plain; charset=utf-8")
426 _, _ = w.Write([]byte(job.Log))
427 return
428 }
429 offset, _ := strconv.Atoi(r.URL.Query().Get("offset"))
430 if offset < 0 || offset > len(job.Log) {
431 offset = 0
432 }
433 queue := ""
434 if job.Status == "queued" {
435 tr := func(key string, args ...any) string { return s.tr(r, key, args...) }
436 queue = queueText(tr, s.queueRanks(r.Context()), job.ID)
437 }
438 w.Header().Set("Content-Type", "application/json")
439 w.Header().Set("Cache-Control", "no-store")
440 _ = json.NewEncoder(w).Encode(map[string]any{
441 "offset": len(job.Log),
442 "status": job.Status,
443 "text": job.Log[offset:],
444 "queue": queue,
445 })
446}
447
448func (s *Server) playJob(w http.ResponseWriter, r *http.Request) {
449 u, repo, _, ok := s.guard(w, r, access.RoleDeveloper)
450 if !ok || !s.csrfOK(w, r) {
451 return
452 }
453 p, job, ok := s.jobFromRequest(w, r, repo)
454 if !ok {
455 return
456 }
457 _, _ = s.opJobAction(r.Context(), u, repo, p.ID, job.ID, "play")
458 s.redirect(w, r, repoURL(repo)+"/-/pipelines/"+strconv.FormatInt(p.ID, 10)+"/jobs/"+strconv.FormatInt(job.ID, 10), s.tr(r, "flash.pipeline"), "")
459}
460
461func (s *Server) jobFromRequest(w http.ResponseWriter, r *http.Request, repo store.Repo) (store.Pipeline, store.Job, bool) {
462 pid, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
463 if err != nil {
464 http.NotFound(w, r)
465 return store.Pipeline{}, store.Job{}, false
466 }
467 jid, err := strconv.ParseInt(r.PathValue("job"), 10, 64)
468 if err != nil {
469 http.NotFound(w, r)
470 return store.Pipeline{}, store.Job{}, false
471 }
472 p, err := s.Store.PipelineByID(r.Context(), repo.ID, pid)
473 if err != nil {
474 http.NotFound(w, r)
475 return store.Pipeline{}, store.Job{}, false
476 }
477 jobs, _ := s.Store.JobsByPipeline(r.Context(), p.ID)
478 for _, j := range jobs {
479 if j.ID == jid {
480 return p, j, true
481 }
482 }
483 http.NotFound(w, r)
484 return store.Pipeline{}, store.Job{}, false
485}
486
487func (s *Server) jobPage(r *http.Request, repo store.Repo, p store.Pipeline, job store.Job, role access.Role) *JobPage {
488 lang := s.langOf(r)
489 jobs, _ := s.Store.JobsByPipeline(r.Context(), p.ID)
490 users := map[string]store.User{}
491 actor, avatar := s.actorOf(r, p.Actor, users)
492 initial := ""
493 if actor != "" {
494 initial = strings.ToUpper(actor[:1])
495 }
496 name, kind := ci.SplitRef(p.Ref)
497 status := jobDisplay(job)
498 pipeStatus := displayStatus(p.Status, jobs)
499 end := job.FinishedAt
500 if end.IsZero() && (job.Status == "success" || job.Status == "failed" || job.Status == "skipped") {
501 end = p.FinishedAt
502 }
503 start := job.StartedAt
504 dur := ""
505 if !start.IsZero() {
506 until := end
507 if until.IsZero() {
508 until = time.Now()
509 }
510 dur = formatClock(until.Sub(start))
511 }
512 queued := ""
513 if !start.IsZero() && !p.CreatedAt.IsZero() {
514 queued = formatClock(start.Sub(p.CreatedAt))
515 }
516 timeout := formatClock(job.Timeout)
517 if job.Timeout == 0 && s.Cfg.CI.TimeoutSec > 0 {
518 timeout = formatClock(time.Duration(s.Cfg.CI.TimeoutSec) * time.Second)
519 }
520 finished := ""
521 if !end.IsZero() {
522 finished = i18n.Ago(lang, end.Unix())
523 }
524 ranks := s.queueRanks(r.Context())
525 tr := func(key string, args ...any) string { return s.tr(r, key, args...) }
526 var stages []string
527 seen := map[string]bool{}
528 var related []JobLink
529 for _, j := range jobs {
530 if !seen[j.Stage] {
531 seen[j.Stage] = true
532 stages = append(stages, j.Stage)
533 }
534 st := jobDisplay(j)
535 related = append(related, JobLink{
536 ID: j.ID, Name: j.Name, Status: st, Label: tr("pipe." + st), Current: j.ID == job.ID, Stage: j.Stage,
537 Queue: queueText(tr, ranks, j.ID),
538 })
539 }
540 sourceKey := "pipe.src." + p.Source
541 source := s.tr(r, sourceKey)
542 if source == sourceKey {
543 source = p.Source
544 }
545 return &JobPage{
546 Job: job, Pipe: p, Name: job.Name, Status: status, Label: s.tr(r, "pipe."+status),
547 Actor: actor, Avatar: avatar, Initial: initial, When: i18n.Ago(lang, p.CreatedAt.Unix()),
548 Duration: dur, Finished: finished, Queued: queued, Timeout: timeout, Source: source,
549 Ref: name, RefKind: kind, Short: shortSHA(p.CommitSHA), Title: p.CommitTitle, Stage: job.Stage,
550 PipeStatus: pipeStatus, PipeLabel: s.tr(r, "pipe."+pipeStatus),
551 Stages: stages, Related: related, Blocks: parseLog(job.Log), Running: job.Status == "running" || job.Status == "queued",
552 LogBytes: len(job.Log), CanPlay: job.Status == "manual" && role.CanWriteCode(),
553 Queue: queueText(tr, ranks, job.ID),
554 Environment: job.Environment, EnvironmentURL: job.EnvironmentURL, EnvironmentLink: safeEnvironmentURL(job.EnvironmentURL),
555 }
556}
557
558func safeEnvironmentURL(raw string) string {
559 if strings.Contains(raw, "$") {
560 return ""
561 }
562 if strings.HasPrefix(raw, "https://") || strings.HasPrefix(raw, "http://") {
563 return raw
564 }
565 return ""
566}
567
568func parseLog(raw string) []LogBlock {
569 var blocks []LogBlock
570 var cur *LogBlock
571 n := 0
572 flush := func() {
573 if cur == nil {
574 return
575 }
576 blocks = append(blocks, *cur)
577 cur = nil
578 }
579 for _, row := range strings.Split(raw, "\n") {
580 if row == "" {
581 continue
582 }
583 ts, text := row, row
584 if i := strings.IndexByte(row, '\t'); i >= 0 {
585 ts, text = row[:i], row[i+1:]
586 }
587 if strings.HasPrefix(text, "section_start:") {
588 flush()
589 body := strings.TrimPrefix(text, "section_start:")
590 title := body
591 if i := strings.IndexByte(body, ':'); i >= 0 {
592 title = body[i+1:]
593 }
594 cur = &LogBlock{Section: true, Title: title, Open: true}
595 continue
596 }
597 if strings.HasPrefix(text, "section_end:") {
598 dur := ""
599 body := strings.TrimPrefix(text, "section_end:")
600 if i := strings.IndexByte(body, '\t'); i >= 0 {
601 dur = body[i+1:]
602 }
603 if cur != nil {
604 cur.Duration = dur
605 flush()
606 }
607 continue
608 }
609 n++
610 line := LogLine{N: n, Time: clockOf(ts), Text: text, Spans: ansiSpans(text)}
611 if cur != nil {
612 cur.Lines = append(cur.Lines, line)
613 continue
614 }
615 blocks = append(blocks, LogBlock{Lines: []LogLine{line}})
616 }
617 if cur != nil {
618 flush()
619 }
620 return blocks
621}
622
623func wantsJSON(r *http.Request) bool {
624 return strings.Contains(r.Header.Get("Accept"), "application/json")
625}
626
627func jobsLive(pipe string, jobs []store.Job) bool {
628 if pipe == "queued" || pipe == "running" {
629 return true
630 }
631 for _, j := range jobs {
632 if j.Status == "queued" || j.Status == "running" {
633 return true
634 }
635 }
636 return false
637}
638
639func linksFor(jobs []store.Job, ranks map[int64]int, tr func(string, ...any) string) []JobLink {
640 out := make([]JobLink, 0, len(jobs))
641 for _, j := range jobs {
642 st := jobDisplay(j)
643 out = append(out, JobLink{
644 ID: j.ID, Name: j.Name, Status: st, Label: tr("pipe." + st), Stage: j.Stage,
645 Queue: queueText(tr, ranks, j.ID),
646 })
647 }
648 return out
649}
650
651func (s *Server) partial(name string, v View) string {
652 var buf bytes.Buffer
653 tmpl := s.byLang[v.Lang]
654 if tmpl == nil {
655 tmpl = s.tmpl
656 }
657 if tmpl == nil {
658 return ""
659 }
660 if err := tmpl.ExecuteTemplate(&buf, name, v); err != nil && s.Log != nil {
661 s.Log.Error("sjabloon", "name", name, "err", err)
662 }
663 return buf.String()
664}
665
666func (s *Server) writePipeList(w http.ResponseWriter, v View) {
667 type job struct {
668 ID int64 `json:"id"`
669 Name string `json:"name"`
670 Status string `json:"status"`
671 Label string `json:"label"`
672 Queue string `json:"queue"`
673 }
674 type stage struct {
675 Name string `json:"name"`
676 Status string `json:"status"`
677 Tip string `json:"tip"`
678 Jobs []job `json:"jobs"`
679 }
680 type row struct {
681 ID int64 `json:"id"`
682 Status string `json:"status"`
683 Label string `json:"label"`
684 Duration string `json:"duration"`
685 When string `json:"when"`
686 Stages []stage `json:"stages"`
687 HTML string `json:"html"`
688 }
689 rows := make([]row, 0, len(v.PipeRows))
690 for _, pr := range v.PipeRows {
691 one := v
692 one.PipeRows = []PipeRow{pr}
693 item := row{
694 ID: pr.ID, Status: pr.Status, Label: pr.Label, Duration: pr.Duration, When: pr.When,
695 HTML: s.partial("pipe-rows", one),
696 }
697 for _, st := range pr.Stages {
698 jobs := make([]job, 0, len(st.Jobs))
699 for _, j := range st.Jobs {
700 jobs = append(jobs, job{ID: j.ID, Name: j.Name, Status: j.Status, Label: j.Label, Queue: j.Queue})
701 }
702 item.Stages = append(item.Stages, stage{Name: st.Name, Status: st.Status, Tip: st.Tip, Jobs: jobs})
703 }
704 rows = append(rows, item)
705 }
706 w.Header().Set("Content-Type", "application/json")
707 w.Header().Set("Cache-Control", "no-store")
708 _ = json.NewEncoder(w).Encode(map[string]any{"active": v.Live, "rows": rows})
709}
710
711func (s *Server) writePipeDetail(w http.ResponseWriter, v View) {
712 type job struct {
713 ID int64 `json:"id"`
714 Name string `json:"name"`
715 Status string `json:"status"`
716 Label string `json:"label"`
717 Stage string `json:"stage"`
718 Queue string `json:"queue"`
719 }
720 type stageJob struct {
721 ID int64 `json:"id"`
722 Name string `json:"name"`
723 Status string `json:"status"`
724 Label string `json:"label"`
725 Queue string `json:"queue"`
726 }
727 type stage struct {
728 Name string `json:"name"`
729 Status string `json:"status"`
730 Tip string `json:"tip"`
731 Jobs []stageJob `json:"jobs"`
732 }
733 jobs := make([]job, 0, len(v.PipeJobs))
734 for _, j := range v.PipeJobs {
735 jobs = append(jobs, job{ID: j.ID, Name: j.Name, Status: j.Status, Label: j.Label, Stage: j.Stage, Queue: j.Queue})
736 }
737 stages := make([]stage, 0, len(v.PipeStages))
738 for _, st := range v.PipeStages {
739 item := stage{Name: st.Name, Status: st.Status, Tip: st.Tip, Jobs: make([]stageJob, 0, len(st.Jobs))}
740 for _, j := range st.Jobs {
741 item.Jobs = append(item.Jobs, stageJob{ID: j.ID, Name: j.Name, Status: j.Status, Label: j.Label, Queue: j.Queue})
742 }
743 stages = append(stages, item)
744 }
745 dur := ""
746 html := ""
747 if v.Pipe != nil {
748 dur = pipelineClock(*v.Pipe)
749 if v.Repo != nil {
750 head := CommitRow{PipeID: v.Pipe.ID, PipeStages: v.PipeStages}
751 html = s.partial("stage-dots", View{Lang: v.Lang, Repo: v.Repo, Head: &head})
752 }
753 }
754 w.Header().Set("Content-Type", "application/json")
755 w.Header().Set("Cache-Control", "no-store")
756 _ = json.NewEncoder(w).Encode(map[string]any{
757 "active": v.Live, "status": v.PipeStatus, "label": v.PipeLabel,
758 "duration": dur, "jobs": jobs, "stages": stages, "html": html,
759 })
760}
761
762func clockOf(ts string) string {
763 if t, err := time.Parse(time.RFC3339, ts); err == nil {
764 return t.UTC().Format("15:04:05")
765 }
766 if len(ts) >= 19 && strings.Contains(ts, "T") {
767 return ts[11:19]
768 }
769 return ""
770}