BlueGit

timfa bluegit

Merge branch 'stage' into 'master'

timfa

Authored 2026-10-27 · 3 weeks ago

Hash
a96e900e85cf11091e86467250c3dcb0343a93cc
Pipeline
Passed
23 files changed +402 −35
internal/i18n/catalog_blocked.go added +20 −0
@@ -0,0 +1,20 @@
1 package i18n
2
3 func init() {
4 addCatalog(en, map[string]string{
5 "pipe.blocked": "Waiting for manual action",
6 "pipe.blocked.tip": "Only manual jobs are left, plus jobs that wait for them. Start a manual job to continue; until then the pipeline does not count as running.",
7 })
8 addCatalog(nl, map[string]string{
9 "pipe.blocked": "Wacht op handmatige actie",
10 "pipe.blocked.tip": "Alleen handmatige jobs zijn nog over, plus jobs die daarop wachten. Start een handmatige job om verder te gaan; tot die tijd telt de pipeline niet als bezig.",
11 })
12 addCatalog(de, map[string]string{
13 "pipe.blocked": "Wartet auf manuelle Aktion",
14 "pipe.blocked.tip": "Nur noch manuelle Jobs und davon abhängige Jobs sind offen. Starte einen manuellen Job, um fortzufahren; bis dahin gilt die Pipeline nicht als laufend.",
15 })
16 addCatalog(fr, map[string]string{
17 "pipe.blocked": "En attente d'une action manuelle",
18 "pipe.blocked.tip": "Il ne reste que des jobs manuels et des jobs qui en dépendent. Lancez un job manuel pour continuer ; d'ici là, le pipeline ne compte pas comme en cours.",
19 })
20 }
@@ -0,0 +1,20 @@
1package i18n
2
3func init() {
4 addCatalog(en, map[string]string{
5 "pipe.blocked": "Waiting for manual action",
6 "pipe.blocked.tip": "Only manual jobs are left, plus jobs that wait for them. Start a manual job to continue; until then the pipeline does not count as running.",
7 })
8 addCatalog(nl, map[string]string{
9 "pipe.blocked": "Wacht op handmatige actie",
10 "pipe.blocked.tip": "Alleen handmatige jobs zijn nog over, plus jobs die daarop wachten. Start een handmatige job om verder te gaan; tot die tijd telt de pipeline niet als bezig.",
11 })
12 addCatalog(de, map[string]string{
13 "pipe.blocked": "Wartet auf manuelle Aktion",
14 "pipe.blocked.tip": "Nur noch manuelle Jobs und davon abhängige Jobs sind offen. Starte einen manuellen Job, um fortzufahren; bis dahin gilt die Pipeline nicht als laufend.",
15 })
16 addCatalog(fr, map[string]string{
17 "pipe.blocked": "En attente d'une action manuelle",
18 "pipe.blocked.tip": "Il ne reste que des jobs manuels et des jobs qui en dépendent. Lancez un job manuel pour continuer ; d'ici là, le pipeline ne compte pas comme en cours.",
19 })
20}
internal/i18n/catalog_pushsort.go added +28 −0
@@ -0,0 +1,28 @@
1 package i18n
2
3 func init() {
4 addCatalog(en, map[string]string{
5 "repo.sortPushed": "Last push",
6 "repo.sortPushedTip": "Sorted by most recent push; repositories without pushes come last, then by name.",
7 "repo.pushedAt": "Pushed %s",
8 "repo.neverPushed": "No pushes yet",
9 })
10 addCatalog(nl, map[string]string{
11 "repo.sortPushed": "Laatste push",
12 "repo.sortPushedTip": "Gesorteerd op de laatste push; repositories zonder push staan onderaan, daarna op naam.",
13 "repo.pushedAt": "Gepusht %s",
14 "repo.neverPushed": "Nog niet gepusht",
15 })
16 addCatalog(de, map[string]string{
17 "repo.sortPushed": "Letzter Push",
18 "repo.sortPushedTip": "Nach dem letzten Push sortiert; Repositories ohne Push stehen unten, danach nach Name.",
19 "repo.pushedAt": "Gepusht %s",
20 "repo.neverPushed": "Noch nicht gepusht",
21 })
22 addCatalog(fr, map[string]string{
23 "repo.sortPushed": "Dernier push",
24 "repo.sortPushedTip": "Trié par push le plus récent ; les dépôts sans push sont en bas, puis par nom.",
25 "repo.pushedAt": "Poussé %s",
26 "repo.neverPushed": "Pas encore de push",
27 })
28 }
@@ -0,0 +1,28 @@
1package i18n
2
3func init() {
4 addCatalog(en, map[string]string{
5 "repo.sortPushed": "Last push",
6 "repo.sortPushedTip": "Sorted by most recent push; repositories without pushes come last, then by name.",
7 "repo.pushedAt": "Pushed %s",
8 "repo.neverPushed": "No pushes yet",
9 })
10 addCatalog(nl, map[string]string{
11 "repo.sortPushed": "Laatste push",
12 "repo.sortPushedTip": "Gesorteerd op de laatste push; repositories zonder push staan onderaan, daarna op naam.",
13 "repo.pushedAt": "Gepusht %s",
14 "repo.neverPushed": "Nog niet gepusht",
15 })
16 addCatalog(de, map[string]string{
17 "repo.sortPushed": "Letzter Push",
18 "repo.sortPushedTip": "Nach dem letzten Push sortiert; Repositories ohne Push stehen unten, danach nach Name.",
19 "repo.pushedAt": "Gepusht %s",
20 "repo.neverPushed": "Noch nicht gepusht",
21 })
22 addCatalog(fr, map[string]string{
23 "repo.sortPushed": "Dernier push",
24 "repo.sortPushedTip": "Trié par push le plus récent ; les dépôts sans push sont en bas, puis par nom.",
25 "repo.pushedAt": "Poussé %s",
26 "repo.neverPushed": "Pas encore de push",
27 })
28}
internal/runner/runner.go +7 −0
@@ -152,6 +152,13 @@ func (r *Runner) Tick(ctx context.Context) {
152 152
153 153 func (r *Runner) schedule(ctx context.Context, p store.Pipeline) {
154 154 r.settle(ctx, p.ID)
155 if p.Status == "running" {
156 // Een pipeline die alleen nog op handmatige jobs wacht, is niet
157 // meer bezig (ook oude pipelines van voor deze regel).
158 if st, err := r.Store.RefreshPipelineStatus(ctx, p.ID); err == nil {
159 p.Status = st
160 }
161 }
155 162 if r.Hold != nil && r.Hold(p) {
156 163 return // wacht op de self-update
157 164 }
@@ -152,6 +152,13 @@ func (r *Runner) Tick(ctx context.Context) {
152
152
153func (r *Runner) schedule(ctx context.Context, p store.Pipeline) {
153func (r *Runner) schedule(ctx context.Context, p store.Pipeline) {
154 r.settle(ctx, p.ID)
154 r.settle(ctx, p.ID)
155 if p.Status == "running" {
156 // Een pipeline die alleen nog op handmatige jobs wacht, is niet
157 // meer bezig (ook oude pipelines van voor deze regel).
158 if st, err := r.Store.RefreshPipelineStatus(ctx, p.ID); err == nil {
159 p.Status = st
160 }
161 }
155 if r.Hold != nil && r.Hold(p) {
162 if r.Hold != nil && r.Hold(p) {
156 return // wacht op de self-update
163 return // wacht op de self-update
157 }
164 }
internal/server/activity_test.go +1 −1
@@ -182,7 +182,7 @@ func TestActivityHeatmap(t *testing.T) {
182 182 if strings.Contains(dash, `title="1 contribution on 6 June 2026"`) {
183 183 t.Fatal("dashboard toont Ada's commit")
184 184 }
185 if strings.Index(dash, "Activity") > strings.Index(dash, "<h2>Repositories</h2>") {
185 if strings.Index(dash, "Activity") > strings.Index(dash, "Repositories</span></h2>") {
186 186 t.Fatal("heatmap staat onder de repositorylijst")
187 187 }
188 188
@@ -182,7 +182,7 @@ func TestActivityHeatmap(t *testing.T) {
182 if strings.Contains(dash, `title="1 contribution on 6 June 2026"`) {
182 if strings.Contains(dash, `title="1 contribution on 6 June 2026"`) {
183 t.Fatal("dashboard toont Ada's commit")
183 t.Fatal("dashboard toont Ada's commit")
184 }
184 }
185 if strings.Index(dash, "Activity") > strings.Index(dash, "<h2>Repositories</h2>") {
185 if strings.Index(dash, "Activity") > strings.Index(dash, "Repositories</span></h2>") {
186 t.Fatal("heatmap staat onder de repositorylijst")
186 t.Fatal("heatmap staat onder de repositorylijst")
187 }
187 }
188
188
internal/server/api_openapi.go +1 −1
@@ -237,7 +237,7 @@ func apiSchemas() map[string]any {
237 237 "id": integer("Pipeline id."),
238 238 "sha": str("Commit SHA."),
239 239 "ref": str("Git ref, for example refs/heads/master."),
240 "status": str("Pipeline status. A pipeline stopped by a newer pipeline stays canceled; see cancel_reason."),
240 "status": str("Pipeline status: queued, running, success, failed, canceled, waiting_for_update, waiting_for_job or manual. manual means only manual jobs are left, plus jobs that wait on them; such a pipeline is not running and has no finished_at until a manual job is played. A pipeline stopped by a newer pipeline stays canceled; see cancel_reason."),
241 241 "display_status": str("Status as the UI shows it: obsolete when every canceled job was superseded by a newer pipeline on the same ref, otherwise equal to status. Only in list and get responses."),
242 242 "cancel_reason": str("For status canceled: superseded (a newer pipeline started for the same ref) or manual. Null otherwise. Only in list and get responses."),
243 243 "waiting_for": map[string]any{"type": "object", "nullable": true, "description": "For status waiting_for_job: the running doNotInterrupt job (job_id, job_name, pipeline_id) in an older pipeline on the same ref that this pipeline waits for. Only in list and get responses."},
@@ -237,7 +237,7 @@ func apiSchemas() map[string]any {
237 "id": integer("Pipeline id."),
237 "id": integer("Pipeline id."),
238 "sha": str("Commit SHA."),
238 "sha": str("Commit SHA."),
239 "ref": str("Git ref, for example refs/heads/master."),
239 "ref": str("Git ref, for example refs/heads/master."),
240 "status": str("Pipeline status. A pipeline stopped by a newer pipeline stays canceled; see cancel_reason."),
240 "status": str("Pipeline status: queued, running, success, failed, canceled, waiting_for_update, waiting_for_job or manual. manual means only manual jobs are left, plus jobs that wait on them; such a pipeline is not running and has no finished_at until a manual job is played. A pipeline stopped by a newer pipeline stays canceled; see cancel_reason."),
241 "display_status": str("Status as the UI shows it: obsolete when every canceled job was superseded by a newer pipeline on the same ref, otherwise equal to status. Only in list and get responses."),
241 "display_status": str("Status as the UI shows it: obsolete when every canceled job was superseded by a newer pipeline on the same ref, otherwise equal to status. Only in list and get responses."),
242 "cancel_reason": str("For status canceled: superseded (a newer pipeline started for the same ref) or manual. Null otherwise. Only in list and get responses."),
242 "cancel_reason": str("For status canceled: superseded (a newer pipeline started for the same ref) or manual. Null otherwise. Only in list and get responses."),
243 "waiting_for": map[string]any{"type": "object", "nullable": true, "description": "For status waiting_for_job: the running doNotInterrupt job (job_id, job_name, pipeline_id) in an older pipeline on the same ref that this pipeline waits for. Only in list and get responses."},
243 "waiting_for": map[string]any{"type": "object", "nullable": true, "description": "For status waiting_for_job: the running doNotInterrupt job (job_id, job_name, pipeline_id) in an older pipeline on the same ref that this pipeline waits for. Only in list and get responses."},
internal/server/auth_handlers.go +4 −0
@@ -5,6 +5,8 @@ import (
5 5 "net/http"
6 6 "strings"
7 7 "time"
8
9 "gitlab.com/Timfa/bluegit/internal/store"
8 10 )
9 11
10 12 func (s *Server) login(w http.ResponseWriter, r *http.Request) {
@@ -103,6 +105,7 @@ func (s *Server) home(w http.ResponseWriter, r *http.Request) {
103 105 http.Error(w, s.tr(r, "err.overview"), http.StatusInternalServerError)
104 106 return
105 107 }
108 store.SortReposByPush(repos)
106 109 v.Repos = repos
107 110 v.ReleaseRepos = s.releaseOnlyRepos(r, v.User.ID)
108 111 groups, err := s.Store.ListGroups(r.Context(), v.User.ID)
@@ -127,6 +130,7 @@ func (s *Server) home(w http.ResponseWriter, r *http.Request) {
127 130 ids, err := s.Store.ListRepoIDs(r.Context(), 0)
128 131 if err == nil {
129 132 v.Repos, _ = s.Store.ReposByIDs(r.Context(), ids)
133 store.SortReposByPush(v.Repos)
130 134 }
131 135 v.ReleaseRepos = s.releaseOnlyRepos(r, 0)
132 136 v.Title = ""
@@ -5,6 +5,8 @@ import (
5 "net/http"
5 "net/http"
6 "strings"
6 "strings"
7 "time"
7 "time"
8
9 "gitlab.com/Timfa/bluegit/internal/store"
8)
10)
9
11
10func (s *Server) login(w http.ResponseWriter, r *http.Request) {
12func (s *Server) login(w http.ResponseWriter, r *http.Request) {
@@ -103,6 +105,7 @@ func (s *Server) home(w http.ResponseWriter, r *http.Request) {
103 http.Error(w, s.tr(r, "err.overview"), http.StatusInternalServerError)
105 http.Error(w, s.tr(r, "err.overview"), http.StatusInternalServerError)
104 return
106 return
105 }
107 }
108 store.SortReposByPush(repos)
106 v.Repos = repos
109 v.Repos = repos
107 v.ReleaseRepos = s.releaseOnlyRepos(r, v.User.ID)
110 v.ReleaseRepos = s.releaseOnlyRepos(r, v.User.ID)
108 groups, err := s.Store.ListGroups(r.Context(), v.User.ID)
111 groups, err := s.Store.ListGroups(r.Context(), v.User.ID)
@@ -127,6 +130,7 @@ func (s *Server) home(w http.ResponseWriter, r *http.Request) {
127 ids, err := s.Store.ListRepoIDs(r.Context(), 0)
130 ids, err := s.Store.ListRepoIDs(r.Context(), 0)
128 if err == nil {
131 if err == nil {
129 v.Repos, _ = s.Store.ReposByIDs(r.Context(), ids)
132 v.Repos, _ = s.Store.ReposByIDs(r.Context(), ids)
133 store.SortReposByPush(v.Repos)
130 }
134 }
131 v.ReleaseRepos = s.releaseOnlyRepos(r, 0)
135 v.ReleaseRepos = s.releaseOnlyRepos(r, 0)
132 v.Title = ""
136 v.Title = ""
internal/server/events.go +18 −0
@@ -45,6 +45,9 @@ func (s *Server) postReceive(ctx context.Context, repo store.Repo, user store.Us
45 45 // git http, SSH en postReceive zijn de enige aanroepers.
46 46 func (s *Server) AfterPush(repo store.Repo, user store.User, before, after map[string]string) {
47 47 s.refsChanged(repo)
48 if s.Store != nil && refsMoved(before, after) {
49 _ = s.Store.TouchPushed(context.Background(), repo.ID, time.Now())
50 }
48 51 if after == nil {
49 52 return
50 53 }
@@ -438,3 +441,18 @@ func gitSHA(r *http.Request, gitBin, dir, rev string) (string, error) {
438 441 }
439 442 return strings.TrimSpace(string(out)), nil
440 443 }
444
445 // refsMoved meldt of een push werkelijk een ref veranderde.
446 func refsMoved(before, after map[string]string) bool {
447 for ref, sha := range after {
448 if before[ref] != sha {
449 return true
450 }
451 }
452 for ref := range before {
453 if _, ok := after[ref]; !ok && after != nil {
454 return true
455 }
456 }
457 return false
458 }
@@ -45,6 +45,9 @@ func (s *Server) postReceive(ctx context.Context, repo store.Repo, user store.Us
45// git http, SSH en postReceive zijn de enige aanroepers.
45// git http, SSH en postReceive zijn de enige aanroepers.
46func (s *Server) AfterPush(repo store.Repo, user store.User, before, after map[string]string) {
46func (s *Server) AfterPush(repo store.Repo, user store.User, before, after map[string]string) {
47 s.refsChanged(repo)
47 s.refsChanged(repo)
48 if s.Store != nil && refsMoved(before, after) {
49 _ = s.Store.TouchPushed(context.Background(), repo.ID, time.Now())
50 }
48 if after == nil {
51 if after == nil {
49 return
52 return
50 }
53 }
@@ -438,3 +441,18 @@ func gitSHA(r *http.Request, gitBin, dir, rev string) (string, error) {
438 }
441 }
439 return strings.TrimSpace(string(out)), nil
442 return strings.TrimSpace(string(out)), nil
440}
443}
444
445// refsMoved meldt of een push werkelijk een ref veranderde.
446func refsMoved(before, after map[string]string) bool {
447 for ref, sha := range after {
448 if before[ref] != sha {
449 return true
450 }
451 }
452 for ref := range before {
453 if _, ok := after[ref]; !ok && after != nil {
454 return true
455 }
456 }
457 return false
458}
internal/server/pipeline_page.go +2 −1
@@ -329,7 +329,8 @@ func displayStatus(pipe string, jobs []store.Job) string {
329 329 case "running":
330 330 return "running"
331 331 case "manual":
332 return "manual"
332 // Alleen handmatige jobs (en wat daarop wacht) zijn over.
333 return "blocked"
333 334 case "queued":
334 335 return "pending"
335 336 case "canceled":
@@ -329,7 +329,8 @@ func displayStatus(pipe string, jobs []store.Job) string {
329 case "running":
329 case "running":
330 return "running"
330 return "running"
331 case "manual":
331 case "manual":
332 return "manual"
332 // Alleen handmatige jobs (en wat daarop wacht) zijn over.
333 return "blocked"
333 case "queued":
334 case "queued":
334 return "pending"
335 return "pending"
335 case "canceled":
336 case "canceled":
internal/server/profile_test.go +1 −1
@@ -115,7 +115,7 @@ func TestProfilePage(t *testing.T) {
115 115 t.Fatalf("dashboard mist %q", want)
116 116 }
117 117 }
118 if strings.Index(dash, "Activity") > strings.Index(dash, "<h2>Repositories</h2>") {
118 if strings.Index(dash, "Activity") > strings.Index(dash, "Repositories</span></h2>") {
119 119 t.Fatal("heatmap staat onder de repositorylijst")
120 120 }
121 121
@@ -115,7 +115,7 @@ func TestProfilePage(t *testing.T) {
115 t.Fatalf("dashboard mist %q", want)
115 t.Fatalf("dashboard mist %q", want)
116 }
116 }
117 }
117 }
118 if strings.Index(dash, "Activity") > strings.Index(dash, "<h2>Repositories</h2>") {
118 if strings.Index(dash, "Activity") > strings.Index(dash, "Repositories</span></h2>") {
119 t.Fatal("heatmap staat onder de repositorylijst")
119 t.Fatal("heatmap staat onder de repositorylijst")
120 }
120 }
121
121
internal/server/pushsort_test.go added +24 −0
@@ -0,0 +1,24 @@
1 package server
2
3 import "testing"
4
5 func TestRefsMoved(t *testing.T) {
6 if refsMoved(map[string]string{"refs/heads/a": "1"}, map[string]string{"refs/heads/a": "1"}) {
7 t.Fatal("niets veranderd")
8 }
9 if !refsMoved(map[string]string{"refs/heads/a": "1"}, map[string]string{"refs/heads/a": "2"}) {
10 t.Fatal("ref verschoof")
11 }
12 if !refsMoved(nil, map[string]string{"refs/tags/v1": "1"}) {
13 t.Fatal("nieuwe tag")
14 }
15 if !refsMoved(map[string]string{"refs/heads/a": "1"}, map[string]string{}) {
16 t.Fatal("verwijderde branch")
17 }
18 }
19
20 func TestManualPipelineShowsBlocked(t *testing.T) {
21 if got := displayStatus("manual", nil); got != "blocked" {
22 t.Fatalf("manual toont %q", got)
23 }
24 }
@@ -0,0 +1,24 @@
1package server
2
3import "testing"
4
5func TestRefsMoved(t *testing.T) {
6 if refsMoved(map[string]string{"refs/heads/a": "1"}, map[string]string{"refs/heads/a": "1"}) {
7 t.Fatal("niets veranderd")
8 }
9 if !refsMoved(map[string]string{"refs/heads/a": "1"}, map[string]string{"refs/heads/a": "2"}) {
10 t.Fatal("ref verschoof")
11 }
12 if !refsMoved(nil, map[string]string{"refs/tags/v1": "1"}) {
13 t.Fatal("nieuwe tag")
14 }
15 if !refsMoved(map[string]string{"refs/heads/a": "1"}, map[string]string{}) {
16 t.Fatal("verwijderde branch")
17 }
18}
19
20func TestManualPipelineShowsBlocked(t *testing.T) {
21 if got := displayStatus("manual", nil); got != "blocked" {
22 t.Fatalf("manual toont %q", got)
23 }
24}
internal/server/server.go +5 −2
@@ -307,8 +307,9 @@ func (s *Server) mustTemplates() {
307 307 }
308 308 return i18n.T(l, key, n)
309 309 },
310 "roleName": func(r access.Role) string { return i18n.T(l, "role."+string(r)) },
311 "visName": func(v string) string { return i18n.T(l, "vis."+v) },
310 "roleName": func(r access.Role) string { return i18n.T(l, "role."+string(r)) },
311 "visName": func(v string) string { return i18n.T(l, "vis."+v) },
312 "pushedLabel": func(r store.Repo) string { return pushedLabel(l, r) },
312 313 "presetName": func(id string) string {
313 314 label := i18n.T(l, "set.preset."+id)
314 315 if label == "set.preset."+id {
@@ -706,6 +707,7 @@ type View struct {
706 707 Langs []LangChoice
707 708 Query string
708 709 SortDir string
710 SortBy string
709 711 FlipDir string
710 712 Cards []RepoCard
711 713 Head *CommitRow
@@ -755,6 +757,7 @@ type RepoCard struct {
755 757 Stars int
756 758 Starred bool
757 759 When string
760 Pushed string
758 761 }
759 762
760 763 // AccountLink is een naam die naar een profiel wijst.
@@ -307,8 +307,9 @@ func (s *Server) mustTemplates() {
307 }
307 }
308 return i18n.T(l, key, n)
308 return i18n.T(l, key, n)
309 },
309 },
310 "roleName": func(r access.Role) string { return i18n.T(l, "role."+string(r)) },
310 "roleName": func(r access.Role) string { return i18n.T(l, "role."+string(r)) },
311 "visName": func(v string) string { return i18n.T(l, "vis."+v) },
311 "visName": func(v string) string { return i18n.T(l, "vis."+v) },
312 "pushedLabel": func(r store.Repo) string { return pushedLabel(l, r) },
312 "presetName": func(id string) string {
313 "presetName": func(id string) string {
313 label := i18n.T(l, "set.preset."+id)
314 label := i18n.T(l, "set.preset."+id)
314 if label == "set.preset."+id {
315 if label == "set.preset."+id {
@@ -706,6 +707,7 @@ type View struct {
706 Langs []LangChoice
707 Langs []LangChoice
707 Query string
708 Query string
708 SortDir string
709 SortDir string
710 SortBy string
709 FlipDir string
711 FlipDir string
710 Cards []RepoCard
712 Cards []RepoCard
711 Head *CommitRow
713 Head *CommitRow
@@ -755,6 +757,7 @@ type RepoCard struct {
755 Stars int
757 Stars int
756 Starred bool
758 Starred bool
757 When string
759 When string
760 Pushed string
758}
761}
759
762
760// AccountLink is een naam die naar een profiel wijst.
763// AccountLink is een naam die naar een profiel wijst.
internal/server/settings_handlers.go +26 −10
@@ -568,7 +568,7 @@ func (s *Server) groupPage(w http.ResponseWriter, r *http.Request) {
568 568 tab = ""
569 569 }
570 570 v.Tab = tab
571 all, _ := s.Store.ReposByGroup(r.Context(), g.ID)
571 all, _ := s.Store.ReposByGroup(r.Context(), g.ID) // laatste push eerst
572 572 uid := int64(0)
573 573 if v.User != nil {
574 574 uid = v.User.ID
@@ -592,7 +592,11 @@ func (s *Server) groupPage(w http.ResponseWriter, r *http.Request) {
592 592 if dir != "desc" {
593 593 dir = "asc"
594 594 }
595 v.Query, v.SortDir = q, dir
595 by := r.URL.Query().Get("sort")
596 if by != "name" {
597 by = "pushed"
598 }
599 v.Query, v.SortDir, v.SortBy = q, dir, by
596 600 if dir == "desc" {
597 601 v.FlipDir = "asc"
598 602 } else {
@@ -607,13 +611,17 @@ func (s *Server) groupPage(w http.ResponseWriter, r *http.Request) {
607 611 }
608 612 repos = filtered
609 613 }
610 sort.Slice(repos, func(i, j int) bool {
611 a, b := strings.ToLower(repos[i].Name), strings.ToLower(repos[j].Name)
612 if dir == "desc" {
613 return a > b
614 }
615 return a < b
616 })
614 if by == "pushed" {
615 store.SortReposByPush(repos)
616 } else {
617 sort.Slice(repos, func(i, j int) bool {
618 a, b := strings.ToLower(repos[i].Name), strings.ToLower(repos[j].Name)
619 if dir == "desc" {
620 return a > b
621 }
622 return a < b
623 })
624 }
617 625 ids := make([]int64, len(repos))
618 626 for i, repo := range repos {
619 627 ids[i] = repo.ID
@@ -623,7 +631,7 @@ func (s *Server) groupPage(w http.ResponseWriter, r *http.Request) {
623 631 for _, repo := range repos {
624 632 v.Cards = append(v.Cards, RepoCard{
625 633 Repo: repo, Stars: counts[repo.ID], Starred: mine[repo.ID],
626 When: i18n.FormatDate(lang, repo.CreatedAt),
634 When: i18n.FormatDate(lang, repo.CreatedAt), Pushed: pushedLabel(lang, repo),
627 635 })
628 636 }
629 637 v.Repos = repos
@@ -689,3 +697,11 @@ func hookEventChoices(selected []string) []HookEventChoice {
689 697 }
690 698 return out
691 699 }
700
701 // pushedLabel is de korte tekst bij de laatste push van een repo.
702 func pushedLabel(lang i18n.Lang, repo store.Repo) string {
703 if repo.PushedAt.IsZero() {
704 return i18n.T(lang, "repo.neverPushed")
705 }
706 return i18n.T(lang, "repo.pushedAt", i18n.FormatDate(lang, repo.PushedAt))
707 }
@@ -568,7 +568,7 @@ func (s *Server) groupPage(w http.ResponseWriter, r *http.Request) {
568 tab = ""
568 tab = ""
569 }
569 }
570 v.Tab = tab
570 v.Tab = tab
571 all, _ := s.Store.ReposByGroup(r.Context(), g.ID)
571 all, _ := s.Store.ReposByGroup(r.Context(), g.ID) // laatste push eerst
572 uid := int64(0)
572 uid := int64(0)
573 if v.User != nil {
573 if v.User != nil {
574 uid = v.User.ID
574 uid = v.User.ID
@@ -592,7 +592,11 @@ func (s *Server) groupPage(w http.ResponseWriter, r *http.Request) {
592 if dir != "desc" {
592 if dir != "desc" {
593 dir = "asc"
593 dir = "asc"
594 }
594 }
595 v.Query, v.SortDir = q, dir
595 by := r.URL.Query().Get("sort")
596 if by != "name" {
597 by = "pushed"
598 }
599 v.Query, v.SortDir, v.SortBy = q, dir, by
596 if dir == "desc" {
600 if dir == "desc" {
597 v.FlipDir = "asc"
601 v.FlipDir = "asc"
598 } else {
602 } else {
@@ -607,13 +611,17 @@ func (s *Server) groupPage(w http.ResponseWriter, r *http.Request) {
607 }
611 }
608 repos = filtered
612 repos = filtered
609 }
613 }
610 sort.Slice(repos, func(i, j int) bool {
614 if by == "pushed" {
611 a, b := strings.ToLower(repos[i].Name), strings.ToLower(repos[j].Name)
615 store.SortReposByPush(repos)
612 if dir == "desc" {
616 } else {
613 return a > b
617 sort.Slice(repos, func(i, j int) bool {
614 }
618 a, b := strings.ToLower(repos[i].Name), strings.ToLower(repos[j].Name)
615 return a < b
619 if dir == "desc" {
616 })
620 return a > b
621 }
622 return a < b
623 })
624 }
617 ids := make([]int64, len(repos))
625 ids := make([]int64, len(repos))
618 for i, repo := range repos {
626 for i, repo := range repos {
619 ids[i] = repo.ID
627 ids[i] = repo.ID
@@ -623,7 +631,7 @@ func (s *Server) groupPage(w http.ResponseWriter, r *http.Request) {
623 for _, repo := range repos {
631 for _, repo := range repos {
624 v.Cards = append(v.Cards, RepoCard{
632 v.Cards = append(v.Cards, RepoCard{
625 Repo: repo, Stars: counts[repo.ID], Starred: mine[repo.ID],
633 Repo: repo, Stars: counts[repo.ID], Starred: mine[repo.ID],
626 When: i18n.FormatDate(lang, repo.CreatedAt),
634 When: i18n.FormatDate(lang, repo.CreatedAt), Pushed: pushedLabel(lang, repo),
627 })
635 })
628 }
636 }
629 v.Repos = repos
637 v.Repos = repos
@@ -689,3 +697,11 @@ func hookEventChoices(selected []string) []HookEventChoice {
689 }
697 }
690 return out
698 return out
691}
699}
700
701// pushedLabel is de korte tekst bij de laatste push van een repo.
702func pushedLabel(lang i18n.Lang, repo store.Repo) string {
703 if repo.PushedAt.IsZero() {
704 return i18n.T(lang, "repo.neverPushed")
705 }
706 return i18n.T(lang, "repo.pushedAt", i18n.FormatDate(lang, repo.PushedAt))
707}
internal/server/setup.go +18 −0
@@ -4,11 +4,13 @@ import (
4 4 "context"
5 5 "net/http"
6 6 "os"
7 "strconv"
7 8 "strings"
8 9 "time"
9 10
10 11 "gitlab.com/Timfa/bluegit/internal/gitrepo"
11 12 "gitlab.com/Timfa/bluegit/internal/state"
13 "gitlab.com/Timfa/bluegit/internal/store"
12 14 )
13 15
14 16 // dirUsage is de laatst getelde grootte van de gekozen map.
@@ -250,5 +252,21 @@ func (s *Server) RefreshHooks() {
250 252 if err := gitrepo.InstallHook(dir, s.HookBin); err != nil && s.Log != nil {
251 253 s.Log.Error("hook", "repo", repo.FullPath(), "err", err)
252 254 }
255 if repo.PushedAt.IsZero() {
256 s.backfillPushed(repo, dir)
257 }
258 }
259 }
260
261 // backfillPushed vult pushed_at eenmalig voor repos van voor deze kolom:
262 // de nieuwste committijd over alle branches en tags. Een lege repo blijft leeg.
263 func (s *Server) backfillPushed(repo store.Repo, dir string) {
264 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
265 defer cancel()
266 raw := gitOne(ctx, s.Git, dir, "for-each-ref", "--sort=-committerdate", "--count=1", "--format=%(committerdate:unix)", "refs/heads", "refs/tags")
267 sec, err := strconv.ParseInt(strings.TrimSpace(raw), 10, 64)
268 if err != nil || sec <= 0 {
269 return
253 270 }
271 _ = s.Store.TouchPushed(ctx, repo.ID, time.Unix(sec, 0))
254 272 }
@@ -4,11 +4,13 @@ import (
4 "context"
4 "context"
5 "net/http"
5 "net/http"
6 "os"
6 "os"
7 "strconv"
7 "strings"
8 "strings"
8 "time"
9 "time"
9
10
10 "gitlab.com/Timfa/bluegit/internal/gitrepo"
11 "gitlab.com/Timfa/bluegit/internal/gitrepo"
11 "gitlab.com/Timfa/bluegit/internal/state"
12 "gitlab.com/Timfa/bluegit/internal/state"
13 "gitlab.com/Timfa/bluegit/internal/store"
12)
14)
13
15
14// dirUsage is de laatst getelde grootte van de gekozen map.
16// dirUsage is de laatst getelde grootte van de gekozen map.
@@ -250,5 +252,21 @@ func (s *Server) RefreshHooks() {
250 if err := gitrepo.InstallHook(dir, s.HookBin); err != nil && s.Log != nil {
252 if err := gitrepo.InstallHook(dir, s.HookBin); err != nil && s.Log != nil {
251 s.Log.Error("hook", "repo", repo.FullPath(), "err", err)
253 s.Log.Error("hook", "repo", repo.FullPath(), "err", err)
252 }
254 }
255 if repo.PushedAt.IsZero() {
256 s.backfillPushed(repo, dir)
257 }
258 }
259}
260
261// backfillPushed vult pushed_at eenmalig voor repos van voor deze kolom:
262// de nieuwste committijd over alle branches en tags. Een lege repo blijft leeg.
263func (s *Server) backfillPushed(repo store.Repo, dir string) {
264 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
265 defer cancel()
266 raw := gitOne(ctx, s.Git, dir, "for-each-ref", "--sort=-committerdate", "--count=1", "--format=%(committerdate:unix)", "refs/heads", "refs/tags")
267 sec, err := strconv.ParseInt(strings.TrimSpace(raw), 10, 64)
268 if err != nil || sec <= 0 {
269 return
253 }
270 }
271 _ = s.Store.TouchPushed(ctx, repo.ID, time.Unix(sec, 0))
254}
272}
internal/server/static/float.js +2 −1
@@ -313,7 +313,8 @@
313 313 (function () {
314 314 var tips = {
315 315 obsolete: document.body.getAttribute("data-obsolete-tip") || "canceled because a newer pipeline started for the same ref",
316 waiting_for_job: document.body.getAttribute("data-waitjob-tip") || "waiting for a non-interruptible job in an older pipeline on the same ref"
316 waiting_for_job: document.body.getAttribute("data-waitjob-tip") || "waiting for a non-interruptible job in an older pipeline on the same ref",
317 blocked: document.body.getAttribute("data-blocked-tip") || "only manual jobs are left; start one to continue"
317 318 };
318 319 function tag() {
319 320 Object.keys(tips).forEach(function (cls) { tagOne(cls, tips[cls]); });
@@ -313,7 +313,8 @@
313(function () {
313(function () {
314 var tips = {
314 var tips = {
315 obsolete: document.body.getAttribute("data-obsolete-tip") || "canceled because a newer pipeline started for the same ref",
315 obsolete: document.body.getAttribute("data-obsolete-tip") || "canceled because a newer pipeline started for the same ref",
316 waiting_for_job: document.body.getAttribute("data-waitjob-tip") || "waiting for a non-interruptible job in an older pipeline on the same ref"
316 waiting_for_job: document.body.getAttribute("data-waitjob-tip") || "waiting for a non-interruptible job in an older pipeline on the same ref",
317 blocked: document.body.getAttribute("data-blocked-tip") || "only manual jobs are left; start one to continue"
317 };
318 };
318 function tag() {
319 function tag() {
319 Object.keys(tips).forEach(function (cls) { tagOne(cls, tips[cls]); });
320 Object.keys(tips).forEach(function (cls) { tagOne(cls, tips[cls]); });
internal/server/static/style.css +7 −0
@@ -632,12 +632,19 @@ svg.ico { width: 14px; height: 14px; flex: none; }
632 632 .status.running { background: #e7f0ff; color: #1f6feb; }
633 633 .status.canceled { background: #f3f0f0; color: #57606a; }
634 634 .status.obsolete { background: #f4f5f7; color: #8c959f; font-weight: 600; }
635 .status.blocked { background: #eef2f7; color: #57606a; }
635 636 .mark { position: relative; width: 16px; height: 16px; border-radius: 50%; display: inline-block; flex: none; background: #8c959f; }
636 637 .status.passed .mark, .stage-dot.passed .mark { background: #1aaa55; }
637 638 .status.failed .mark, .stage-dot.failed .mark { background: #dd2b0e; }
638 639 .status.warning .mark, .stage-dot.warning .mark { background: #c17d10; }
639 640 .status.running .mark, .stage-dot.running .mark { background: #1f75cb; }
640 641 .status.canceled .mark, .stage-dot.canceled .mark { background: #8c959f; }
642 .status.blocked .mark, .stage-dot.blocked .mark { background: #57606a; }
643 .blocked .mark::before, .blocked .mark::after {
644 content: ""; position: absolute; top: 4px; width: 2px; height: 8px; background: #fff;
645 }
646 .blocked .mark::before { left: 5px; }
647 .blocked .mark::after { left: 9px; }
641 648 .status.obsolete .mark, .stage-dot.obsolete .mark { background: transparent; box-shadow: inset 0 0 0 2px #afb8c1; }
642 649 .obsolete .mark::after {
643 650 content: ""; position: absolute; left: 3px; top: 7px; width: 10px; height: 2px; background: #afb8c1; transform: rotate(-45deg);
@@ -632,12 +632,19 @@ svg.ico { width: 14px; height: 14px; flex: none; }
632.status.running { background: #e7f0ff; color: #1f6feb; }
632.status.running { background: #e7f0ff; color: #1f6feb; }
633.status.canceled { background: #f3f0f0; color: #57606a; }
633.status.canceled { background: #f3f0f0; color: #57606a; }
634.status.obsolete { background: #f4f5f7; color: #8c959f; font-weight: 600; }
634.status.obsolete { background: #f4f5f7; color: #8c959f; font-weight: 600; }
635.status.blocked { background: #eef2f7; color: #57606a; }
635.mark { position: relative; width: 16px; height: 16px; border-radius: 50%; display: inline-block; flex: none; background: #8c959f; }
636.mark { position: relative; width: 16px; height: 16px; border-radius: 50%; display: inline-block; flex: none; background: #8c959f; }
636.status.passed .mark, .stage-dot.passed .mark { background: #1aaa55; }
637.status.passed .mark, .stage-dot.passed .mark { background: #1aaa55; }
637.status.failed .mark, .stage-dot.failed .mark { background: #dd2b0e; }
638.status.failed .mark, .stage-dot.failed .mark { background: #dd2b0e; }
638.status.warning .mark, .stage-dot.warning .mark { background: #c17d10; }
639.status.warning .mark, .stage-dot.warning .mark { background: #c17d10; }
639.status.running .mark, .stage-dot.running .mark { background: #1f75cb; }
640.status.running .mark, .stage-dot.running .mark { background: #1f75cb; }
640.status.canceled .mark, .stage-dot.canceled .mark { background: #8c959f; }
641.status.canceled .mark, .stage-dot.canceled .mark { background: #8c959f; }
642.status.blocked .mark, .stage-dot.blocked .mark { background: #57606a; }
643.blocked .mark::before, .blocked .mark::after {
644 content: ""; position: absolute; top: 4px; width: 2px; height: 8px; background: #fff;
645}
646.blocked .mark::before { left: 5px; }
647.blocked .mark::after { left: 9px; }
641.status.obsolete .mark, .stage-dot.obsolete .mark { background: transparent; box-shadow: inset 0 0 0 2px #afb8c1; }
648.status.obsolete .mark, .stage-dot.obsolete .mark { background: transparent; box-shadow: inset 0 0 0 2px #afb8c1; }
642.obsolete .mark::after {
649.obsolete .mark::after {
643 content: ""; position: absolute; left: 3px; top: 7px; width: 10px; height: 2px; background: #afb8c1; transform: rotate(-45deg);
650 content: ""; position: absolute; left: 3px; top: 7px; width: 10px; height: 2px; background: #afb8c1; transform: rotate(-45deg);
internal/server/templates/collab.html +5 −3
@@ -981,8 +981,10 @@
981 981 <form class="bar" method="get" action="/groups/{{.Group.Path}}">
982 982 <input type="search" name="q" value="{{.Query}}" placeholder="{{t "group.search"}}" aria-label="{{t "group.search"}}">
983 983 <input type="hidden" name="dir" value="{{.SortDir}}">
984 <span class="sortlabel">{{t "group.sort"}}</span>
985 <a class="iconbtn" href="/groups/{{.Group.Path}}?q={{urlquery .Query}}&amp;dir={{.FlipDir}}" aria-label="{{t "group.direction"}}">{{if eq .SortDir "desc"}}↓{{else}}↑{{end}}</a>
984 <input type="hidden" name="sort" value="{{.SortBy}}">
985 <a class="btn ghost tiny{{if eq .SortBy "pushed"}} on{{end}}" href="/groups/{{.Group.Path}}?q={{urlquery .Query}}&amp;sort=pushed" data-tip="{{t "repo.sortPushedTip"}}" aria-current="{{if eq .SortBy "pushed"}}true{{else}}false{{end}}">{{t "repo.sortPushed"}}</a>
986 <a class="btn ghost tiny{{if eq .SortBy "name"}} on{{end}}" href="/groups/{{.Group.Path}}?q={{urlquery .Query}}&amp;sort=name&amp;dir={{.SortDir}}" aria-current="{{if eq .SortBy "name"}}true{{else}}false{{end}}">{{t "group.sort"}}</a>
987 {{if eq .SortBy "name"}}<a class="iconbtn" href="/groups/{{.Group.Path}}?q={{urlquery .Query}}&amp;sort=name&amp;dir={{.FlipDir}}" aria-label="{{t "group.direction"}}">{{if eq .SortDir "desc"}}↓{{else}}↑{{end}}</a>{{end}}
986 988 </form>
987 989 <ul class="repolist">
988 990 {{range .Cards}}
@@ -991,7 +993,7 @@
991 993 <a class="reponame" href="/{{.Repo.FullPath}}">{{.Repo.Name}}</a>
992 994 {{template "visicon" .Repo.Visibility}}
993 995 <span class="stars" aria-label="{{t "group.star"}}">★ {{.Stars}}</span>
994 <span class="muted grown">{{t "group.created" .When}}</span>
996 <span class="muted grown"><span data-tip="{{t "repo.sortPushedTip"}}">{{.Pushed}}</span> · {{t "group.created" .When}}</span>
995 997 <details class="rowmenu">
996 998 <summary aria-label="{{t "group.menu"}}">⋯</summary>
997 999 <div class="menu-panel">
@@ -981,8 +981,10 @@
981<form class="bar" method="get" action="/groups/{{.Group.Path}}">
981<form class="bar" method="get" action="/groups/{{.Group.Path}}">
982 <input type="search" name="q" value="{{.Query}}" placeholder="{{t "group.search"}}" aria-label="{{t "group.search"}}">
982 <input type="search" name="q" value="{{.Query}}" placeholder="{{t "group.search"}}" aria-label="{{t "group.search"}}">
983 <input type="hidden" name="dir" value="{{.SortDir}}">
983 <input type="hidden" name="dir" value="{{.SortDir}}">
984 <span class="sortlabel">{{t "group.sort"}}</span>
984 <input type="hidden" name="sort" value="{{.SortBy}}">
985 <a class="iconbtn" href="/groups/{{.Group.Path}}?q={{urlquery .Query}}&amp;dir={{.FlipDir}}" aria-label="{{t "group.direction"}}">{{if eq .SortDir "desc"}}↓{{else}}↑{{end}}</a>
985 <a class="btn ghost tiny{{if eq .SortBy "pushed"}} on{{end}}" href="/groups/{{.Group.Path}}?q={{urlquery .Query}}&amp;sort=pushed" data-tip="{{t "repo.sortPushedTip"}}" aria-current="{{if eq .SortBy "pushed"}}true{{else}}false{{end}}">{{t "repo.sortPushed"}}</a>
986 <a class="btn ghost tiny{{if eq .SortBy "name"}} on{{end}}" href="/groups/{{.Group.Path}}?q={{urlquery .Query}}&amp;sort=name&amp;dir={{.SortDir}}" aria-current="{{if eq .SortBy "name"}}true{{else}}false{{end}}">{{t "group.sort"}}</a>
987 {{if eq .SortBy "name"}}<a class="iconbtn" href="/groups/{{.Group.Path}}?q={{urlquery .Query}}&amp;sort=name&amp;dir={{.FlipDir}}" aria-label="{{t "group.direction"}}">{{if eq .SortDir "desc"}}↓{{else}}↑{{end}}</a>{{end}}
986</form>
988</form>
987<ul class="repolist">
989<ul class="repolist">
988 {{range .Cards}}
990 {{range .Cards}}
@@ -991,7 +993,7 @@
991 <a class="reponame" href="/{{.Repo.FullPath}}">{{.Repo.Name}}</a>
993 <a class="reponame" href="/{{.Repo.FullPath}}">{{.Repo.Name}}</a>
992 {{template "visicon" .Repo.Visibility}}
994 {{template "visicon" .Repo.Visibility}}
993 <span class="stars" aria-label="{{t "group.star"}}">★ {{.Stars}}</span>
995 <span class="stars" aria-label="{{t "group.star"}}">★ {{.Stars}}</span>
994 <span class="muted grown">{{t "group.created" .When}}</span>
996 <span class="muted grown"><span data-tip="{{t "repo.sortPushedTip"}}">{{.Pushed}}</span> · {{t "group.created" .When}}</span>
995 <details class="rowmenu">
997 <details class="rowmenu">
996 <summary aria-label="{{t "group.menu"}}">⋯</summary>
998 <summary aria-label="{{t "group.menu"}}">⋯</summary>
997 <div class="menu-panel">
999 <div class="menu-panel">
internal/server/templates/layout.html +1 −1
@@ -26,7 +26,7 @@
26 26 <link rel="icon" href="/assets/logo.svg" type="image/svg+xml">
27 27 <link rel="stylesheet" href="/assets/style.css">
28 28 </head>
29 <body data-copied="{{t "action.copied"}}" data-modal-title="{{t "modal.title"}}" data-modal-ok="{{t "modal.ok"}}" data-modal-cancel="{{t "modal.cancel"}}" data-obsolete-tip="{{t "pipe.obsolete.tip"}}" data-waitjob-tip="{{t "pipe.waiting_for_job.tip"}}">
29 <body data-copied="{{t "action.copied"}}" data-modal-title="{{t "modal.title"}}" data-modal-ok="{{t "modal.ok"}}" data-modal-cancel="{{t "modal.cancel"}}" data-obsolete-tip="{{t "pipe.obsolete.tip"}}" data-waitjob-tip="{{t "pipe.waiting_for_job.tip"}}" data-blocked-tip="{{t "pipe.blocked.tip"}}">
30 30 <header class="top">
31 31 <a class="brand" href="/"><img src="/assets/logo.svg" alt=""> BlueGit</a>
32 32 <nav>
@@ -26,7 +26,7 @@
26 <link rel="icon" href="/assets/logo.svg" type="image/svg+xml">
26 <link rel="icon" href="/assets/logo.svg" type="image/svg+xml">
27 <link rel="stylesheet" href="/assets/style.css">
27 <link rel="stylesheet" href="/assets/style.css">
28</head>
28</head>
29<body data-copied="{{t "action.copied"}}" data-modal-title="{{t "modal.title"}}" data-modal-ok="{{t "modal.ok"}}" data-modal-cancel="{{t "modal.cancel"}}" data-obsolete-tip="{{t "pipe.obsolete.tip"}}" data-waitjob-tip="{{t "pipe.waiting_for_job.tip"}}">
29<body data-copied="{{t "action.copied"}}" data-modal-title="{{t "modal.title"}}" data-modal-ok="{{t "modal.ok"}}" data-modal-cancel="{{t "modal.cancel"}}" data-obsolete-tip="{{t "pipe.obsolete.tip"}}" data-waitjob-tip="{{t "pipe.waiting_for_job.tip"}}" data-blocked-tip="{{t "pipe.blocked.tip"}}">
30<header class="top">
30<header class="top">
31 <a class="brand" href="/"><img src="/assets/logo.svg" alt=""> BlueGit</a>
31 <a class="brand" href="/"><img src="/assets/logo.svg" alt=""> BlueGit</a>
32 <nav>
32 <nav>
internal/server/templates/pages.html +4 −4
@@ -92,10 +92,10 @@
92 92 {{if .Heat}}{{template "heatmap" .Heat}}{{end}}
93 93 <div class="grid-2">
94 94 <section class="panel">
95 <h2>{{t "dash.repos"}}</h2>
95 <h2><span data-tip="{{t "repo.sortPushedTip"}}">{{t "dash.repos"}}</span></h2>
96 96 {{if not .Repos}}<p class="muted">{{t "dash.noRepos"}}</p>{{end}}
97 97 <ul class="repolist">
98 {{range .Repos}}<li>{{template "namemark" .}}<div class="grown"><a class="reponame" href="/{{.FullPath}}">{{.FullPath}}</a> <span class="pill">{{visName .Visibility}}</span>{{if .Description}}<div class="muted">{{.Description}}</div>{{end}}</div></li>{{end}}
98 {{range .Repos}}<li>{{template "namemark" .}}<div class="grown"><a class="reponame" href="/{{.FullPath}}" title="{{pushedLabel .}}">{{.FullPath}}</a> <span class="pill">{{visName .Visibility}}</span>{{if .Description}}<div class="muted">{{.Description}}</div>{{end}}</div></li>{{end}}
99 99 </ul>
100 100 </section>
101 101 <section class="panel">
@@ -116,12 +116,12 @@
116 116 {{if .Heat}}{{template "heatmap" .Heat}}{{end}}
117 117 <div class="grid-2">
118 118 <section>
119 <h2>{{t "dash.repos"}}</h2>
119 <h2><span data-tip="{{t "repo.sortPushedTip"}}">{{t "dash.repos"}}</span></h2>
120 120 <ul class="repolist">
121 121 {{range .Repos}}
122 122 <li>
123 123 {{template "namemark" .}}
124 <a class="reponame" href="/{{.FullPath}}">{{.Name}}</a>
124 <a class="reponame" href="/{{.FullPath}}" title="{{pushedLabel .}}">{{.Name}}</a>
125 125 {{template "visicon" .Visibility}}
126 126 <span class="muted grown">{{.Description}}</span>
127 127 </li>
@@ -92,10 +92,10 @@
92{{if .Heat}}{{template "heatmap" .Heat}}{{end}}
92{{if .Heat}}{{template "heatmap" .Heat}}{{end}}
93<div class="grid-2">
93<div class="grid-2">
94 <section class="panel">
94 <section class="panel">
95 <h2>{{t "dash.repos"}}</h2>
95 <h2><span data-tip="{{t "repo.sortPushedTip"}}">{{t "dash.repos"}}</span></h2>
96 {{if not .Repos}}<p class="muted">{{t "dash.noRepos"}}</p>{{end}}
96 {{if not .Repos}}<p class="muted">{{t "dash.noRepos"}}</p>{{end}}
97 <ul class="repolist">
97 <ul class="repolist">
98 {{range .Repos}}<li>{{template "namemark" .}}<div class="grown"><a class="reponame" href="/{{.FullPath}}">{{.FullPath}}</a> <span class="pill">{{visName .Visibility}}</span>{{if .Description}}<div class="muted">{{.Description}}</div>{{end}}</div></li>{{end}}
98 {{range .Repos}}<li>{{template "namemark" .}}<div class="grown"><a class="reponame" href="/{{.FullPath}}" title="{{pushedLabel .}}">{{.FullPath}}</a> <span class="pill">{{visName .Visibility}}</span>{{if .Description}}<div class="muted">{{.Description}}</div>{{end}}</div></li>{{end}}
99 </ul>
99 </ul>
100 </section>
100 </section>
101 <section class="panel">
101 <section class="panel">
@@ -116,12 +116,12 @@
116{{if .Heat}}{{template "heatmap" .Heat}}{{end}}
116{{if .Heat}}{{template "heatmap" .Heat}}{{end}}
117<div class="grid-2">
117<div class="grid-2">
118 <section>
118 <section>
119 <h2>{{t "dash.repos"}}</h2>
119 <h2><span data-tip="{{t "repo.sortPushedTip"}}">{{t "dash.repos"}}</span></h2>
120 <ul class="repolist">
120 <ul class="repolist">
121 {{range .Repos}}
121 {{range .Repos}}
122 <li>
122 <li>
123 {{template "namemark" .}}
123 {{template "namemark" .}}
124 <a class="reponame" href="/{{.FullPath}}">{{.Name}}</a>
124 <a class="reponame" href="/{{.FullPath}}" title="{{pushedLabel .}}">{{.Name}}</a>
125 {{template "visicon" .Visibility}}
125 {{template "visicon" .Visibility}}
126 <span class="muted grown">{{.Description}}</span>
126 <span class="muted grown">{{.Description}}</span>
127 </li>
127 </li>
internal/store/flow.go +38 −2
@@ -1127,7 +1127,8 @@ func (s *Store) RefreshPipelineStatus(ctx context.Context, pipelineID int64) (st
1127 1127 open := false
1128 1128 manual := false
1129 1129 canceled := false
1130 for _, j := range jobs {
1130 blocked := manualBlocked(jobs)
1131 for i, j := range jobs {
1131 1132 switch j.Status {
1132 1133 case "failed":
1133 1134 if !j.AllowFailure {
@@ -1137,8 +1138,16 @@ func (s *Store) RefreshPipelineStatus(ctx context.Context, pipelineID int64) (st
1137 1138 if !j.AllowFailure {
1138 1139 canceled = true
1139 1140 }
1140 case "queued", "running":
1141 case "running":
1141 1142 open = true
1143 case "queued":
1144 // Een job die alleen nog op een handmatige job wacht, telt niet
1145 // als bezig: de pipeline wacht dan op een handmatige actie.
1146 if blocked[i] {
1147 manual = true
1148 } else {
1149 open = true
1150 }
1142 1151 case "manual":
1143 1152 manual = true
1144 1153 }
@@ -1633,3 +1642,30 @@ func (s *Store) SetWebhookActive(ctx context.Context, scopeKind string, scopeID,
1633 1642 _, err := s.db.ExecContext(ctx, `UPDATE webhooks SET active = ? WHERE id = ? AND scope_kind = ? AND scope_id = ?`, boolInt(on), id, scopeKind, scopeID)
1634 1643 return err
1635 1644 }
1645
1646 // manualBlocked markeert queued jobs die (direct of via andere wachtende
1647 // jobs) op een handmatige job wachten die nog niet gestart is. Een
1648 // handmatige job met allow_failure blokkeert niet, net als in ci.Gate.
1649 func manualBlocked(jobs []Job) map[int]bool {
1650 preds := predecessorIndexes(jobs)
1651 blocked := map[int]bool{}
1652 for {
1653 moved := false
1654 for i, j := range jobs {
1655 if blocked[i] || j.Status != "queued" {
1656 continue
1657 }
1658 for _, p := range preds[i] {
1659 pj := jobs[p]
1660 if (pj.Status == "manual" && !pj.AllowFailure) || blocked[p] {
1661 blocked[i] = true
1662 moved = true
1663 break
1664 }
1665 }
1666 }
1667 if !moved {
1668 return blocked
1669 }
1670 }
1671 }
@@ -1127,7 +1127,8 @@ func (s *Store) RefreshPipelineStatus(ctx context.Context, pipelineID int64) (st
1127 open := false
1127 open := false
1128 manual := false
1128 manual := false
1129 canceled := false
1129 canceled := false
1130 for _, j := range jobs {
1130 blocked := manualBlocked(jobs)
1131 for i, j := range jobs {
1131 switch j.Status {
1132 switch j.Status {
1132 case "failed":
1133 case "failed":
1133 if !j.AllowFailure {
1134 if !j.AllowFailure {
@@ -1137,8 +1138,16 @@ func (s *Store) RefreshPipelineStatus(ctx context.Context, pipelineID int64) (st
1137 if !j.AllowFailure {
1138 if !j.AllowFailure {
1138 canceled = true
1139 canceled = true
1139 }
1140 }
1140 case "queued", "running":
1141 case "running":
1141 open = true
1142 open = true
1143 case "queued":
1144 // Een job die alleen nog op een handmatige job wacht, telt niet
1145 // als bezig: de pipeline wacht dan op een handmatige actie.
1146 if blocked[i] {
1147 manual = true
1148 } else {
1149 open = true
1150 }
1142 case "manual":
1151 case "manual":
1143 manual = true
1152 manual = true
1144 }
1153 }
@@ -1633,3 +1642,30 @@ func (s *Store) SetWebhookActive(ctx context.Context, scopeKind string, scopeID,
1633 _, err := s.db.ExecContext(ctx, `UPDATE webhooks SET active = ? WHERE id = ? AND scope_kind = ? AND scope_id = ?`, boolInt(on), id, scopeKind, scopeID)
1642 _, err := s.db.ExecContext(ctx, `UPDATE webhooks SET active = ? WHERE id = ? AND scope_kind = ? AND scope_id = ?`, boolInt(on), id, scopeKind, scopeID)
1634 return err
1643 return err
1635}
1644}
1645
1646// manualBlocked markeert queued jobs die (direct of via andere wachtende
1647// jobs) op een handmatige job wachten die nog niet gestart is. Een
1648// handmatige job met allow_failure blokkeert niet, net als in ci.Gate.
1649func manualBlocked(jobs []Job) map[int]bool {
1650 preds := predecessorIndexes(jobs)
1651 blocked := map[int]bool{}
1652 for {
1653 moved := false
1654 for i, j := range jobs {
1655 if blocked[i] || j.Status != "queued" {
1656 continue
1657 }
1658 for _, p := range preds[i] {
1659 pj := jobs[p]
1660 if (pj.Status == "manual" && !pj.AllowFailure) || blocked[p] {
1661 blocked[i] = true
1662 moved = true
1663 break
1664 }
1665 }
1666 }
1667 if !moved {
1668 return blocked
1669 }
1670 }
1671}
internal/store/manual_blocked_test.go added +72 −0
@@ -0,0 +1,72 @@
1 package store
2
3 import (
4 "context"
5 "testing"
6 )
7
8 func TestPipelineWaitingOnManualIsNotRunning(t *testing.T) {
9 s := openTest(t)
10 ctx := context.Background()
11 tim, err := s.UpsertUser(ctx, 1, "tim", "", false)
12 if err != nil {
13 t.Fatal(err)
14 }
15 repo, err := s.CreateRepo(ctx, "user", tim.ID, "pp", "", "master", "private")
16 if err != nil {
17 t.Fatal(err)
18 }
19 id, err := s.CreatePipeline(ctx, repo.ID, "abc", "refs/heads/master", "push", "tim", "rel", []NewJob{
20 {Name: "build", Stage: "build", Script: "true"},
21 {Name: "release", Stage: "release", Script: "true", When: "manual"},
22 {Name: "publish", Stage: "publish", Script: "true", Needs: []string{"release"}, NeedsSet: true},
23 {Name: "after", Stage: "post", Script: "true"},
24 })
25 if err != nil {
26 t.Fatal(err)
27 }
28 jobs, _ := s.JobsByPipeline(ctx, id)
29 byName := map[string]Job{}
30 for _, j := range jobs {
31 byName[j.Name] = j
32 }
33 if byName["release"].Status != "manual" || byName["publish"].Status != "queued" {
34 t.Fatalf("opzet: %s %s", byName["release"].Status, byName["publish"].Status)
35 }
36 // build loopt nog: de pipeline is bezig.
37 if st, _ := s.RefreshPipelineStatus(ctx, id); st != "running" {
38 t.Fatalf("met open build: %s", st)
39 }
40 if err := s.FinishJob(ctx, byName["build"].ID, "success", ""); err != nil {
41 t.Fatal(err)
42 }
43 st, err := s.RefreshPipelineStatus(ctx, id)
44 if err != nil || st != "manual" {
45 t.Fatalf("alleen handmatig over hoort manual te zijn: %s %v", st, err)
46 }
47 p, _ := s.PipelineByID(ctx, repo.ID, id)
48 if p.Status != "manual" {
49 t.Fatalf("opgeslagen status %s", p.Status)
50 }
51 // Na het starten van de handmatige job is hij weer bezig.
52 if ok, _ := s.QueueJob(ctx, byName["release"].ID); !ok {
53 t.Fatal("queue")
54 }
55 if st, _ := s.RefreshPipelineStatus(ctx, id); st != "running" {
56 t.Fatalf("na play: %s", st)
57 }
58 }
59
60 func TestManualAllowFailureDoesNotBlock(t *testing.T) {
61 jobs := []Job{
62 {Name: "opt", Stage: "a", Status: "manual", AllowFailure: true},
63 {Name: "next", Stage: "b", Status: "queued"},
64 }
65 if manualBlocked(jobs)[1] {
66 t.Fatal("allow_failure-manual blokkeert niet")
67 }
68 jobs[0].AllowFailure = false
69 if !manualBlocked(jobs)[1] {
70 t.Fatal("manual blokkeert")
71 }
72 }
@@ -0,0 +1,72 @@
1package store
2
3import (
4 "context"
5 "testing"
6)
7
8func TestPipelineWaitingOnManualIsNotRunning(t *testing.T) {
9 s := openTest(t)
10 ctx := context.Background()
11 tim, err := s.UpsertUser(ctx, 1, "tim", "", false)
12 if err != nil {
13 t.Fatal(err)
14 }
15 repo, err := s.CreateRepo(ctx, "user", tim.ID, "pp", "", "master", "private")
16 if err != nil {
17 t.Fatal(err)
18 }
19 id, err := s.CreatePipeline(ctx, repo.ID, "abc", "refs/heads/master", "push", "tim", "rel", []NewJob{
20 {Name: "build", Stage: "build", Script: "true"},
21 {Name: "release", Stage: "release", Script: "true", When: "manual"},
22 {Name: "publish", Stage: "publish", Script: "true", Needs: []string{"release"}, NeedsSet: true},
23 {Name: "after", Stage: "post", Script: "true"},
24 })
25 if err != nil {
26 t.Fatal(err)
27 }
28 jobs, _ := s.JobsByPipeline(ctx, id)
29 byName := map[string]Job{}
30 for _, j := range jobs {
31 byName[j.Name] = j
32 }
33 if byName["release"].Status != "manual" || byName["publish"].Status != "queued" {
34 t.Fatalf("opzet: %s %s", byName["release"].Status, byName["publish"].Status)
35 }
36 // build loopt nog: de pipeline is bezig.
37 if st, _ := s.RefreshPipelineStatus(ctx, id); st != "running" {
38 t.Fatalf("met open build: %s", st)
39 }
40 if err := s.FinishJob(ctx, byName["build"].ID, "success", ""); err != nil {
41 t.Fatal(err)
42 }
43 st, err := s.RefreshPipelineStatus(ctx, id)
44 if err != nil || st != "manual" {
45 t.Fatalf("alleen handmatig over hoort manual te zijn: %s %v", st, err)
46 }
47 p, _ := s.PipelineByID(ctx, repo.ID, id)
48 if p.Status != "manual" {
49 t.Fatalf("opgeslagen status %s", p.Status)
50 }
51 // Na het starten van de handmatige job is hij weer bezig.
52 if ok, _ := s.QueueJob(ctx, byName["release"].ID); !ok {
53 t.Fatal("queue")
54 }
55 if st, _ := s.RefreshPipelineStatus(ctx, id); st != "running" {
56 t.Fatalf("na play: %s", st)
57 }
58}
59
60func TestManualAllowFailureDoesNotBlock(t *testing.T) {
61 jobs := []Job{
62 {Name: "opt", Stage: "a", Status: "manual", AllowFailure: true},
63 {Name: "next", Stage: "b", Status: "queued"},
64 }
65 if manualBlocked(jobs)[1] {
66 t.Fatal("allow_failure-manual blokkeert niet")
67 }
68 jobs[0].AllowFailure = false
69 if !manualBlocked(jobs)[1] {
70 t.Fatal("manual blokkeert")
71 }
72}
internal/store/pushsort_test.go added +69 −0
@@ -0,0 +1,69 @@
1 package store
2
3 import (
4 "context"
5 "testing"
6 "time"
7
8 "gitlab.com/Timfa/bluegit/internal/access"
9 )
10
11 func TestReposSortedByLastPush(t *testing.T) {
12 s := openStore(t)
13 ctx := context.Background()
14 tim, err := s.UpsertUser(ctx, 1, "tim", "", false)
15 if err != nil {
16 t.Fatal(err)
17 }
18 mk := func(kind string, owner int64, name string) Repo {
19 r, err := s.CreateRepo(ctx, kind, owner, name, "", "master", "public")
20 if err != nil {
21 t.Fatal(err)
22 }
23 return r
24 }
25 a, b, c, d := mk("user", tim.ID, "alpha"), mk("user", tim.ID, "beta"), mk("user", tim.ID, "Gamma"), mk("user", tim.ID, "delta")
26 base := time.Date(2026, 10, 1, 12, 0, 0, 0, time.UTC)
27 _ = s.TouchPushed(ctx, a.ID, base)
28 _ = s.TouchPushed(ctx, c.ID, base.Add(2*time.Hour))
29 _ = s.TouchPushed(ctx, d.ID, base.Add(2*time.Hour))
30 // Een oudere tijd overschrijft een nieuwere niet.
31 _ = s.TouchPushed(ctx, c.ID, base.Add(-time.Hour))
32 _ = b
33 list, err := s.ReposByOwner(ctx, tim.ID)
34 if err != nil {
35 t.Fatal(err)
36 }
37 var got []string
38 for _, r := range list {
39 got = append(got, r.Name)
40 }
41 want := []string{"delta", "Gamma", "alpha", "beta"}
42 for i := range want {
43 if got[i] != want[i] {
44 t.Fatalf("volgorde %v, wil %v", got, want)
45 }
46 }
47 if !list[0].PushedAt.Equal(base.Add(2*time.Hour)) || !list[3].PushedAt.IsZero() {
48 t.Fatalf("pushed_at: %v %v", list[0].PushedAt, list[3].PushedAt)
49 }
50 SortReposByPush(list[:0])
51 rev := []Repo{list[3], list[2], list[1], list[0]}
52 SortReposByPush(rev)
53 for i := range want {
54 if rev[i].Name != want[i] {
55 t.Fatalf("SortReposByPush %v", rev)
56 }
57 }
58
59 g, err := s.CreateGroup(ctx, tim.ID, "Crew", "crew", "", access.RoleDeveloper)
60 if err != nil {
61 t.Fatal(err)
62 }
63 x, y := mk("group", g.ID, "x"), mk("group", g.ID, "y")
64 _ = s.TouchPushed(ctx, y.ID, base)
65 gl, _ := s.ReposByGroup(ctx, g.ID)
66 if len(gl) != 2 || gl[0].ID != y.ID || gl[1].ID != x.ID {
67 t.Fatalf("groep %+v", gl)
68 }
69 }
@@ -0,0 +1,69 @@
1package store
2
3import (
4 "context"
5 "testing"
6 "time"
7
8 "gitlab.com/Timfa/bluegit/internal/access"
9)
10
11func TestReposSortedByLastPush(t *testing.T) {
12 s := openStore(t)
13 ctx := context.Background()
14 tim, err := s.UpsertUser(ctx, 1, "tim", "", false)
15 if err != nil {
16 t.Fatal(err)
17 }
18 mk := func(kind string, owner int64, name string) Repo {
19 r, err := s.CreateRepo(ctx, kind, owner, name, "", "master", "public")
20 if err != nil {
21 t.Fatal(err)
22 }
23 return r
24 }
25 a, b, c, d := mk("user", tim.ID, "alpha"), mk("user", tim.ID, "beta"), mk("user", tim.ID, "Gamma"), mk("user", tim.ID, "delta")
26 base := time.Date(2026, 10, 1, 12, 0, 0, 0, time.UTC)
27 _ = s.TouchPushed(ctx, a.ID, base)
28 _ = s.TouchPushed(ctx, c.ID, base.Add(2*time.Hour))
29 _ = s.TouchPushed(ctx, d.ID, base.Add(2*time.Hour))
30 // Een oudere tijd overschrijft een nieuwere niet.
31 _ = s.TouchPushed(ctx, c.ID, base.Add(-time.Hour))
32 _ = b
33 list, err := s.ReposByOwner(ctx, tim.ID)
34 if err != nil {
35 t.Fatal(err)
36 }
37 var got []string
38 for _, r := range list {
39 got = append(got, r.Name)
40 }
41 want := []string{"delta", "Gamma", "alpha", "beta"}
42 for i := range want {
43 if got[i] != want[i] {
44 t.Fatalf("volgorde %v, wil %v", got, want)
45 }
46 }
47 if !list[0].PushedAt.Equal(base.Add(2*time.Hour)) || !list[3].PushedAt.IsZero() {
48 t.Fatalf("pushed_at: %v %v", list[0].PushedAt, list[3].PushedAt)
49 }
50 SortReposByPush(list[:0])
51 rev := []Repo{list[3], list[2], list[1], list[0]}
52 SortReposByPush(rev)
53 for i := range want {
54 if rev[i].Name != want[i] {
55 t.Fatalf("SortReposByPush %v", rev)
56 }
57 }
58
59 g, err := s.CreateGroup(ctx, tim.ID, "Crew", "crew", "", access.RoleDeveloper)
60 if err != nil {
61 t.Fatal(err)
62 }
63 x, y := mk("group", g.ID, "x"), mk("group", g.ID, "y")
64 _ = s.TouchPushed(ctx, y.ID, base)
65 gl, _ := s.ReposByGroup(ctx, g.ID)
66 if len(gl) != 2 || gl[0].ID != y.ID || gl[1].ID != x.ID {
67 t.Fatalf("groep %+v", gl)
68 }
69}
internal/store/repos.go +48 −8
@@ -4,6 +4,7 @@ import (
4 4 "context"
5 5 "database/sql"
6 6 "errors"
7 "sort"
7 8 "strings"
8 9 "time"
9 10
@@ -52,6 +53,8 @@ type Repo struct {
52 53 // ReleaseVisibility is "inherit" (zelfde als de repo), "private" of
53 54 // "public". Zie ReleasesPublic.
54 55 ReleaseVisibility string
56 // PushedAt is het moment van de laatste push. Nul: nog nooit gepusht.
57 PushedAt time.Time
55 58 }
56 59
57 60 // ReleasesPublic meldt of releases (pagina, notities, assets) voor
@@ -319,14 +322,14 @@ func (s *Store) RepoByPath(ctx context.Context, owner, name string) (Repo, error
319 322 const repoSelect = `
320 323 SELECT r.id, r.owner_kind, r.owner_id,
321 324 CASE r.owner_kind WHEN 'user' THEN (SELECT username FROM users WHERE id = r.owner_id) ELSE (SELECT path FROM groups WHERE id = r.owner_id) END,
322 r.name, r.description, r.default_branch, r.visibility, r.created_at, r.logo_mime, r.release_visibility
325 r.name, r.description, r.default_branch, r.visibility, r.created_at, r.logo_mime, r.release_visibility, r.pushed_at
323 326 FROM repos r`
324 327
325 328 func scanRepo(row *sql.Row) (Repo, error) {
326 329 var r Repo
327 var created string
330 var created, pushed string
328 331 var owner sql.NullString
329 if err := row.Scan(&r.ID, &r.OwnerKind, &r.OwnerID, &owner, &r.Name, &r.Description, &r.DefaultBranch, &r.Visibility, &created, &r.LogoMIME, &r.ReleaseVisibility); err != nil {
332 if err := row.Scan(&r.ID, &r.OwnerKind, &r.OwnerID, &owner, &r.Name, &r.Description, &r.DefaultBranch, &r.Visibility, &created, &r.LogoMIME, &r.ReleaseVisibility, &pushed); err != nil {
330 333 if errors.Is(err, sql.ErrNoRows) {
331 334 return Repo{}, errNotFound
332 335 }
@@ -334,6 +337,9 @@ func scanRepo(row *sql.Row) (Repo, error) {
334 337 }
335 338 r.OwnerPath = owner.String
336 339 r.CreatedAt = parseTime(created)
340 if pushed != "" {
341 r.PushedAt = parseTime(pushed)
342 }
337 343 return r, nil
338 344 }
339 345
@@ -383,9 +389,12 @@ func (s *Store) ListRepoIDs(ctx context.Context, userID int64) ([]int64, error)
383 389 return ids, rows.Err()
384 390 }
385 391
386 // ReposByOwner geeft de repositories van een gebruiker, op naam.
392 // pushOrder: laatste push bovenaan, repos zonder push onderaan, daarna op naam.
393 const pushOrder = `(r.pushed_at = ''), r.pushed_at DESC, r.name COLLATE NOCASE, r.id`
394
395 // ReposByOwner geeft de repositories van een gebruiker, laatste push eerst.
387 396 func (s *Store) ReposByOwner(ctx context.Context, userID int64) ([]Repo, error) {
388 rows, err := s.db.QueryContext(ctx, repoSelect+` WHERE r.owner_kind = 'user' AND r.owner_id = ? ORDER BY r.name`, userID)
397 rows, err := s.db.QueryContext(ctx, repoSelect+` WHERE r.owner_kind = 'user' AND r.owner_id = ? ORDER BY `+pushOrder, userID)
389 398 if err != nil {
390 399 return nil, err
391 400 }
@@ -406,7 +415,7 @@ func (s *Store) CountRepos(ctx context.Context, ownerKind string, ownerID int64,
406 415
407 416 // ReposByGroup geeft de repositories van een groep.
408 417 func (s *Store) ReposByGroup(ctx context.Context, groupID int64) ([]Repo, error) {
409 rows, err := s.db.QueryContext(ctx, repoSelect+` WHERE r.owner_kind = 'group' AND r.owner_id = ? ORDER BY r.name`, groupID)
418 rows, err := s.db.QueryContext(ctx, repoSelect+` WHERE r.owner_kind = 'group' AND r.owner_id = ? ORDER BY `+pushOrder, groupID)
410 419 if err != nil {
411 420 return nil, err
412 421 }
@@ -431,13 +440,19 @@ func scanRepos(rows *sql.Rows) ([]Repo, error) {
431 440 var out []Repo
432 441 for rows.Next() {
433 442 var r Repo
434 var created string
443 var created, pushed string
435 444 var owner sql.NullString
436 if err := rows.Scan(&r.ID, &r.OwnerKind, &r.OwnerID, &owner, &r.Name, &r.Description, &r.DefaultBranch, &r.Visibility, &created, &r.LogoMIME, &r.ReleaseVisibility); err != nil {
445 if err := rows.Scan(&r.ID, &r.OwnerKind, &r.OwnerID, &owner, &r.Name, &r.Description, &r.DefaultBranch, &r.Visibility, &created, &r.LogoMIME, &r.ReleaseVisibility, &pushed); err != nil {
437 446 return nil, err
438 447 }
439 448 r.OwnerPath = owner.String
440 449 r.CreatedAt = parseTime(created)
450 if pushed != "" {
451 r.PushedAt = parseTime(pushed)
452 }
453 if pushed != "" {
454 r.PushedAt = parseTime(pushed)
455 }
441 456 out = append(out, r)
442 457 }
443 458 return out, rows.Err()
@@ -868,3 +883,28 @@ func (s *Store) SecretValues(ctx context.Context, scopeKind string, scopeID int6
868 883 }
869 884 return out, rows.Err()
870 885 }
886
887 // TouchPushed zet het moment van de laatste push.
888 func (s *Store) TouchPushed(ctx context.Context, repoID int64, at time.Time) error {
889 _, err := s.db.ExecContext(ctx, `UPDATE repos SET pushed_at = ? WHERE id = ? AND (pushed_at = '' OR pushed_at < ?)`,
890 at.UTC().Format(time.RFC3339), repoID, at.UTC().Format(time.RFC3339))
891 return err
892 }
893
894 // SortReposByPush sorteert zoals pushOrder: laatste push eerst, zonder push
895 // onderaan, daarna op naam.
896 func SortReposByPush(list []Repo) {
897 sort.SliceStable(list, func(i, j int) bool {
898 a, b := list[i], list[j]
899 if a.PushedAt.IsZero() != b.PushedAt.IsZero() {
900 return !a.PushedAt.IsZero()
901 }
902 if !a.PushedAt.Equal(b.PushedAt) {
903 return a.PushedAt.After(b.PushedAt)
904 }
905 if x, y := strings.ToLower(a.FullPath()), strings.ToLower(b.FullPath()); x != y {
906 return x < y
907 }
908 return a.ID < b.ID
909 })
910 }
@@ -4,6 +4,7 @@ import (
4 "context"
4 "context"
5 "database/sql"
5 "database/sql"
6 "errors"
6 "errors"
7 "sort"
7 "strings"
8 "strings"
8 "time"
9 "time"
9
10
@@ -52,6 +53,8 @@ type Repo struct {
52 // ReleaseVisibility is "inherit" (zelfde als de repo), "private" of
53 // ReleaseVisibility is "inherit" (zelfde als de repo), "private" of
53 // "public". Zie ReleasesPublic.
54 // "public". Zie ReleasesPublic.
54 ReleaseVisibility string
55 ReleaseVisibility string
56 // PushedAt is het moment van de laatste push. Nul: nog nooit gepusht.
57 PushedAt time.Time
55}
58}
56
59
57// ReleasesPublic meldt of releases (pagina, notities, assets) voor
60// ReleasesPublic meldt of releases (pagina, notities, assets) voor
@@ -319,14 +322,14 @@ func (s *Store) RepoByPath(ctx context.Context, owner, name string) (Repo, error
319const repoSelect = `
322const repoSelect = `
320SELECT r.id, r.owner_kind, r.owner_id,
323SELECT r.id, r.owner_kind, r.owner_id,
321 CASE r.owner_kind WHEN 'user' THEN (SELECT username FROM users WHERE id = r.owner_id) ELSE (SELECT path FROM groups WHERE id = r.owner_id) END,
324 CASE r.owner_kind WHEN 'user' THEN (SELECT username FROM users WHERE id = r.owner_id) ELSE (SELECT path FROM groups WHERE id = r.owner_id) END,
322 r.name, r.description, r.default_branch, r.visibility, r.created_at, r.logo_mime, r.release_visibility
325 r.name, r.description, r.default_branch, r.visibility, r.created_at, r.logo_mime, r.release_visibility, r.pushed_at
323FROM repos r`
326FROM repos r`
324
327
325func scanRepo(row *sql.Row) (Repo, error) {
328func scanRepo(row *sql.Row) (Repo, error) {
326 var r Repo
329 var r Repo
327 var created string
330 var created, pushed string
328 var owner sql.NullString
331 var owner sql.NullString
329 if err := row.Scan(&r.ID, &r.OwnerKind, &r.OwnerID, &owner, &r.Name, &r.Description, &r.DefaultBranch, &r.Visibility, &created, &r.LogoMIME, &r.ReleaseVisibility); err != nil {
332 if err := row.Scan(&r.ID, &r.OwnerKind, &r.OwnerID, &owner, &r.Name, &r.Description, &r.DefaultBranch, &r.Visibility, &created, &r.LogoMIME, &r.ReleaseVisibility, &pushed); err != nil {
330 if errors.Is(err, sql.ErrNoRows) {
333 if errors.Is(err, sql.ErrNoRows) {
331 return Repo{}, errNotFound
334 return Repo{}, errNotFound
332 }
335 }
@@ -334,6 +337,9 @@ func scanRepo(row *sql.Row) (Repo, error) {
334 }
337 }
335 r.OwnerPath = owner.String
338 r.OwnerPath = owner.String
336 r.CreatedAt = parseTime(created)
339 r.CreatedAt = parseTime(created)
340 if pushed != "" {
341 r.PushedAt = parseTime(pushed)
342 }
337 return r, nil
343 return r, nil
338}
344}
339
345
@@ -383,9 +389,12 @@ func (s *Store) ListRepoIDs(ctx context.Context, userID int64) ([]int64, error)
383 return ids, rows.Err()
389 return ids, rows.Err()
384}
390}
385
391
386// ReposByOwner geeft de repositories van een gebruiker, op naam.
392// pushOrder: laatste push bovenaan, repos zonder push onderaan, daarna op naam.
393const pushOrder = `(r.pushed_at = ''), r.pushed_at DESC, r.name COLLATE NOCASE, r.id`
394
395// ReposByOwner geeft de repositories van een gebruiker, laatste push eerst.
387func (s *Store) ReposByOwner(ctx context.Context, userID int64) ([]Repo, error) {
396func (s *Store) ReposByOwner(ctx context.Context, userID int64) ([]Repo, error) {
388 rows, err := s.db.QueryContext(ctx, repoSelect+` WHERE r.owner_kind = 'user' AND r.owner_id = ? ORDER BY r.name`, userID)
397 rows, err := s.db.QueryContext(ctx, repoSelect+` WHERE r.owner_kind = 'user' AND r.owner_id = ? ORDER BY `+pushOrder, userID)
389 if err != nil {
398 if err != nil {
390 return nil, err
399 return nil, err
391 }
400 }
@@ -406,7 +415,7 @@ func (s *Store) CountRepos(ctx context.Context, ownerKind string, ownerID int64,
406
415
407// ReposByGroup geeft de repositories van een groep.
416// ReposByGroup geeft de repositories van een groep.
408func (s *Store) ReposByGroup(ctx context.Context, groupID int64) ([]Repo, error) {
417func (s *Store) ReposByGroup(ctx context.Context, groupID int64) ([]Repo, error) {
409 rows, err := s.db.QueryContext(ctx, repoSelect+` WHERE r.owner_kind = 'group' AND r.owner_id = ? ORDER BY r.name`, groupID)
418 rows, err := s.db.QueryContext(ctx, repoSelect+` WHERE r.owner_kind = 'group' AND r.owner_id = ? ORDER BY `+pushOrder, groupID)
410 if err != nil {
419 if err != nil {
411 return nil, err
420 return nil, err
412 }
421 }
@@ -431,13 +440,19 @@ func scanRepos(rows *sql.Rows) ([]Repo, error) {
431 var out []Repo
440 var out []Repo
432 for rows.Next() {
441 for rows.Next() {
433 var r Repo
442 var r Repo
434 var created string
443 var created, pushed string
435 var owner sql.NullString
444 var owner sql.NullString
436 if err := rows.Scan(&r.ID, &r.OwnerKind, &r.OwnerID, &owner, &r.Name, &r.Description, &r.DefaultBranch, &r.Visibility, &created, &r.LogoMIME, &r.ReleaseVisibility); err != nil {
445 if err := rows.Scan(&r.ID, &r.OwnerKind, &r.OwnerID, &owner, &r.Name, &r.Description, &r.DefaultBranch, &r.Visibility, &created, &r.LogoMIME, &r.ReleaseVisibility, &pushed); err != nil {
437 return nil, err
446 return nil, err
438 }
447 }
439 r.OwnerPath = owner.String
448 r.OwnerPath = owner.String
440 r.CreatedAt = parseTime(created)
449 r.CreatedAt = parseTime(created)
450 if pushed != "" {
451 r.PushedAt = parseTime(pushed)
452 }
453 if pushed != "" {
454 r.PushedAt = parseTime(pushed)
455 }
441 out = append(out, r)
456 out = append(out, r)
442 }
457 }
443 return out, rows.Err()
458 return out, rows.Err()
@@ -868,3 +883,28 @@ func (s *Store) SecretValues(ctx context.Context, scopeKind string, scopeID int6
868 }
883 }
869 return out, rows.Err()
884 return out, rows.Err()
870}
885}
886
887// TouchPushed zet het moment van de laatste push.
888func (s *Store) TouchPushed(ctx context.Context, repoID int64, at time.Time) error {
889 _, err := s.db.ExecContext(ctx, `UPDATE repos SET pushed_at = ? WHERE id = ? AND (pushed_at = '' OR pushed_at < ?)`,
890 at.UTC().Format(time.RFC3339), repoID, at.UTC().Format(time.RFC3339))
891 return err
892}
893
894// SortReposByPush sorteert zoals pushOrder: laatste push eerst, zonder push
895// onderaan, daarna op naam.
896func SortReposByPush(list []Repo) {
897 sort.SliceStable(list, func(i, j int) bool {
898 a, b := list[i], list[j]
899 if a.PushedAt.IsZero() != b.PushedAt.IsZero() {
900 return !a.PushedAt.IsZero()
901 }
902 if !a.PushedAt.Equal(b.PushedAt) {
903 return a.PushedAt.After(b.PushedAt)
904 }
905 if x, y := strings.ToLower(a.FullPath()), strings.ToLower(b.FullPath()); x != y {
906 return x < y
907 }
908 return a.ID < b.ID
909 })
910}
internal/store/store.go +1 −0
@@ -63,6 +63,7 @@ func (s *Store) migrate() error {
63 63 `ALTER TABLE groups ADD COLUMN logo_mime TEXT NOT NULL DEFAULT ''`,
64 64 `ALTER TABLE repos ADD COLUMN logo_mime TEXT NOT NULL DEFAULT ''`,
65 65 `ALTER TABLE repos ADD COLUMN release_visibility TEXT NOT NULL DEFAULT 'inherit'`,
66 `ALTER TABLE repos ADD COLUMN pushed_at TEXT NOT NULL DEFAULT ''`,
66 67 `ALTER TABLE webhooks ADD COLUMN method TEXT NOT NULL DEFAULT 'POST'`,
67 68 `ALTER TABLE notes ADD COLUMN file_path TEXT NOT NULL DEFAULT ''`,
68 69 `ALTER TABLE notes ADD COLUMN line_start INTEGER NOT NULL DEFAULT 0`,
@@ -63,6 +63,7 @@ func (s *Store) migrate() error {
63 `ALTER TABLE groups ADD COLUMN logo_mime TEXT NOT NULL DEFAULT ''`,
63 `ALTER TABLE groups ADD COLUMN logo_mime TEXT NOT NULL DEFAULT ''`,
64 `ALTER TABLE repos ADD COLUMN logo_mime TEXT NOT NULL DEFAULT ''`,
64 `ALTER TABLE repos ADD COLUMN logo_mime TEXT NOT NULL DEFAULT ''`,
65 `ALTER TABLE repos ADD COLUMN release_visibility TEXT NOT NULL DEFAULT 'inherit'`,
65 `ALTER TABLE repos ADD COLUMN release_visibility TEXT NOT NULL DEFAULT 'inherit'`,
66 `ALTER TABLE repos ADD COLUMN pushed_at TEXT NOT NULL DEFAULT ''`,
66 `ALTER TABLE webhooks ADD COLUMN method TEXT NOT NULL DEFAULT 'POST'`,
67 `ALTER TABLE webhooks ADD COLUMN method TEXT NOT NULL DEFAULT 'POST'`,
67 `ALTER TABLE notes ADD COLUMN file_path TEXT NOT NULL DEFAULT ''`,
68 `ALTER TABLE notes ADD COLUMN file_path TEXT NOT NULL DEFAULT ''`,
68 `ALTER TABLE notes ADD COLUMN line_start INTEGER NOT NULL DEFAULT 0`,
69 `ALTER TABLE notes ADD COLUMN line_start INTEGER NOT NULL DEFAULT 0`,