BlueGit

timfa bluegit

feat: ververs de pipeline op het projectoverzicht

De laatste pipeline op het overzicht toont status, duur en jobs,
en pollt elke 3 seconden zolang die pending of running is.

Co-authored-by: tim <tim@timfalken.com>

timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa

Authored 2026-10-23 · 3 weeks ago

Hash
42fd73794791575fa73125603d4e7f0afd3f8879
Parent
6bba2e3f
Pipeline
Passed
8 files changed +293 −15
internal/server/overview_live_test.go added +191 −0
@@ -0,0 +1,191 @@
1 package server
2
3 import (
4 "context"
5 "net/http"
6 "net/http/cookiejar"
7 "net/http/httptest"
8 "net/url"
9 "os/exec"
10 "path/filepath"
11 "regexp"
12 "strconv"
13 "strings"
14 "testing"
15
16 "gitlab.com/Timfa/bluegit/internal/auth"
17 "gitlab.com/Timfa/bluegit/internal/config"
18 "gitlab.com/Timfa/bluegit/internal/gitrepo"
19 "gitlab.com/Timfa/bluegit/internal/store"
20 )
21
22 func TestOverviewPipelinePollsWhileRunning(t *testing.T) {
23 if _, err := exec.LookPath("git"); err != nil {
24 t.Skip("git ontbreekt")
25 }
26 storage := t.TempDir()
27 st, err := store.Open(filepath.Join(storage, "bluegit.db"), bytes32())
28 if err != nil {
29 t.Fatal(err)
30 }
31 t.Cleanup(func() { _ = st.Close() })
32 cfg := config.Config{
33 BaseURL: "http://127.0.0.1:9", Listen: "127.0.0.1:0", StoragePath: storage,
34 Auth: config.Auth{Mode: "dev", DevUser: "tim", DevAuthID: 1, UserAgent: "test", BaseURL: "https://auth.timfalken.com"},
35 Git: config.Git{Binary: "git", DefaultBranch: "master"},
36 }
37 srv := &Server{Cfg: cfg, Store: st, Auth: auth.Dev{Username: "tim", AuthID: 1}, Dev: true, Git: "git", HookBin: "/bin/true"}
38 ts := httptest.NewServer(srv.Handler())
39 t.Cleanup(ts.Close)
40 jar, _ := cookiejar.New(nil)
41 tim := &http.Client{Jar: jar}
42 page := read(t, mustGet(t, tim, ts.URL+"/login"))
43 if _, err := tim.PostForm(ts.URL+"/new/repo", url.Values{
44 "csrf": {csrfOf(t, page)}, "name": {"livepipe"}, "visibility": {"public"},
45 }); err != nil {
46 t.Fatal(err)
47 }
48 ctx := context.Background()
49 repo, err := st.RepoByPath(ctx, "tim", "livepipe")
50 if err != nil {
51 t.Fatal(err)
52 }
53 dir := gitrepo.Dir(storage, "tim", "livepipe")
54 work := t.TempDir()
55 git(t, work, "init", "-b", "master")
56 git(t, work, "config", "user.email", "tim@users.git.timfalken.com")
57 git(t, work, "config", "user.name", "tim")
58 writeFile(t, filepath.Join(work, "README.md"), "hallo\n")
59 git(t, work, "add", "README.md")
60 git(t, work, "commit", "-m", "leesmij")
61 git(t, work, "remote", "add", "origin", dir)
62 git(t, work, "push", "origin", "master")
63 sha := strings.TrimSpace(mustGit(t, dir, "rev-parse", "refs/heads/master"))
64
65 id := makePipe(t, st, repo.ID, sha, "wachten", []store.NewJob{
66 {Name: "unit", Stage: "test", Script: "exit 0"},
67 {Name: "ship", Stage: "deploy", Script: "exit 0"},
68 })
69 home := read(t, mustGet(t, tim, ts.URL+"/tim/livepipe"))
70 live := `data-live="/tim/livepipe/-/pipelines/` + strconv.FormatInt(id, 10) + `" data-live-on="1"`
71 for _, want := range []string{
72 live, `data-head-pipe`, `data-pipe-status`, `data-pipe-label`, `data-pipe-duration`,
73 `data-stage="test"`, `data-stage="deploy"`, `class="stage-dot pending"`,
74 `class="status pending"`, "Pending", `<script src="/assets/pipeline.js"></script>`,
75 } {
76 if !strings.Contains(home, want) {
77 t.Errorf("lopend overzicht mist %q", want)
78 }
79 }
80 if !regexp.MustCompile(`data-pipe-duration>\d{2}:\d{2}:\d{2}<`).MatchString(home) {
81 t.Fatalf("duur ontbreekt:\n%s", home)
82 }
83 file := read(t, mustGet(t, tim, ts.URL+"/tim/livepipe/-/blob/README.md?rev=master"))
84 if strings.Contains(file, `data-live-on="1"`) || strings.Contains(file, "/assets/pipeline.js") {
85 t.Fatal("bestandspagina pollt de pipeline mee")
86 }
87 if !strings.Contains(file, `class="status pending"`) {
88 t.Fatal("bestandspagina mist de statische status")
89 }
90 body := overviewJSON(t, tim, ts.URL+"/tim/livepipe/-/pipelines/"+strconv.FormatInt(id, 10))
91 for _, want := range []string{`"active":true`, `"status":"pending"`, `"duration":"`, `"name":"test"`, `"name":"deploy"`, "stage-dot"} {
92 if !strings.Contains(body, want) {
93 t.Errorf("detail-json mist %q:\n%s", want, body)
94 }
95 }
96 if strings.Contains(body, `"rows"`) {
97 t.Fatalf("detail-json lijkt op de lijst:\n%s", body)
98 }
99 js := read(t, mustGet(t, tim, ts.URL+"/assets/pipeline.js"))
100 if !strings.Contains(js, "data-head-pipe") || !strings.Contains(js, "3000") {
101 t.Fatal("pipeline.js mist de overzichtspoll")
102 }
103
104 finishPipe(t, st, id, "success")
105 home = read(t, mustGet(t, tim, ts.URL+"/tim/livepipe"))
106 if strings.Contains(home, `data-live-on="1"`) || strings.Contains(home, "/assets/pipeline.js") {
107 t.Fatal("geslaagde pipeline blijft pollen")
108 }
109 for _, want := range []string{`class="status passed"`, `class="stage-dot passed"`, `data-pipe-duration`, "Passed"} {
110 if !strings.Contains(home, want) {
111 t.Errorf("geslaagd overzicht mist %q", want)
112 }
113 }
114 body = overviewJSON(t, tim, ts.URL+"/tim/livepipe/-/pipelines/"+strconv.FormatInt(id, 10))
115 if !strings.Contains(body, `"active":false`) || !strings.Contains(body, `"status":"passed"`) || !strings.Contains(body, `"duration":"`) {
116 t.Fatalf("stille json:\n%s", body)
117 }
118
119 failed := makePipe(t, st, repo.ID, sha, "kapot", []store.NewJob{{Name: "unit", Stage: "test", Script: "exit 1"}})
120 finishPipe(t, st, failed, "failed")
121 home = read(t, mustGet(t, tim, ts.URL+"/tim/livepipe"))
122 if strings.Contains(home, `data-live-on="1"`) || !strings.Contains(home, `class="status failed"`) {
123 t.Fatalf("mislukt overzicht:\n%s", home)
124 }
125
126 canceled := makePipe(t, st, repo.ID, sha, "stop", []store.NewJob{{Name: "unit", Stage: "test", Script: "exit 0"}})
127 finishPipe(t, st, canceled, "canceled")
128 home = read(t, mustGet(t, tim, ts.URL+"/tim/livepipe"))
129 if strings.Contains(home, `data-live-on="1"`) || !strings.Contains(home, `class="status canceled"`) {
130 t.Fatalf("geannuleerd overzicht:\n%s", home)
131 }
132
133 running := makePipe(t, st, repo.ID, sha, "bezig", []store.NewJob{
134 {Name: "unit", Stage: "test", Script: "exit 0"},
135 {Name: "ship", Stage: "deploy", Script: "exit 0"},
136 })
137 jobs, err := st.JobsByPipeline(ctx, running)
138 if err != nil {
139 t.Fatal(err)
140 }
141 if ok, err := st.MarkJobRunning(ctx, jobs[0].ID); err != nil || !ok {
142 t.Fatalf("running: %v %v", ok, err)
143 }
144 home = read(t, mustGet(t, tim, ts.URL+"/tim/livepipe"))
145 if !strings.Contains(home, `data-live-on="1"`) || !strings.Contains(home, `class="status running"`) || !strings.Contains(home, `class="stage-dot running"`) {
146 t.Fatalf("lopend overzicht:\n%s", home)
147 }
148 if !strings.Contains(home, `/tim/livepipe/-/pipelines/`+strconv.FormatInt(running, 10)) {
149 t.Fatal("poll wijst niet naar de lopende pipeline")
150 }
151 }
152
153 func makePipe(t *testing.T, st *store.Store, repoID int64, sha, title string, jobs []store.NewJob) int64 {
154 t.Helper()
155 id, err := st.CreatePipeline(context.Background(), repoID, sha, "refs/heads/master", "push", "tim", title, jobs)
156 if err != nil {
157 t.Fatal(err)
158 }
159 return id
160 }
161
162 func finishPipe(t *testing.T, st *store.Store, id int64, status string) {
163 t.Helper()
164 ctx := context.Background()
165 jobs, err := st.JobsByPipeline(ctx, id)
166 if err != nil {
167 t.Fatal(err)
168 }
169 for _, j := range jobs {
170 if err := st.FinishJob(ctx, j.ID, status, ""); err != nil {
171 t.Fatal(err)
172 }
173 }
174 if _, err := st.RefreshPipelineStatus(ctx, id); err != nil {
175 t.Fatal(err)
176 }
177 }
178
179 func overviewJSON(t *testing.T, c *http.Client, raw string) string {
180 t.Helper()
181 req, err := http.NewRequest(http.MethodGet, raw, nil)
182 if err != nil {
183 t.Fatal(err)
184 }
185 req.Header.Set("Accept", "application/json")
186 res, err := c.Do(req)
187 if err != nil {
188 t.Fatal(err)
189 }
190 return read(t, res)
191 }
@@ -0,0 +1,191 @@
1package server
2
3import (
4 "context"
5 "net/http"
6 "net/http/cookiejar"
7 "net/http/httptest"
8 "net/url"
9 "os/exec"
10 "path/filepath"
11 "regexp"
12 "strconv"
13 "strings"
14 "testing"
15
16 "gitlab.com/Timfa/bluegit/internal/auth"
17 "gitlab.com/Timfa/bluegit/internal/config"
18 "gitlab.com/Timfa/bluegit/internal/gitrepo"
19 "gitlab.com/Timfa/bluegit/internal/store"
20)
21
22func TestOverviewPipelinePollsWhileRunning(t *testing.T) {
23 if _, err := exec.LookPath("git"); err != nil {
24 t.Skip("git ontbreekt")
25 }
26 storage := t.TempDir()
27 st, err := store.Open(filepath.Join(storage, "bluegit.db"), bytes32())
28 if err != nil {
29 t.Fatal(err)
30 }
31 t.Cleanup(func() { _ = st.Close() })
32 cfg := config.Config{
33 BaseURL: "http://127.0.0.1:9", Listen: "127.0.0.1:0", StoragePath: storage,
34 Auth: config.Auth{Mode: "dev", DevUser: "tim", DevAuthID: 1, UserAgent: "test", BaseURL: "https://auth.timfalken.com"},
35 Git: config.Git{Binary: "git", DefaultBranch: "master"},
36 }
37 srv := &Server{Cfg: cfg, Store: st, Auth: auth.Dev{Username: "tim", AuthID: 1}, Dev: true, Git: "git", HookBin: "/bin/true"}
38 ts := httptest.NewServer(srv.Handler())
39 t.Cleanup(ts.Close)
40 jar, _ := cookiejar.New(nil)
41 tim := &http.Client{Jar: jar}
42 page := read(t, mustGet(t, tim, ts.URL+"/login"))
43 if _, err := tim.PostForm(ts.URL+"/new/repo", url.Values{
44 "csrf": {csrfOf(t, page)}, "name": {"livepipe"}, "visibility": {"public"},
45 }); err != nil {
46 t.Fatal(err)
47 }
48 ctx := context.Background()
49 repo, err := st.RepoByPath(ctx, "tim", "livepipe")
50 if err != nil {
51 t.Fatal(err)
52 }
53 dir := gitrepo.Dir(storage, "tim", "livepipe")
54 work := t.TempDir()
55 git(t, work, "init", "-b", "master")
56 git(t, work, "config", "user.email", "tim@users.git.timfalken.com")
57 git(t, work, "config", "user.name", "tim")
58 writeFile(t, filepath.Join(work, "README.md"), "hallo\n")
59 git(t, work, "add", "README.md")
60 git(t, work, "commit", "-m", "leesmij")
61 git(t, work, "remote", "add", "origin", dir)
62 git(t, work, "push", "origin", "master")
63 sha := strings.TrimSpace(mustGit(t, dir, "rev-parse", "refs/heads/master"))
64
65 id := makePipe(t, st, repo.ID, sha, "wachten", []store.NewJob{
66 {Name: "unit", Stage: "test", Script: "exit 0"},
67 {Name: "ship", Stage: "deploy", Script: "exit 0"},
68 })
69 home := read(t, mustGet(t, tim, ts.URL+"/tim/livepipe"))
70 live := `data-live="/tim/livepipe/-/pipelines/` + strconv.FormatInt(id, 10) + `" data-live-on="1"`
71 for _, want := range []string{
72 live, `data-head-pipe`, `data-pipe-status`, `data-pipe-label`, `data-pipe-duration`,
73 `data-stage="test"`, `data-stage="deploy"`, `class="stage-dot pending"`,
74 `class="status pending"`, "Pending", `<script src="/assets/pipeline.js"></script>`,
75 } {
76 if !strings.Contains(home, want) {
77 t.Errorf("lopend overzicht mist %q", want)
78 }
79 }
80 if !regexp.MustCompile(`data-pipe-duration>\d{2}:\d{2}:\d{2}<`).MatchString(home) {
81 t.Fatalf("duur ontbreekt:\n%s", home)
82 }
83 file := read(t, mustGet(t, tim, ts.URL+"/tim/livepipe/-/blob/README.md?rev=master"))
84 if strings.Contains(file, `data-live-on="1"`) || strings.Contains(file, "/assets/pipeline.js") {
85 t.Fatal("bestandspagina pollt de pipeline mee")
86 }
87 if !strings.Contains(file, `class="status pending"`) {
88 t.Fatal("bestandspagina mist de statische status")
89 }
90 body := overviewJSON(t, tim, ts.URL+"/tim/livepipe/-/pipelines/"+strconv.FormatInt(id, 10))
91 for _, want := range []string{`"active":true`, `"status":"pending"`, `"duration":"`, `"name":"test"`, `"name":"deploy"`, "stage-dot"} {
92 if !strings.Contains(body, want) {
93 t.Errorf("detail-json mist %q:\n%s", want, body)
94 }
95 }
96 if strings.Contains(body, `"rows"`) {
97 t.Fatalf("detail-json lijkt op de lijst:\n%s", body)
98 }
99 js := read(t, mustGet(t, tim, ts.URL+"/assets/pipeline.js"))
100 if !strings.Contains(js, "data-head-pipe") || !strings.Contains(js, "3000") {
101 t.Fatal("pipeline.js mist de overzichtspoll")
102 }
103
104 finishPipe(t, st, id, "success")
105 home = read(t, mustGet(t, tim, ts.URL+"/tim/livepipe"))
106 if strings.Contains(home, `data-live-on="1"`) || strings.Contains(home, "/assets/pipeline.js") {
107 t.Fatal("geslaagde pipeline blijft pollen")
108 }
109 for _, want := range []string{`class="status passed"`, `class="stage-dot passed"`, `data-pipe-duration`, "Passed"} {
110 if !strings.Contains(home, want) {
111 t.Errorf("geslaagd overzicht mist %q", want)
112 }
113 }
114 body = overviewJSON(t, tim, ts.URL+"/tim/livepipe/-/pipelines/"+strconv.FormatInt(id, 10))
115 if !strings.Contains(body, `"active":false`) || !strings.Contains(body, `"status":"passed"`) || !strings.Contains(body, `"duration":"`) {
116 t.Fatalf("stille json:\n%s", body)
117 }
118
119 failed := makePipe(t, st, repo.ID, sha, "kapot", []store.NewJob{{Name: "unit", Stage: "test", Script: "exit 1"}})
120 finishPipe(t, st, failed, "failed")
121 home = read(t, mustGet(t, tim, ts.URL+"/tim/livepipe"))
122 if strings.Contains(home, `data-live-on="1"`) || !strings.Contains(home, `class="status failed"`) {
123 t.Fatalf("mislukt overzicht:\n%s", home)
124 }
125
126 canceled := makePipe(t, st, repo.ID, sha, "stop", []store.NewJob{{Name: "unit", Stage: "test", Script: "exit 0"}})
127 finishPipe(t, st, canceled, "canceled")
128 home = read(t, mustGet(t, tim, ts.URL+"/tim/livepipe"))
129 if strings.Contains(home, `data-live-on="1"`) || !strings.Contains(home, `class="status canceled"`) {
130 t.Fatalf("geannuleerd overzicht:\n%s", home)
131 }
132
133 running := makePipe(t, st, repo.ID, sha, "bezig", []store.NewJob{
134 {Name: "unit", Stage: "test", Script: "exit 0"},
135 {Name: "ship", Stage: "deploy", Script: "exit 0"},
136 })
137 jobs, err := st.JobsByPipeline(ctx, running)
138 if err != nil {
139 t.Fatal(err)
140 }
141 if ok, err := st.MarkJobRunning(ctx, jobs[0].ID); err != nil || !ok {
142 t.Fatalf("running: %v %v", ok, err)
143 }
144 home = read(t, mustGet(t, tim, ts.URL+"/tim/livepipe"))
145 if !strings.Contains(home, `data-live-on="1"`) || !strings.Contains(home, `class="status running"`) || !strings.Contains(home, `class="stage-dot running"`) {
146 t.Fatalf("lopend overzicht:\n%s", home)
147 }
148 if !strings.Contains(home, `/tim/livepipe/-/pipelines/`+strconv.FormatInt(running, 10)) {
149 t.Fatal("poll wijst niet naar de lopende pipeline")
150 }
151}
152
153func makePipe(t *testing.T, st *store.Store, repoID int64, sha, title string, jobs []store.NewJob) int64 {
154 t.Helper()
155 id, err := st.CreatePipeline(context.Background(), repoID, sha, "refs/heads/master", "push", "tim", title, jobs)
156 if err != nil {
157 t.Fatal(err)
158 }
159 return id
160}
161
162func finishPipe(t *testing.T, st *store.Store, id int64, status string) {
163 t.Helper()
164 ctx := context.Background()
165 jobs, err := st.JobsByPipeline(ctx, id)
166 if err != nil {
167 t.Fatal(err)
168 }
169 for _, j := range jobs {
170 if err := st.FinishJob(ctx, j.ID, status, ""); err != nil {
171 t.Fatal(err)
172 }
173 }
174 if _, err := st.RefreshPipelineStatus(ctx, id); err != nil {
175 t.Fatal(err)
176 }
177}
178
179func overviewJSON(t *testing.T, c *http.Client, raw string) string {
180 t.Helper()
181 req, err := http.NewRequest(http.MethodGet, raw, nil)
182 if err != nil {
183 t.Fatal(err)
184 }
185 req.Header.Set("Accept", "application/json")
186 res, err := c.Do(req)
187 if err != nil {
188 t.Fatal(err)
189 }
190 return read(t, res)
191}
internal/server/pipeline_page.go +48 −10
@@ -154,17 +154,9 @@ func (s *Server) pipeRow(r *http.Request, lang i18n.Lang, repo store.Repo, p sto
154 154 if actor != "" {
155 155 initial = strings.ToUpper(actor[:1])
156 156 }
157 end := p.FinishedAt
158 if end.IsZero() {
159 end = time.Now()
160 }
161 start := p.StartedAt
162 if start.IsZero() {
163 start = p.CreatedAt
164 }
165 157 return PipeRow{
166 158 ID: p.ID, Status: status, Label: s.tr(r, "pipe."+status),
167 Duration: formatClock(end.Sub(start)), When: i18n.Ago(lang, p.CreatedAt.Unix()),
159 Duration: pipelineClock(p), When: i18n.Ago(lang, p.CreatedAt.Unix()),
168 160 Title: p.CommitTitle, SHA: p.CommitSHA, Short: shortSHA(p.CommitSHA),
169 161 Ref: name, RefKind: kind, Actor: actor, Avatar: avatar, Initial: initial,
170 162 Stages: stageViews(jobs, ranks, func(key string, args ...any) string { return s.tr(r, key, args...) }),
@@ -328,6 +320,21 @@ func jobDisplay(j store.Job) string {
328 320 }
329 321 }
330 322
323 func pipelineClock(p store.Pipeline) string {
324 end := p.FinishedAt
325 if end.IsZero() {
326 end = time.Now()
327 }
328 start := p.StartedAt
329 if start.IsZero() {
330 start = p.CreatedAt
331 }
332 if start.IsZero() {
333 return ""
334 }
335 return formatClock(end.Sub(start))
336 }
337
331 338 func formatClock(d time.Duration) string {
332 339 if d < 0 {
333 340 d = 0
@@ -672,14 +679,45 @@ func (s *Server) writePipeDetail(w http.ResponseWriter, v View) {
672 679 Stage string `json:"stage"`
673 680 Queue string `json:"queue"`
674 681 }
682 type stageJob struct {
683 ID int64 `json:"id"`
684 Name string `json:"name"`
685 Status string `json:"status"`
686 Label string `json:"label"`
687 Queue string `json:"queue"`
688 }
689 type stage struct {
690 Name string `json:"name"`
691 Status string `json:"status"`
692 Tip string `json:"tip"`
693 Jobs []stageJob `json:"jobs"`
694 }
675 695 jobs := make([]job, 0, len(v.PipeJobs))
676 696 for _, j := range v.PipeJobs {
677 697 jobs = append(jobs, job{ID: j.ID, Name: j.Name, Status: j.Status, Label: j.Label, Stage: j.Stage, Queue: j.Queue})
678 698 }
699 stages := make([]stage, 0, len(v.PipeStages))
700 for _, st := range v.PipeStages {
701 item := stage{Name: st.Name, Status: st.Status, Tip: st.Tip, Jobs: make([]stageJob, 0, len(st.Jobs))}
702 for _, j := range st.Jobs {
703 item.Jobs = append(item.Jobs, stageJob{ID: j.ID, Name: j.Name, Status: j.Status, Label: j.Label, Queue: j.Queue})
704 }
705 stages = append(stages, item)
706 }
707 dur := ""
708 html := ""
709 if v.Pipe != nil {
710 dur = pipelineClock(*v.Pipe)
711 if v.Repo != nil {
712 head := CommitRow{PipeID: v.Pipe.ID, PipeStages: v.PipeStages}
713 html = s.partial("stage-dots", View{Lang: v.Lang, Repo: v.Repo, Head: &head})
714 }
715 }
679 716 w.Header().Set("Content-Type", "application/json")
680 717 w.Header().Set("Cache-Control", "no-store")
681 718 _ = json.NewEncoder(w).Encode(map[string]any{
682 "active": v.Live, "status": v.PipeStatus, "label": v.PipeLabel, "jobs": jobs,
719 "active": v.Live, "status": v.PipeStatus, "label": v.PipeLabel,
720 "duration": dur, "jobs": jobs, "stages": stages, "html": html,
683 721 })
684 722 }
685 723
@@ -154,17 +154,9 @@ func (s *Server) pipeRow(r *http.Request, lang i18n.Lang, repo store.Repo, p sto
154 if actor != "" {
154 if actor != "" {
155 initial = strings.ToUpper(actor[:1])
155 initial = strings.ToUpper(actor[:1])
156 }
156 }
157 end := p.FinishedAt
158 if end.IsZero() {
159 end = time.Now()
160 }
161 start := p.StartedAt
162 if start.IsZero() {
163 start = p.CreatedAt
164 }
165 return PipeRow{
157 return PipeRow{
166 ID: p.ID, Status: status, Label: s.tr(r, "pipe."+status),
158 ID: p.ID, Status: status, Label: s.tr(r, "pipe."+status),
167 Duration: formatClock(end.Sub(start)), When: i18n.Ago(lang, p.CreatedAt.Unix()),
159 Duration: pipelineClock(p), When: i18n.Ago(lang, p.CreatedAt.Unix()),
168 Title: p.CommitTitle, SHA: p.CommitSHA, Short: shortSHA(p.CommitSHA),
160 Title: p.CommitTitle, SHA: p.CommitSHA, Short: shortSHA(p.CommitSHA),
169 Ref: name, RefKind: kind, Actor: actor, Avatar: avatar, Initial: initial,
161 Ref: name, RefKind: kind, Actor: actor, Avatar: avatar, Initial: initial,
170 Stages: stageViews(jobs, ranks, func(key string, args ...any) string { return s.tr(r, key, args...) }),
162 Stages: stageViews(jobs, ranks, func(key string, args ...any) string { return s.tr(r, key, args...) }),
@@ -328,6 +320,21 @@ func jobDisplay(j store.Job) string {
328 }
320 }
329}
321}
330
322
323func pipelineClock(p store.Pipeline) string {
324 end := p.FinishedAt
325 if end.IsZero() {
326 end = time.Now()
327 }
328 start := p.StartedAt
329 if start.IsZero() {
330 start = p.CreatedAt
331 }
332 if start.IsZero() {
333 return ""
334 }
335 return formatClock(end.Sub(start))
336}
337
331func formatClock(d time.Duration) string {
338func formatClock(d time.Duration) string {
332 if d < 0 {
339 if d < 0 {
333 d = 0
340 d = 0
@@ -672,14 +679,45 @@ func (s *Server) writePipeDetail(w http.ResponseWriter, v View) {
672 Stage string `json:"stage"`
679 Stage string `json:"stage"`
673 Queue string `json:"queue"`
680 Queue string `json:"queue"`
674 }
681 }
682 type stageJob struct {
683 ID int64 `json:"id"`
684 Name string `json:"name"`
685 Status string `json:"status"`
686 Label string `json:"label"`
687 Queue string `json:"queue"`
688 }
689 type stage struct {
690 Name string `json:"name"`
691 Status string `json:"status"`
692 Tip string `json:"tip"`
693 Jobs []stageJob `json:"jobs"`
694 }
675 jobs := make([]job, 0, len(v.PipeJobs))
695 jobs := make([]job, 0, len(v.PipeJobs))
676 for _, j := range v.PipeJobs {
696 for _, j := range v.PipeJobs {
677 jobs = append(jobs, job{ID: j.ID, Name: j.Name, Status: j.Status, Label: j.Label, Stage: j.Stage, Queue: j.Queue})
697 jobs = append(jobs, job{ID: j.ID, Name: j.Name, Status: j.Status, Label: j.Label, Stage: j.Stage, Queue: j.Queue})
678 }
698 }
699 stages := make([]stage, 0, len(v.PipeStages))
700 for _, st := range v.PipeStages {
701 item := stage{Name: st.Name, Status: st.Status, Tip: st.Tip, Jobs: make([]stageJob, 0, len(st.Jobs))}
702 for _, j := range st.Jobs {
703 item.Jobs = append(item.Jobs, stageJob{ID: j.ID, Name: j.Name, Status: j.Status, Label: j.Label, Queue: j.Queue})
704 }
705 stages = append(stages, item)
706 }
707 dur := ""
708 html := ""
709 if v.Pipe != nil {
710 dur = pipelineClock(*v.Pipe)
711 if v.Repo != nil {
712 head := CommitRow{PipeID: v.Pipe.ID, PipeStages: v.PipeStages}
713 html = s.partial("stage-dots", View{Lang: v.Lang, Repo: v.Repo, Head: &head})
714 }
715 }
679 w.Header().Set("Content-Type", "application/json")
716 w.Header().Set("Content-Type", "application/json")
680 w.Header().Set("Cache-Control", "no-store")
717 w.Header().Set("Cache-Control", "no-store")
681 _ = json.NewEncoder(w).Encode(map[string]any{
718 _ = json.NewEncoder(w).Encode(map[string]any{
682 "active": v.Live, "status": v.PipeStatus, "label": v.PipeLabel, "jobs": jobs,
719 "active": v.Live, "status": v.PipeStatus, "label": v.PipeLabel,
720 "duration": dur, "jobs": jobs, "stages": stages, "html": html,
683 })
721 })
684}
722}
685
723
internal/server/project.go +4 −0
@@ -119,6 +119,10 @@ func (s *Server) attachHeadPipeline(ctx context.Context, repo store.Repo, row *C
119 119 row.PipeID = p.ID
120 120 row.PipeStatus = status
121 121 row.PipeLabel = i18n.T(lang, "pipe."+status)
122 row.PipeDuration = pipelineClock(p)
123 tr := func(key string, args ...any) string { return i18n.T(lang, key, args...) }
124 row.PipeStages = stageViews(jobs, s.queueRanks(ctx), tr)
125 row.PipeLive = jobsLive(p.Status, jobs)
122 126 }
123 127
124 128 func fileRows(entries []gitrepo.Entry, base string, touch map[string]gitrepo.Commit, lang i18n.Lang) []FileRow {
@@ -119,6 +119,10 @@ func (s *Server) attachHeadPipeline(ctx context.Context, repo store.Repo, row *C
119 row.PipeID = p.ID
119 row.PipeID = p.ID
120 row.PipeStatus = status
120 row.PipeStatus = status
121 row.PipeLabel = i18n.T(lang, "pipe."+status)
121 row.PipeLabel = i18n.T(lang, "pipe."+status)
122 row.PipeDuration = pipelineClock(p)
123 tr := func(key string, args ...any) string { return i18n.T(lang, key, args...) }
124 row.PipeStages = stageViews(jobs, s.queueRanks(ctx), tr)
125 row.PipeLive = jobsLive(p.Status, jobs)
122}
126}
123
127
124func fileRows(entries []gitrepo.Entry, base string, touch map[string]gitrepo.Commit, lang i18n.Lang) []FileRow {
128func fileRows(entries []gitrepo.Entry, base string, touch map[string]gitrepo.Commit, lang i18n.Lang) []FileRow {
internal/server/repo_handlers.go +1 −0
@@ -368,6 +368,7 @@ func (s *Server) pipeline(w http.ResponseWriter, r *http.Request) {
368 368 v.PipeStatus = displayStatus(p.Status, jobs)
369 369 v.PipeLabel = tr("pipe." + v.PipeStatus)
370 370 v.PipeJobs = linksFor(jobs, ranks, tr)
371 v.PipeStages = stageViews(jobs, ranks, tr)
371 372 v.Live = jobsLive(p.Status, jobs)
372 373 v.LiveURL = repoURL(repo) + "/-/pipelines/" + strconv.FormatInt(p.ID, 10)
373 374 if wantsJSON(r) {
@@ -368,6 +368,7 @@ func (s *Server) pipeline(w http.ResponseWriter, r *http.Request) {
368 v.PipeStatus = displayStatus(p.Status, jobs)
368 v.PipeStatus = displayStatus(p.Status, jobs)
369 v.PipeLabel = tr("pipe." + v.PipeStatus)
369 v.PipeLabel = tr("pipe." + v.PipeStatus)
370 v.PipeJobs = linksFor(jobs, ranks, tr)
370 v.PipeJobs = linksFor(jobs, ranks, tr)
371 v.PipeStages = stageViews(jobs, ranks, tr)
371 v.Live = jobsLive(p.Status, jobs)
372 v.Live = jobsLive(p.Status, jobs)
372 v.LiveURL = repoURL(repo) + "/-/pipelines/" + strconv.FormatInt(p.ID, 10)
373 v.LiveURL = repoURL(repo) + "/-/pipelines/" + strconv.FormatInt(p.ID, 10)
373 if wantsJSON(r) {
374 if wantsJSON(r) {
internal/server/server.go +4 −1
@@ -543,6 +543,7 @@ type View struct {
543 543 PipeStatus string
544 544 PipeLabel string
545 545 PipeJobs []JobLink
546 PipeStages []StageView
546 547 Live bool
547 548 LiveURL string
548 549 Jobs []store.Job
@@ -689,7 +690,9 @@ type CommitRow struct {
689 690 SHA, Short, Author, Date, Subject, Body, When string
690 691 UserURL, Avatar, Initial, RawName, PushedBy string
691 692 PipeID int64
692 PipeStatus, PipeLabel string
693 PipeStatus, PipeLabel, PipeDuration string
694 PipeStages []StageView
695 PipeLive bool
693 696 }
694 697
695 698 // EntryRow is een bestand of map.
@@ -543,6 +543,7 @@ type View struct {
543 PipeStatus string
543 PipeStatus string
544 PipeLabel string
544 PipeLabel string
545 PipeJobs []JobLink
545 PipeJobs []JobLink
546 PipeStages []StageView
546 Live bool
547 Live bool
547 LiveURL string
548 LiveURL string
548 Jobs []store.Job
549 Jobs []store.Job
@@ -689,7 +690,9 @@ type CommitRow struct {
689 SHA, Short, Author, Date, Subject, Body, When string
690 SHA, Short, Author, Date, Subject, Body, When string
690 UserURL, Avatar, Initial, RawName, PushedBy string
691 UserURL, Avatar, Initial, RawName, PushedBy string
691 PipeID int64
692 PipeID int64
692 PipeStatus, PipeLabel string
693 PipeStatus, PipeLabel, PipeDuration string
694 PipeStages []StageView
695 PipeLive bool
693}
696}
694
697
695// EntryRow is een bestand of map.
698// EntryRow is een bestand of map.
internal/server/static/pipeline.js +17 −3
@@ -115,6 +115,16 @@
115 115 return wrap.querySelector("tr");
116 116 }
117 117
118 function stagesFromHTML(html) {
119 var row = rowElement(html);
120 if (row) {
121 return row.querySelector(".stages");
122 }
123 var wrap = document.createElement("div");
124 wrap.innerHTML = (html || "").trim();
125 return wrap.querySelector(".stages");
126 }
127
118 128 function findStage(root, name) {
119 129 var buttons = root.querySelectorAll("button.stage-dot[data-stage]");
120 130 for (var i = 0; i < buttons.length; i++) {
@@ -177,8 +187,8 @@
177 187 }
178 188 }
179 189 if (!same) {
180 var fresh = rowElement(row.html);
181 if (!fresh) {
190 var freshStages = stagesFromHTML(row.html);
191 if (!freshStages) {
182 192 return;
183 193 }
184 194 var openName = "";
@@ -187,7 +197,7 @@
187 197 var openBtn = openPop.parentElement.querySelector("button.stage-dot");
188 198 openName = openBtn ? openBtn.getAttribute("data-stage") : "";
189 199 }
190 stages.innerHTML = fresh.querySelector(".stages").innerHTML;
200 stages.innerHTML = freshStages.innerHTML;
191 201 if (openName) {
192 202 var again = findStage(live, openName);
193 203 if (again) {
@@ -297,6 +307,10 @@
297 307 }
298 308 setQueue(li, job.queue);
299 309 });
310 var head = document.querySelector("[data-head-pipe]");
311 if (head) {
312 patchPipeRow(head, data);
313 }
300 314 }
301 315
302 316 var liveEl = document.querySelector("[data-live-on]");
@@ -115,6 +115,16 @@
115 return wrap.querySelector("tr");
115 return wrap.querySelector("tr");
116 }
116 }
117
117
118 function stagesFromHTML(html) {
119 var row = rowElement(html);
120 if (row) {
121 return row.querySelector(".stages");
122 }
123 var wrap = document.createElement("div");
124 wrap.innerHTML = (html || "").trim();
125 return wrap.querySelector(".stages");
126 }
127
118 function findStage(root, name) {
128 function findStage(root, name) {
119 var buttons = root.querySelectorAll("button.stage-dot[data-stage]");
129 var buttons = root.querySelectorAll("button.stage-dot[data-stage]");
120 for (var i = 0; i < buttons.length; i++) {
130 for (var i = 0; i < buttons.length; i++) {
@@ -177,8 +187,8 @@
177 }
187 }
178 }
188 }
179 if (!same) {
189 if (!same) {
180 var fresh = rowElement(row.html);
190 var freshStages = stagesFromHTML(row.html);
181 if (!fresh) {
191 if (!freshStages) {
182 return;
192 return;
183 }
193 }
184 var openName = "";
194 var openName = "";
@@ -187,7 +197,7 @@
187 var openBtn = openPop.parentElement.querySelector("button.stage-dot");
197 var openBtn = openPop.parentElement.querySelector("button.stage-dot");
188 openName = openBtn ? openBtn.getAttribute("data-stage") : "";
198 openName = openBtn ? openBtn.getAttribute("data-stage") : "";
189 }
199 }
190 stages.innerHTML = fresh.querySelector(".stages").innerHTML;
200 stages.innerHTML = freshStages.innerHTML;
191 if (openName) {
201 if (openName) {
192 var again = findStage(live, openName);
202 var again = findStage(live, openName);
193 if (again) {
203 if (again) {
@@ -297,6 +307,10 @@
297 }
307 }
298 setQueue(li, job.queue);
308 setQueue(li, job.queue);
299 });
309 });
310 var head = document.querySelector("[data-head-pipe]");
311 if (head) {
312 patchPipeRow(head, data);
313 }
300 }
314 }
301
315
302 var liveEl = document.querySelector("[data-live-on]");
316 var liveEl = document.querySelector("[data-live-on]");
internal/server/static/style.css +2 −0
@@ -504,6 +504,8 @@ svg.ico { width: 14px; height: 14px; flex: none; }
504 504 .running .mark::after { animation: none; }
505 505 }
506 506 .commitbar a.status { flex: none; text-decoration: none; }
507 .headpipe { display: flex; align-items: center; gap: 0.45rem; flex: none; }
508 .headpipe [data-pipe-duration] { font-variant-numeric: tabular-nums; }
507 509 .stages { display: flex; align-items: center; }
508 510 .mrpipe { display: flex; align-items: center; gap: 0.8rem; margin: 0.2rem 0 1rem; }
509 511 .danger-modal {
@@ -504,6 +504,8 @@ svg.ico { width: 14px; height: 14px; flex: none; }
504 .running .mark::after { animation: none; }
504 .running .mark::after { animation: none; }
505}
505}
506.commitbar a.status { flex: none; text-decoration: none; }
506.commitbar a.status { flex: none; text-decoration: none; }
507.headpipe { display: flex; align-items: center; gap: 0.45rem; flex: none; }
508.headpipe [data-pipe-duration] { font-variant-numeric: tabular-nums; }
507.stages { display: flex; align-items: center; }
509.stages { display: flex; align-items: center; }
508.mrpipe { display: flex; align-items: center; gap: 0.8rem; margin: 0.2rem 0 1rem; }
510.mrpipe { display: flex; align-items: center; gap: 0.8rem; margin: 0.2rem 0 1rem; }
509.danger-modal {
511.danger-modal {
internal/server/templates/pages.html +26 −1
@@ -290,7 +290,13 @@
290 290 <a class="subject" href="/{{.Repo.FullPath}}/-/commit/{{.Head.SHA}}">{{.Head.Subject}}</a>
291 291 <div class="muted">{{template "commitwho" .Head}} · {{.Head.When}}</div>
292 292 </div>
293 {{if .Head.PipeStatus}}<a class="status {{.Head.PipeStatus}}" href="/{{.Repo.FullPath}}/-/pipelines/{{.Head.PipeID}}"><span class="mark"></span>{{.Head.PipeLabel}}</a>{{end}}
293 {{if and .Head.PipeStatus (eq .Page "overview")}}
294 <span class="headpipe" data-head-pipe{{if .Head.PipeLive}} data-live="/{{.Repo.FullPath}}/-/pipelines/{{.Head.PipeID}}" data-live-on="1"{{end}}>
295 <a class="status {{.Head.PipeStatus}}" data-pipe-status href="/{{.Repo.FullPath}}/-/pipelines/{{.Head.PipeID}}"><span class="mark"></span><span data-pipe-label>{{.Head.PipeLabel}}</span></a>
296 <span class="muted" data-pipe-duration>{{.Head.PipeDuration}}</span>
297 {{template "stage-dots" .}}
298 </span>
299 {{else if .Head.PipeStatus}}<a class="status {{.Head.PipeStatus}}" href="/{{.Repo.FullPath}}/-/pipelines/{{.Head.PipeID}}"><span class="mark"></span>{{.Head.PipeLabel}}</a>{{end}}
294 300 <code class="sha">{{slice .Head.SHA 0 8}}</code>
295 301 <button type="button" class="iconbtn" data-copy="{{.Head.SHA}}" aria-label="{{t "action.copy"}}">{{t "action.copy"}}</button>
296 302 <a class="btn ghost" href="/{{.Repo.FullPath}}/-/commits?rev={{.Rev}}">{{t "repo.history"}}</a>
@@ -298,6 +304,24 @@
298 304 {{end}}
299 305 {{end}}
300 306
307 {{define "stage-dots"}}
308 {{with .Head}}
309 <div class="stages">
310 {{range .PipeStages}}
311 <span class="stage">
312 <button type="button" class="stage-dot {{.Status}}" data-stage="{{.Name}}" data-tip="{{.Tip}}" aria-label="{{.Tip}}"><span class="mark"></span></button>
313 <div class="stage-pop" popover="manual">
314 <strong>{{t "pipe.stage"}}: {{.Name}}</strong>
315 <ul>
316 {{range .Jobs}}<li data-job="{{.ID}}"><a href="/{{$.Repo.FullPath}}/-/pipelines/{{$.Head.PipeID}}/jobs/{{.ID}}"><span class="stage-dot sm {{.Status}}"><span class="mark"></span></span>{{.Name}}{{if .Queue}} <span class="queue" data-queue>{{.Queue}}</span>{{end}}</a></li>{{end}}
317 </ul>
318 </div>
319 </span>
320 {{end}}
321 </div>
322 {{end}}
323 {{end}}
324
301 325 {{define "codemenu"}}
302 326 <details class="menu" data-clone>
303 327 <summary class="btn">{{t "repo.code"}}</summary>
@@ -371,6 +395,7 @@
371 395 </aside>
372 396 </div>
373 397 <script src="/assets/repo.js"></script>
398 {{if and .Head .Head.PipeLive}}<script src="/assets/pipeline.js"></script>{{end}}
374 399 {{template "layout-end" .}}
375 400 {{end}}
376 401
@@ -290,7 +290,13 @@
290 <a class="subject" href="/{{.Repo.FullPath}}/-/commit/{{.Head.SHA}}">{{.Head.Subject}}</a>
290 <a class="subject" href="/{{.Repo.FullPath}}/-/commit/{{.Head.SHA}}">{{.Head.Subject}}</a>
291 <div class="muted">{{template "commitwho" .Head}} · {{.Head.When}}</div>
291 <div class="muted">{{template "commitwho" .Head}} · {{.Head.When}}</div>
292 </div>
292 </div>
293 {{if .Head.PipeStatus}}<a class="status {{.Head.PipeStatus}}" href="/{{.Repo.FullPath}}/-/pipelines/{{.Head.PipeID}}"><span class="mark"></span>{{.Head.PipeLabel}}</a>{{end}}
293 {{if and .Head.PipeStatus (eq .Page "overview")}}
294 <span class="headpipe" data-head-pipe{{if .Head.PipeLive}} data-live="/{{.Repo.FullPath}}/-/pipelines/{{.Head.PipeID}}" data-live-on="1"{{end}}>
295 <a class="status {{.Head.PipeStatus}}" data-pipe-status href="/{{.Repo.FullPath}}/-/pipelines/{{.Head.PipeID}}"><span class="mark"></span><span data-pipe-label>{{.Head.PipeLabel}}</span></a>
296 <span class="muted" data-pipe-duration>{{.Head.PipeDuration}}</span>
297 {{template "stage-dots" .}}
298 </span>
299 {{else if .Head.PipeStatus}}<a class="status {{.Head.PipeStatus}}" href="/{{.Repo.FullPath}}/-/pipelines/{{.Head.PipeID}}"><span class="mark"></span>{{.Head.PipeLabel}}</a>{{end}}
294 <code class="sha">{{slice .Head.SHA 0 8}}</code>
300 <code class="sha">{{slice .Head.SHA 0 8}}</code>
295 <button type="button" class="iconbtn" data-copy="{{.Head.SHA}}" aria-label="{{t "action.copy"}}">{{t "action.copy"}}</button>
301 <button type="button" class="iconbtn" data-copy="{{.Head.SHA}}" aria-label="{{t "action.copy"}}">{{t "action.copy"}}</button>
296 <a class="btn ghost" href="/{{.Repo.FullPath}}/-/commits?rev={{.Rev}}">{{t "repo.history"}}</a>
302 <a class="btn ghost" href="/{{.Repo.FullPath}}/-/commits?rev={{.Rev}}">{{t "repo.history"}}</a>
@@ -298,6 +304,24 @@
298{{end}}
304{{end}}
299{{end}}
305{{end}}
300
306
307{{define "stage-dots"}}
308{{with .Head}}
309<div class="stages">
310 {{range .PipeStages}}
311 <span class="stage">
312 <button type="button" class="stage-dot {{.Status}}" data-stage="{{.Name}}" data-tip="{{.Tip}}" aria-label="{{.Tip}}"><span class="mark"></span></button>
313 <div class="stage-pop" popover="manual">
314 <strong>{{t "pipe.stage"}}: {{.Name}}</strong>
315 <ul>
316 {{range .Jobs}}<li data-job="{{.ID}}"><a href="/{{$.Repo.FullPath}}/-/pipelines/{{$.Head.PipeID}}/jobs/{{.ID}}"><span class="stage-dot sm {{.Status}}"><span class="mark"></span></span>{{.Name}}{{if .Queue}} <span class="queue" data-queue>{{.Queue}}</span>{{end}}</a></li>{{end}}
317 </ul>
318 </div>
319 </span>
320 {{end}}
321</div>
322{{end}}
323{{end}}
324
301{{define "codemenu"}}
325{{define "codemenu"}}
302<details class="menu" data-clone>
326<details class="menu" data-clone>
303 <summary class="btn">{{t "repo.code"}}</summary>
327 <summary class="btn">{{t "repo.code"}}</summary>
@@ -371,6 +395,7 @@
371 </aside>
395 </aside>
372</div>
396</div>
373<script src="/assets/repo.js"></script>
397<script src="/assets/repo.js"></script>
398{{if and .Head .Head.PipeLive}}<script src="/assets/pipeline.js"></script>{{end}}
374{{template "layout-end" .}}
399{{template "layout-end" .}}
375{{end}}
400{{end}}
376
401