BlueGit

timfa bluegit

feat: geef de branches- en tagspagina de GitLab-opbouw

Tabs, filter en groepen voor branches, dezelfde kaarten voor tags,
en een zip- of tar.gz-archief per branch.

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

timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa

Authored 2026-10-23 · 3 weeks ago

Hash
6e85d75045527b79eb26e0e8538df98adb41ff0b
Parent
2cf7d2a1
Pipeline
Passed
14 files changed +551 −130
internal/gitrepo/repo.go +10 −2
@@ -529,17 +529,25 @@ func Archive(ctx context.Context, w io.Writer, gitBin, dir, prefix, name, format
529 529 if !HasTag(ctx, gitBin, dir, name) {
530 530 return i18n.E("err.tagMissing", name)
531 531 }
532 kind := format
532 return ArchiveAt(ctx, w, gitBin, dir, prefix, name, format)
533 }
534
535 // ArchiveAt schrijft een zip of tar.gz van een bestaande revisie.
536 // rev is een tagnaam of refs/heads/….
537 func ArchiveAt(ctx context.Context, w io.Writer, gitBin, dir, prefix, rev, format string) error {
533 538 if format != "zip" && format != "tar.gz" {
534 539 return i18n.E("err.notFound")
535 540 }
541 if rev == "" || strings.HasPrefix(rev, "-") || strings.Contains(rev, "..") || strings.ContainsAny(rev, " \t\r\n\\") {
542 return i18n.E("err.notFound")
543 }
536 544 if gitBin == "" {
537 545 gitBin = "git"
538 546 }
539 547 if prefix != "" && !strings.HasSuffix(prefix, "/") {
540 548 prefix += "/"
541 549 }
542 cmd := exec.CommandContext(ctx, gitBin, "-C", dir, "archive", "--format="+kind, "--prefix="+prefix, name)
550 cmd := exec.CommandContext(ctx, gitBin, "-C", dir, "archive", "--format="+format, "--prefix="+prefix, rev)
543 551 cmd.Stdout = w
544 552 var stderr bytes.Buffer
545 553 cmd.Stderr = &stderr
@@ -529,17 +529,25 @@ func Archive(ctx context.Context, w io.Writer, gitBin, dir, prefix, name, format
529 if !HasTag(ctx, gitBin, dir, name) {
529 if !HasTag(ctx, gitBin, dir, name) {
530 return i18n.E("err.tagMissing", name)
530 return i18n.E("err.tagMissing", name)
531 }
531 }
532 kind := format
532 return ArchiveAt(ctx, w, gitBin, dir, prefix, name, format)
533}
534
535// ArchiveAt schrijft een zip of tar.gz van een bestaande revisie.
536// rev is een tagnaam of refs/heads/….
537func ArchiveAt(ctx context.Context, w io.Writer, gitBin, dir, prefix, rev, format string) error {
533 if format != "zip" && format != "tar.gz" {
538 if format != "zip" && format != "tar.gz" {
534 return i18n.E("err.notFound")
539 return i18n.E("err.notFound")
535 }
540 }
541 if rev == "" || strings.HasPrefix(rev, "-") || strings.Contains(rev, "..") || strings.ContainsAny(rev, " \t\r\n\\") {
542 return i18n.E("err.notFound")
543 }
536 if gitBin == "" {
544 if gitBin == "" {
537 gitBin = "git"
545 gitBin = "git"
538 }
546 }
539 if prefix != "" && !strings.HasSuffix(prefix, "/") {
547 if prefix != "" && !strings.HasSuffix(prefix, "/") {
540 prefix += "/"
548 prefix += "/"
541 }
549 }
542 cmd := exec.CommandContext(ctx, gitBin, "-C", dir, "archive", "--format="+kind, "--prefix="+prefix, name)
550 cmd := exec.CommandContext(ctx, gitBin, "-C", dir, "archive", "--format="+format, "--prefix="+prefix, rev)
543 cmd.Stdout = w
551 cmd.Stdout = w
544 var stderr bytes.Buffer
552 var stderr bytes.Buffer
545 cmd.Stderr = &stderr
553 cmd.Stderr = &stderr
internal/i18n/catalog.go +1 −1
@@ -145,7 +145,7 @@ var en = map[string]string{
145 145 "repo.binary": "Binary file.",
146 146 "repo.noTags": "No tags yet.",
147 147 "tag.search": "Find a tag",
148 "tag.create": "Create tag",
148 "tag.create": "New tag",
149 149 "tag.name": "Name",
150 150 "tag.target": "Branch or commit",
151 151 "tag.message": "Message",
@@ -145,7 +145,7 @@ var en = map[string]string{
145 "repo.binary": "Binary file.",
145 "repo.binary": "Binary file.",
146 "repo.noTags": "No tags yet.",
146 "repo.noTags": "No tags yet.",
147 "tag.search": "Find a tag",
147 "tag.search": "Find a tag",
148 "tag.create": "Create tag",
148 "tag.create": "New tag",
149 "tag.name": "Name",
149 "tag.name": "Name",
150 "tag.target": "Branch or commit",
150 "tag.target": "Branch or commit",
151 "tag.message": "Message",
151 "tag.message": "Message",
internal/i18n/catalog_branch.go +44 −0
@@ -25,6 +25,17 @@ var branchEN = map[string]string{
25 25 "branch.behind": "%d behind",
26 26 "branch.even": "Up to date",
27 27 "branch.actions": "Actions",
28 "branch.tab.overview": "Overview",
29 "branch.tab.active": "Active",
30 "branch.tab.stale": "Stale",
31 "branch.tab.all": "All",
32 "branch.group.active": "Active branches",
33 "branch.group.stale": "Stale branches",
34 "branch.filter": "Filter by branch name",
35 "branch.download": "Download",
36 "branch.makeMR": "Create MR",
37 "branch.none.active": "No active branches.",
38 "branch.none.stale": "No stale branches.",
28 39 "mr.draft": "Draft",
29 40 "mr.markDraft": "Mark as draft",
30 41 "mr.block.draft": "This merge request is a draft.",
@@ -94,6 +105,17 @@ var branchNL = map[string]string{
94 105 "branch.behind": "%d achter",
95 106 "branch.even": "Bijgewerkt",
96 107 "branch.actions": "Acties",
108 "branch.tab.overview": "Overzicht",
109 "branch.tab.active": "Actief",
110 "branch.tab.stale": "Inactief",
111 "branch.tab.all": "Alles",
112 "branch.group.active": "Actieve branches",
113 "branch.group.stale": "Inactieve branches",
114 "branch.filter": "Filter op branchnaam",
115 "branch.download": "Downloaden",
116 "branch.makeMR": "MR maken",
117 "branch.none.active": "Geen actieve branches.",
118 "branch.none.stale": "Geen inactieve branches.",
97 119 "mr.draft": "Concept",
98 120 "mr.markDraft": "Als concept markeren",
99 121 "mr.block.draft": "Deze merge request is een concept.",
@@ -163,6 +185,17 @@ var branchDE = map[string]string{
163 185 "branch.behind": "%d zurück",
164 186 "branch.even": "Aktuell",
165 187 "branch.actions": "Aktionen",
188 "branch.tab.overview": "Übersicht",
189 "branch.tab.active": "Aktiv",
190 "branch.tab.stale": "Veraltet",
191 "branch.tab.all": "Alle",
192 "branch.group.active": "Aktive Branches",
193 "branch.group.stale": "Veraltete Branches",
194 "branch.filter": "Nach Branchname filtern",
195 "branch.download": "Herunterladen",
196 "branch.makeMR": "MR erstellen",
197 "branch.none.active": "Keine aktiven Branches.",
198 "branch.none.stale": "Keine veralteten Branches.",
166 199 "mr.draft": "Entwurf",
167 200 "mr.markDraft": "Als Entwurf markieren",
168 201 "mr.block.draft": "Dieser Merge Request ist ein Entwurf.",
@@ -232,6 +265,17 @@ var branchFR = map[string]string{
232 265 "branch.behind": "%d en retard",
233 266 "branch.even": "À jour",
234 267 "branch.actions": "Actions",
268 "branch.tab.overview": "Aperçu",
269 "branch.tab.active": "Actives",
270 "branch.tab.stale": "Inactives",
271 "branch.tab.all": "Toutes",
272 "branch.group.active": "Branches actives",
273 "branch.group.stale": "Branches inactives",
274 "branch.filter": "Filtrer par nom de branche",
275 "branch.download": "Télécharger",
276 "branch.makeMR": "Créer une MR",
277 "branch.none.active": "Aucune branche active.",
278 "branch.none.stale": "Aucune branche inactive.",
235 279 "mr.draft": "Brouillon",
236 280 "mr.markDraft": "Marquer comme brouillon",
237 281 "mr.block.draft": "Cette merge request est un brouillon.",
@@ -25,6 +25,17 @@ var branchEN = map[string]string{
25 "branch.behind": "%d behind",
25 "branch.behind": "%d behind",
26 "branch.even": "Up to date",
26 "branch.even": "Up to date",
27 "branch.actions": "Actions",
27 "branch.actions": "Actions",
28 "branch.tab.overview": "Overview",
29 "branch.tab.active": "Active",
30 "branch.tab.stale": "Stale",
31 "branch.tab.all": "All",
32 "branch.group.active": "Active branches",
33 "branch.group.stale": "Stale branches",
34 "branch.filter": "Filter by branch name",
35 "branch.download": "Download",
36 "branch.makeMR": "Create MR",
37 "branch.none.active": "No active branches.",
38 "branch.none.stale": "No stale branches.",
28 "mr.draft": "Draft",
39 "mr.draft": "Draft",
29 "mr.markDraft": "Mark as draft",
40 "mr.markDraft": "Mark as draft",
30 "mr.block.draft": "This merge request is a draft.",
41 "mr.block.draft": "This merge request is a draft.",
@@ -94,6 +105,17 @@ var branchNL = map[string]string{
94 "branch.behind": "%d achter",
105 "branch.behind": "%d achter",
95 "branch.even": "Bijgewerkt",
106 "branch.even": "Bijgewerkt",
96 "branch.actions": "Acties",
107 "branch.actions": "Acties",
108 "branch.tab.overview": "Overzicht",
109 "branch.tab.active": "Actief",
110 "branch.tab.stale": "Inactief",
111 "branch.tab.all": "Alles",
112 "branch.group.active": "Actieve branches",
113 "branch.group.stale": "Inactieve branches",
114 "branch.filter": "Filter op branchnaam",
115 "branch.download": "Downloaden",
116 "branch.makeMR": "MR maken",
117 "branch.none.active": "Geen actieve branches.",
118 "branch.none.stale": "Geen inactieve branches.",
97 "mr.draft": "Concept",
119 "mr.draft": "Concept",
98 "mr.markDraft": "Als concept markeren",
120 "mr.markDraft": "Als concept markeren",
99 "mr.block.draft": "Deze merge request is een concept.",
121 "mr.block.draft": "Deze merge request is een concept.",
@@ -163,6 +185,17 @@ var branchDE = map[string]string{
163 "branch.behind": "%d zurück",
185 "branch.behind": "%d zurück",
164 "branch.even": "Aktuell",
186 "branch.even": "Aktuell",
165 "branch.actions": "Aktionen",
187 "branch.actions": "Aktionen",
188 "branch.tab.overview": "Übersicht",
189 "branch.tab.active": "Aktiv",
190 "branch.tab.stale": "Veraltet",
191 "branch.tab.all": "Alle",
192 "branch.group.active": "Aktive Branches",
193 "branch.group.stale": "Veraltete Branches",
194 "branch.filter": "Nach Branchname filtern",
195 "branch.download": "Herunterladen",
196 "branch.makeMR": "MR erstellen",
197 "branch.none.active": "Keine aktiven Branches.",
198 "branch.none.stale": "Keine veralteten Branches.",
166 "mr.draft": "Entwurf",
199 "mr.draft": "Entwurf",
167 "mr.markDraft": "Als Entwurf markieren",
200 "mr.markDraft": "Als Entwurf markieren",
168 "mr.block.draft": "Dieser Merge Request ist ein Entwurf.",
201 "mr.block.draft": "Dieser Merge Request ist ein Entwurf.",
@@ -232,6 +265,17 @@ var branchFR = map[string]string{
232 "branch.behind": "%d en retard",
265 "branch.behind": "%d en retard",
233 "branch.even": "À jour",
266 "branch.even": "À jour",
234 "branch.actions": "Actions",
267 "branch.actions": "Actions",
268 "branch.tab.overview": "Aperçu",
269 "branch.tab.active": "Actives",
270 "branch.tab.stale": "Inactives",
271 "branch.tab.all": "Toutes",
272 "branch.group.active": "Branches actives",
273 "branch.group.stale": "Branches inactives",
274 "branch.filter": "Filtrer par nom de branche",
275 "branch.download": "Télécharger",
276 "branch.makeMR": "Créer une MR",
277 "branch.none.active": "Aucune branche active.",
278 "branch.none.stale": "Aucune branche inactive.",
235 "mr.draft": "Brouillon",
279 "mr.draft": "Brouillon",
236 "mr.markDraft": "Marquer comme brouillon",
280 "mr.markDraft": "Marquer comme brouillon",
237 "mr.block.draft": "Cette merge request est un brouillon.",
281 "mr.block.draft": "Cette merge request est un brouillon.",
internal/i18n/catalog_lang.go +3 −3
@@ -150,7 +150,7 @@ var nl = map[string]string{
150 150 "repo.binary": "Binair bestand.",
151 151 "repo.noTags": "Nog geen tags.",
152 152 "tag.search": "Zoek een tag",
153 "tag.create": "Tag aanmaken",
153 "tag.create": "Nieuwe tag",
154 154 "tag.name": "Naam",
155 155 "tag.target": "Branch of commit",
156 156 "tag.message": "Bericht",
@@ -772,7 +772,7 @@ var de = map[string]string{
772 772 "repo.binary": "Binäre Datei.",
773 773 "repo.noTags": "Noch keine Tags.",
774 774 "tag.search": "Tag suchen",
775 "tag.create": "Tag anlegen",
775 "tag.create": "Neuer Tag",
776 776 "tag.name": "Name",
777 777 "tag.target": "Branch oder Commit",
778 778 "tag.message": "Nachricht",
@@ -1394,7 +1394,7 @@ var fr = map[string]string{
1394 1394 "repo.binary": "Fichier binaire.",
1395 1395 "repo.noTags": "Pas encore de tags.",
1396 1396 "tag.search": "Chercher un tag",
1397 "tag.create": "Créer un tag",
1397 "tag.create": "Nouveau tag",
1398 1398 "tag.name": "Nom",
1399 1399 "tag.target": "Branche ou commit",
1400 1400 "tag.message": "Message",
@@ -150,7 +150,7 @@ var nl = map[string]string{
150 "repo.binary": "Binair bestand.",
150 "repo.binary": "Binair bestand.",
151 "repo.noTags": "Nog geen tags.",
151 "repo.noTags": "Nog geen tags.",
152 "tag.search": "Zoek een tag",
152 "tag.search": "Zoek een tag",
153 "tag.create": "Tag aanmaken",
153 "tag.create": "Nieuwe tag",
154 "tag.name": "Naam",
154 "tag.name": "Naam",
155 "tag.target": "Branch of commit",
155 "tag.target": "Branch of commit",
156 "tag.message": "Bericht",
156 "tag.message": "Bericht",
@@ -772,7 +772,7 @@ var de = map[string]string{
772 "repo.binary": "Binäre Datei.",
772 "repo.binary": "Binäre Datei.",
773 "repo.noTags": "Noch keine Tags.",
773 "repo.noTags": "Noch keine Tags.",
774 "tag.search": "Tag suchen",
774 "tag.search": "Tag suchen",
775 "tag.create": "Tag anlegen",
775 "tag.create": "Neuer Tag",
776 "tag.name": "Name",
776 "tag.name": "Name",
777 "tag.target": "Branch oder Commit",
777 "tag.target": "Branch oder Commit",
778 "tag.message": "Nachricht",
778 "tag.message": "Nachricht",
@@ -1394,7 +1394,7 @@ var fr = map[string]string{
1394 "repo.binary": "Fichier binaire.",
1394 "repo.binary": "Fichier binaire.",
1395 "repo.noTags": "Pas encore de tags.",
1395 "repo.noTags": "Pas encore de tags.",
1396 "tag.search": "Chercher un tag",
1396 "tag.search": "Chercher un tag",
1397 "tag.create": "Créer un tag",
1397 "tag.create": "Nouveau tag",
1398 "tag.name": "Nom",
1398 "tag.name": "Nom",
1399 "tag.target": "Branche ou commit",
1399 "tag.target": "Branche ou commit",
1400 "tag.message": "Message",
1400 "tag.message": "Message",
internal/server/branch_page_test.go added +171 −0
@@ -0,0 +1,171 @@
1 package server
2
3 import (
4 "io"
5 "net/http"
6 "net/http/cookiejar"
7 "net/http/httptest"
8 "net/url"
9 "os"
10 "os/exec"
11 "path/filepath"
12 "strings"
13 "testing"
14 "time"
15
16 "gitlab.com/Timfa/bluegit/internal/auth"
17 "gitlab.com/Timfa/bluegit/internal/config"
18 "gitlab.com/Timfa/bluegit/internal/store"
19 )
20
21 func TestBranchIsStale(t *testing.T) {
22 now := time.Date(2026, 10, 23, 12, 0, 0, 0, time.UTC)
23 old := now.Add(-91 * 24 * time.Hour).Unix()
24 fresh := now.Add(-10 * 24 * time.Hour).Unix()
25 if !branchIsStale(old, false, now) {
26 t.Fatal("een branch zonder commit in drie maanden is inactief")
27 }
28 if branchIsStale(old, true, now) {
29 t.Fatal("de standaardbranch blijft actief")
30 }
31 if branchIsStale(fresh, false, now) {
32 t.Fatal("een recente branch is actief")
33 }
34 if branchIsStale(0, false, now) {
35 t.Fatal("een branch zonder datum is actief")
36 }
37 }
38
39 func TestBranchGroupsAndArchive(t *testing.T) {
40 if _, err := exec.LookPath("git"); err != nil {
41 t.Skip("git ontbreekt")
42 }
43 storage := t.TempDir()
44 st, err := store.Open(filepath.Join(storage, "bluegit.db"), bytes32())
45 if err != nil {
46 t.Fatal(err)
47 }
48 t.Cleanup(func() { _ = st.Close() })
49 cfg := config.Config{
50 BaseURL: "http://127.0.0.1:9", Listen: "127.0.0.1:0", StoragePath: storage,
51 Auth: config.Auth{Mode: "dev", DevUser: "tim", DevAuthID: 1, UserAgent: "test", BaseURL: "https://auth.timfalken.com"},
52 Git: config.Git{Binary: "git", DefaultBranch: "master"},
53 }
54 srv := &Server{Cfg: cfg, Store: st, Auth: auth.Dev{Username: "tim", AuthID: 1}, Dev: true, Git: "git", HookBin: "/bin/true"}
55 ts := httptest.NewServer(srv.Handler())
56 t.Cleanup(ts.Close)
57 jar, _ := cookiejar.New(nil)
58 tim := &http.Client{Jar: jar}
59 page := read(t, mustGet(t, tim, ts.URL+"/login"))
60 page = read(t, mustPost(t, tim, ts.URL+"/new/repo", url.Values{
61 "csrf": {csrfOf(t, page)}, "name": {"groepen"}, "visibility": {"public"},
62 }))
63 page = read(t, mustPost(t, tim, ts.URL+"/settings/tokens", url.Values{
64 "csrf": {csrfOf(t, page)}, "name": {"laptop"},
65 }))
66 token := between(page, `<p class="code">`, "</p>")
67 remote := strings.Replace(ts.URL, "http://", "http://tim:"+token+"@", 1) + "/tim/groepen.git"
68 work := t.TempDir()
69 git(t, work, "init", "-b", "master")
70 git(t, work, "config", "user.email", "tim@users.git.timfalken.com")
71 git(t, work, "config", "user.name", "tim")
72 writeFile(t, filepath.Join(work, "hello.txt"), "alpha\n")
73 git(t, work, "add", "hello.txt")
74 git(t, work, "commit", "-m", "start")
75 git(t, work, "remote", "add", "origin", remote)
76 git(t, work, "push", "-u", "origin", "master")
77
78 git(t, work, "checkout", "-b", "vers")
79 writeFile(t, filepath.Join(work, "hello.txt"), "beta\n")
80 git(t, work, "add", "hello.txt")
81 git(t, work, "commit", "-m", "vers-onderwerp")
82 git(t, work, "push", "-u", "origin", "vers")
83
84 git(t, work, "checkout", "-b", "oud", "master")
85 writeFile(t, filepath.Join(work, "hello.txt"), "oud\n")
86 git(t, work, "add", "hello.txt")
87 commitAt(t, work, "oud-onderwerp", "2020-01-15T12:00:00")
88 git(t, work, "push", "-u", "origin", "oud")
89
90 overview := read(t, mustGet(t, tim, ts.URL+"/tim/groepen/-/branches"))
91 for _, want := range []string{
92 `class="on"`, "Overview", "Active branches", "Stale branches",
93 `data-name="master"`, `data-name="vers"`, `data-name="oud"`,
94 "Filter by branch name", "New branch", "default",
95 `data-copy="oud"`, "Create MR", "vers-onderwerp", "oud-onderwerp",
96 "/-/branches/archive?name=oud&amp;format=zip",
97 "/-/branches/archive?name=oud&amp;format=tar.gz",
98 "/-/merge-requests/new?source=oud&amp;target=master",
99 } {
100 if !strings.Contains(overview, want) {
101 t.Fatalf("overzicht mist %q", want)
102 }
103 }
104 if strings.Contains(overview, `data-delete="master"`) {
105 t.Fatal("de standaardbranch heeft een verwijderknop")
106 }
107 if !strings.Contains(overview, `data-delete="oud"`) || !strings.Contains(overview, `data-delete="vers"`) {
108 t.Fatal("een gewone branch mist de verwijderknop")
109 }
110 oudAt := strings.Index(overview, `data-name="oud"`)
111 staleAt := strings.Index(overview, "Stale branches")
112 activeAt := strings.Index(overview, "Active branches")
113 if activeAt < 0 || staleAt < activeAt || oudAt < staleAt {
114 t.Fatalf("oud hoort in de inactieve groep:\n%s", overview)
115 }
116
117 active := read(t, mustGet(t, tim, ts.URL+"/tim/groepen/-/branches?state=active"))
118 if strings.Contains(active, `data-name="oud"`) || strings.Contains(active, "Stale branches") || !strings.Contains(active, `data-name="master"`) {
119 t.Fatalf("actief:\n%s", active)
120 }
121 stale := read(t, mustGet(t, tim, ts.URL+"/tim/groepen/-/branches?state=stale"))
122 if !strings.Contains(stale, `data-name="oud"`) || strings.Contains(stale, `data-name="master"`) || strings.Contains(stale, "Active branches") {
123 t.Fatalf("inactief:\n%s", stale)
124 }
125 if !strings.Contains(stale, `state=stale"`) || !strings.Contains(stale, `class="on"`) {
126 t.Fatalf("tab inactief:\n%s", stale)
127 }
128
129 zipRes := mustGet(t, tim, ts.URL+"/tim/groepen/-/branches/archive?name=oud&format=zip")
130 zipBody, err := io.ReadAll(zipRes.Body)
131 zipRes.Body.Close()
132 if err != nil {
133 t.Fatal(err)
134 }
135 if zipRes.StatusCode != http.StatusOK || len(zipBody) < 2 || zipBody[0] != 'P' || zipBody[1] != 'K' {
136 t.Fatalf("zip status %d lengte %d", zipRes.StatusCode, len(zipBody))
137 }
138 if !strings.Contains(zipRes.Header.Get("Content-Disposition"), "groepen-oud.zip") {
139 t.Fatalf("bestandsnaam: %s", zipRes.Header.Get("Content-Disposition"))
140 }
141 tarRes := mustGet(t, tim, ts.URL+"/tim/groepen/-/branches/archive?name=vers&format=tar.gz")
142 tarBody, err := io.ReadAll(tarRes.Body)
143 tarRes.Body.Close()
144 if err != nil {
145 t.Fatal(err)
146 }
147 if tarRes.StatusCode != http.StatusOK || len(tarBody) < 2 || tarBody[0] != 0x1f || tarBody[1] != 0x8b {
148 t.Fatalf("tar.gz status %d", tarRes.StatusCode)
149 }
150 missing := mustGet(t, tim, ts.URL+"/tim/groepen/-/branches/archive?name=geen&format=zip")
151 missing.Body.Close()
152 if missing.StatusCode != http.StatusNotFound {
153 t.Fatalf("ontbrekende branch: %d", missing.StatusCode)
154 }
155 bad := mustGet(t, tim, ts.URL+"/tim/groepen/-/branches/archive?name=master&format=exe")
156 bad.Body.Close()
157 if bad.StatusCode != http.StatusNotFound {
158 t.Fatalf("formaat: %d", bad.StatusCode)
159 }
160 }
161
162 func commitAt(t *testing.T, dir, msg, when string) {
163 t.Helper()
164 cmd := exec.Command("git", "-c", "commit.gpgsign=false", "commit", "-m", msg)
165 cmd.Dir = dir
166 cmd.Env = append(os.Environ(), "GIT_AUTHOR_DATE="+when, "GIT_COMMITTER_DATE="+when)
167 out, err := cmd.CombinedOutput()
168 if err != nil {
169 t.Fatalf("commit: %v\n%s", err, out)
170 }
171 }
@@ -0,0 +1,171 @@
1package server
2
3import (
4 "io"
5 "net/http"
6 "net/http/cookiejar"
7 "net/http/httptest"
8 "net/url"
9 "os"
10 "os/exec"
11 "path/filepath"
12 "strings"
13 "testing"
14 "time"
15
16 "gitlab.com/Timfa/bluegit/internal/auth"
17 "gitlab.com/Timfa/bluegit/internal/config"
18 "gitlab.com/Timfa/bluegit/internal/store"
19)
20
21func TestBranchIsStale(t *testing.T) {
22 now := time.Date(2026, 10, 23, 12, 0, 0, 0, time.UTC)
23 old := now.Add(-91 * 24 * time.Hour).Unix()
24 fresh := now.Add(-10 * 24 * time.Hour).Unix()
25 if !branchIsStale(old, false, now) {
26 t.Fatal("een branch zonder commit in drie maanden is inactief")
27 }
28 if branchIsStale(old, true, now) {
29 t.Fatal("de standaardbranch blijft actief")
30 }
31 if branchIsStale(fresh, false, now) {
32 t.Fatal("een recente branch is actief")
33 }
34 if branchIsStale(0, false, now) {
35 t.Fatal("een branch zonder datum is actief")
36 }
37}
38
39func TestBranchGroupsAndArchive(t *testing.T) {
40 if _, err := exec.LookPath("git"); err != nil {
41 t.Skip("git ontbreekt")
42 }
43 storage := t.TempDir()
44 st, err := store.Open(filepath.Join(storage, "bluegit.db"), bytes32())
45 if err != nil {
46 t.Fatal(err)
47 }
48 t.Cleanup(func() { _ = st.Close() })
49 cfg := config.Config{
50 BaseURL: "http://127.0.0.1:9", Listen: "127.0.0.1:0", StoragePath: storage,
51 Auth: config.Auth{Mode: "dev", DevUser: "tim", DevAuthID: 1, UserAgent: "test", BaseURL: "https://auth.timfalken.com"},
52 Git: config.Git{Binary: "git", DefaultBranch: "master"},
53 }
54 srv := &Server{Cfg: cfg, Store: st, Auth: auth.Dev{Username: "tim", AuthID: 1}, Dev: true, Git: "git", HookBin: "/bin/true"}
55 ts := httptest.NewServer(srv.Handler())
56 t.Cleanup(ts.Close)
57 jar, _ := cookiejar.New(nil)
58 tim := &http.Client{Jar: jar}
59 page := read(t, mustGet(t, tim, ts.URL+"/login"))
60 page = read(t, mustPost(t, tim, ts.URL+"/new/repo", url.Values{
61 "csrf": {csrfOf(t, page)}, "name": {"groepen"}, "visibility": {"public"},
62 }))
63 page = read(t, mustPost(t, tim, ts.URL+"/settings/tokens", url.Values{
64 "csrf": {csrfOf(t, page)}, "name": {"laptop"},
65 }))
66 token := between(page, `<p class="code">`, "</p>")
67 remote := strings.Replace(ts.URL, "http://", "http://tim:"+token+"@", 1) + "/tim/groepen.git"
68 work := t.TempDir()
69 git(t, work, "init", "-b", "master")
70 git(t, work, "config", "user.email", "tim@users.git.timfalken.com")
71 git(t, work, "config", "user.name", "tim")
72 writeFile(t, filepath.Join(work, "hello.txt"), "alpha\n")
73 git(t, work, "add", "hello.txt")
74 git(t, work, "commit", "-m", "start")
75 git(t, work, "remote", "add", "origin", remote)
76 git(t, work, "push", "-u", "origin", "master")
77
78 git(t, work, "checkout", "-b", "vers")
79 writeFile(t, filepath.Join(work, "hello.txt"), "beta\n")
80 git(t, work, "add", "hello.txt")
81 git(t, work, "commit", "-m", "vers-onderwerp")
82 git(t, work, "push", "-u", "origin", "vers")
83
84 git(t, work, "checkout", "-b", "oud", "master")
85 writeFile(t, filepath.Join(work, "hello.txt"), "oud\n")
86 git(t, work, "add", "hello.txt")
87 commitAt(t, work, "oud-onderwerp", "2020-01-15T12:00:00")
88 git(t, work, "push", "-u", "origin", "oud")
89
90 overview := read(t, mustGet(t, tim, ts.URL+"/tim/groepen/-/branches"))
91 for _, want := range []string{
92 `class="on"`, "Overview", "Active branches", "Stale branches",
93 `data-name="master"`, `data-name="vers"`, `data-name="oud"`,
94 "Filter by branch name", "New branch", "default",
95 `data-copy="oud"`, "Create MR", "vers-onderwerp", "oud-onderwerp",
96 "/-/branches/archive?name=oud&amp;format=zip",
97 "/-/branches/archive?name=oud&amp;format=tar.gz",
98 "/-/merge-requests/new?source=oud&amp;target=master",
99 } {
100 if !strings.Contains(overview, want) {
101 t.Fatalf("overzicht mist %q", want)
102 }
103 }
104 if strings.Contains(overview, `data-delete="master"`) {
105 t.Fatal("de standaardbranch heeft een verwijderknop")
106 }
107 if !strings.Contains(overview, `data-delete="oud"`) || !strings.Contains(overview, `data-delete="vers"`) {
108 t.Fatal("een gewone branch mist de verwijderknop")
109 }
110 oudAt := strings.Index(overview, `data-name="oud"`)
111 staleAt := strings.Index(overview, "Stale branches")
112 activeAt := strings.Index(overview, "Active branches")
113 if activeAt < 0 || staleAt < activeAt || oudAt < staleAt {
114 t.Fatalf("oud hoort in de inactieve groep:\n%s", overview)
115 }
116
117 active := read(t, mustGet(t, tim, ts.URL+"/tim/groepen/-/branches?state=active"))
118 if strings.Contains(active, `data-name="oud"`) || strings.Contains(active, "Stale branches") || !strings.Contains(active, `data-name="master"`) {
119 t.Fatalf("actief:\n%s", active)
120 }
121 stale := read(t, mustGet(t, tim, ts.URL+"/tim/groepen/-/branches?state=stale"))
122 if !strings.Contains(stale, `data-name="oud"`) || strings.Contains(stale, `data-name="master"`) || strings.Contains(stale, "Active branches") {
123 t.Fatalf("inactief:\n%s", stale)
124 }
125 if !strings.Contains(stale, `state=stale"`) || !strings.Contains(stale, `class="on"`) {
126 t.Fatalf("tab inactief:\n%s", stale)
127 }
128
129 zipRes := mustGet(t, tim, ts.URL+"/tim/groepen/-/branches/archive?name=oud&format=zip")
130 zipBody, err := io.ReadAll(zipRes.Body)
131 zipRes.Body.Close()
132 if err != nil {
133 t.Fatal(err)
134 }
135 if zipRes.StatusCode != http.StatusOK || len(zipBody) < 2 || zipBody[0] != 'P' || zipBody[1] != 'K' {
136 t.Fatalf("zip status %d lengte %d", zipRes.StatusCode, len(zipBody))
137 }
138 if !strings.Contains(zipRes.Header.Get("Content-Disposition"), "groepen-oud.zip") {
139 t.Fatalf("bestandsnaam: %s", zipRes.Header.Get("Content-Disposition"))
140 }
141 tarRes := mustGet(t, tim, ts.URL+"/tim/groepen/-/branches/archive?name=vers&format=tar.gz")
142 tarBody, err := io.ReadAll(tarRes.Body)
143 tarRes.Body.Close()
144 if err != nil {
145 t.Fatal(err)
146 }
147 if tarRes.StatusCode != http.StatusOK || len(tarBody) < 2 || tarBody[0] != 0x1f || tarBody[1] != 0x8b {
148 t.Fatalf("tar.gz status %d", tarRes.StatusCode)
149 }
150 missing := mustGet(t, tim, ts.URL+"/tim/groepen/-/branches/archive?name=geen&format=zip")
151 missing.Body.Close()
152 if missing.StatusCode != http.StatusNotFound {
153 t.Fatalf("ontbrekende branch: %d", missing.StatusCode)
154 }
155 bad := mustGet(t, tim, ts.URL+"/tim/groepen/-/branches/archive?name=master&format=exe")
156 bad.Body.Close()
157 if bad.StatusCode != http.StatusNotFound {
158 t.Fatalf("formaat: %d", bad.StatusCode)
159 }
160}
161
162func commitAt(t *testing.T, dir, msg, when string) {
163 t.Helper()
164 cmd := exec.Command("git", "-c", "commit.gpgsign=false", "commit", "-m", msg)
165 cmd.Dir = dir
166 cmd.Env = append(os.Environ(), "GIT_AUTHOR_DATE="+when, "GIT_COMMITTER_DATE="+when)
167 out, err := cmd.CombinedOutput()
168 if err != nil {
169 t.Fatalf("commit: %v\n%s", err, out)
170 }
171}
internal/server/branches.go +78 −2
@@ -2,6 +2,7 @@ package server
2 2
3 3 import (
4 4 "net/http"
5 "net/url"
5 6 "sort"
6 7 "strconv"
7 8 "strings"
@@ -10,9 +11,13 @@ import (
10 11 "gitlab.com/Timfa/bluegit/internal/access"
11 12 "gitlab.com/Timfa/bluegit/internal/gitrepo"
12 13 "gitlab.com/Timfa/bluegit/internal/i18n"
14 "gitlab.com/Timfa/bluegit/internal/names"
13 15 "gitlab.com/Timfa/bluegit/internal/store"
14 16 )
15 17
18 // Een branch zonder commit in drie maanden is inactief, zoals bij GitLab.
19 const branchStaleAfter = 90 * 24 * time.Hour
20
16 21 func (s *Server) branches(w http.ResponseWriter, r *http.Request) {
17 22 _, repo, role, ok := s.guard(w, r, access.RoleReadonly)
18 23 if !ok {
@@ -21,18 +26,26 @@ func (s *Server) branches(w http.ResponseWriter, r *http.Request) {
21 26 s.absorbMergedMRs(r.Context(), repo)
22 27 v := s.repoView(w, r, repo, role, "title.branches")
23 28 v.Page = "branches"
29 v.Wide = true
24 30 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
25 31 tips, _ := gitrepo.BranchTips(r.Context(), s.Git, dir)
26 32 patterns, _ := s.Store.ProtectedPatterns(r.Context(), repo.ID)
27 33 lang := s.langOf(r)
34 now := time.Now()
28 35 for _, tip := range tips {
29 36 when, title := branchWhen(lang, tip.Date)
37 unix, _ := strconv.ParseInt(strings.TrimSpace(tip.Date), 10, 64)
30 38 row := BranchRow{
31 39 Name: tip.Name, SHA: tip.SHA, Short: shortSHA(tip.SHA),
32 Subject: tip.Subject, When: when, WhenTitle: title,
40 Subject: tip.Subject, When: when, WhenTitle: title, Unix: unix,
33 41 Protected: access.BranchProtected(patterns, tip.Name),
34 42 Default: tip.Name == repo.DefaultBranch,
43 RepoPath: repo.FullPath(),
44 Target: repo.DefaultBranch,
45 ZipURL: branchArchiveURL(repo, tip.Name, "zip"),
46 TarURL: branchArchiveURL(repo, tip.Name, "tar.gz"),
35 47 }
48 row.CanEdit = role.CanWriteCode() && !row.Default && !row.Protected
36 49 if !row.Default && repo.DefaultBranch != "" {
37 50 ahead, behind, err := gitrepo.AheadBehind(r.Context(), s.Git, dir, repo.DefaultBranch, tip.Name)
38 51 if err == nil {
@@ -56,8 +69,32 @@ func (s *Server) branches(w http.ResponseWriter, r *http.Request) {
56 69 if v.Branches[i].Default != v.Branches[j].Default {
57 70 return v.Branches[i].Default
58 71 }
72 if v.Branches[i].Unix != v.Branches[j].Unix {
73 return v.Branches[i].Unix > v.Branches[j].Unix
74 }
59 75 return v.Branches[i].Name < v.Branches[j].Name
60 76 })
77 state := branchTab(r.URL.Query().Get("state"))
78 board := &BranchBoard{State: state}
79 for _, row := range v.Branches {
80 if branchIsStale(row.Unix, row.Default, now) {
81 board.Stale = append(board.Stale, row)
82 } else {
83 board.Active = append(board.Active, row)
84 }
85 }
86 switch state {
87 case "active":
88 board.ShowActive = true
89 case "stale":
90 board.ShowStale = true
91 case "all":
92 board.ShowActive, board.ShowStale = true, true
93 default:
94 board.ShowActive = len(board.Active) > 0 || len(board.Stale) == 0
95 board.ShowStale = len(board.Stale) > 0
96 }
97 v.Branch = board
61 98 tags, _ := gitrepo.Tags(r.Context(), s.Git, dir)
62 99 for _, name := range tags {
63 100 v.Tags = append(v.Tags, TagRow{Name: name})
@@ -65,6 +102,25 @@ func (s *Server) branches(w http.ResponseWriter, r *http.Request) {
65 102 s.render(w, "branches", v)
66 103 }
67 104
105 func (s *Server) branchArchive(w http.ResponseWriter, r *http.Request) {
106 _, repo, _, ok := s.guard(w, r, access.RoleReadonly)
107 if !ok {
108 return
109 }
110 name := r.URL.Query().Get("name")
111 format := r.URL.Query().Get("format")
112 if names.ValidBranch(name) != nil || (format != "zip" && format != "tar.gz") {
113 http.NotFound(w, r)
114 return
115 }
116 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
117 if gitOne(r.Context(), s.Git, dir, "rev-parse", "--verify", "--quiet", "refs/heads/"+name) == "" {
118 http.NotFound(w, r)
119 return
120 }
121 s.writeArchive(w, r, repo, dir, "refs/heads/"+name, name, format)
122 }
123
68 124 func (s *Server) createBranch(w http.ResponseWriter, r *http.Request) {
69 125 u, repo, _, ok := s.guard(w, r, access.RoleDeveloper)
70 126 if !ok || !s.csrfOK(w, r) {
@@ -101,13 +157,33 @@ func (s *Server) renameBranch(w http.ResponseWriter, r *http.Request) {
101 157 s.redirect(w, r, back, s.tr(r, "flash.branchRenamed"), "")
102 158 }
103 159
160 func branchTab(raw string) string {
161 switch raw {
162 case "active", "stale", "all":
163 return raw
164 default:
165 return "overview"
166 }
167 }
168
169 func branchIsStale(unix int64, isDefault bool, now time.Time) bool {
170 if isDefault || unix <= 0 {
171 return false
172 }
173 return now.Sub(time.Unix(unix, 0)) > branchStaleAfter
174 }
175
176 func branchArchiveURL(repo interface{ FullPath() string }, name, format string) string {
177 return "/" + repo.FullPath() + "/-/branches/archive?name=" + url.QueryEscape(name) + "&format=" + format
178 }
179
104 180 func branchWhen(lang i18n.Lang, unixText string) (short, title string) {
105 181 unix, err := strconv.ParseInt(strings.TrimSpace(unixText), 10, 64)
106 182 if err != nil || unix <= 0 {
107 183 return "", ""
108 184 }
109 185 at := time.Unix(unix, 0).UTC()
110 return i18n.ShortAgo(lang, unix), at.Format("2006-01-02 15:04 UTC")
186 return i18n.Ago(lang, unix), at.Format("2006-01-02 15:04 UTC")
111 187 }
112 188
113 189 // branchLocked weigert de standaardbranch en elke beschermde branch, ook voor een beheerder.
@@ -2,6 +2,7 @@ package server
2
2
3import (
3import (
4 "net/http"
4 "net/http"
5 "net/url"
5 "sort"
6 "sort"
6 "strconv"
7 "strconv"
7 "strings"
8 "strings"
@@ -10,9 +11,13 @@ import (
10 "gitlab.com/Timfa/bluegit/internal/access"
11 "gitlab.com/Timfa/bluegit/internal/access"
11 "gitlab.com/Timfa/bluegit/internal/gitrepo"
12 "gitlab.com/Timfa/bluegit/internal/gitrepo"
12 "gitlab.com/Timfa/bluegit/internal/i18n"
13 "gitlab.com/Timfa/bluegit/internal/i18n"
14 "gitlab.com/Timfa/bluegit/internal/names"
13 "gitlab.com/Timfa/bluegit/internal/store"
15 "gitlab.com/Timfa/bluegit/internal/store"
14)
16)
15
17
18// Een branch zonder commit in drie maanden is inactief, zoals bij GitLab.
19const branchStaleAfter = 90 * 24 * time.Hour
20
16func (s *Server) branches(w http.ResponseWriter, r *http.Request) {
21func (s *Server) branches(w http.ResponseWriter, r *http.Request) {
17 _, repo, role, ok := s.guard(w, r, access.RoleReadonly)
22 _, repo, role, ok := s.guard(w, r, access.RoleReadonly)
18 if !ok {
23 if !ok {
@@ -21,18 +26,26 @@ func (s *Server) branches(w http.ResponseWriter, r *http.Request) {
21 s.absorbMergedMRs(r.Context(), repo)
26 s.absorbMergedMRs(r.Context(), repo)
22 v := s.repoView(w, r, repo, role, "title.branches")
27 v := s.repoView(w, r, repo, role, "title.branches")
23 v.Page = "branches"
28 v.Page = "branches"
29 v.Wide = true
24 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
30 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
25 tips, _ := gitrepo.BranchTips(r.Context(), s.Git, dir)
31 tips, _ := gitrepo.BranchTips(r.Context(), s.Git, dir)
26 patterns, _ := s.Store.ProtectedPatterns(r.Context(), repo.ID)
32 patterns, _ := s.Store.ProtectedPatterns(r.Context(), repo.ID)
27 lang := s.langOf(r)
33 lang := s.langOf(r)
34 now := time.Now()
28 for _, tip := range tips {
35 for _, tip := range tips {
29 when, title := branchWhen(lang, tip.Date)
36 when, title := branchWhen(lang, tip.Date)
37 unix, _ := strconv.ParseInt(strings.TrimSpace(tip.Date), 10, 64)
30 row := BranchRow{
38 row := BranchRow{
31 Name: tip.Name, SHA: tip.SHA, Short: shortSHA(tip.SHA),
39 Name: tip.Name, SHA: tip.SHA, Short: shortSHA(tip.SHA),
32 Subject: tip.Subject, When: when, WhenTitle: title,
40 Subject: tip.Subject, When: when, WhenTitle: title, Unix: unix,
33 Protected: access.BranchProtected(patterns, tip.Name),
41 Protected: access.BranchProtected(patterns, tip.Name),
34 Default: tip.Name == repo.DefaultBranch,
42 Default: tip.Name == repo.DefaultBranch,
43 RepoPath: repo.FullPath(),
44 Target: repo.DefaultBranch,
45 ZipURL: branchArchiveURL(repo, tip.Name, "zip"),
46 TarURL: branchArchiveURL(repo, tip.Name, "tar.gz"),
35 }
47 }
48 row.CanEdit = role.CanWriteCode() && !row.Default && !row.Protected
36 if !row.Default && repo.DefaultBranch != "" {
49 if !row.Default && repo.DefaultBranch != "" {
37 ahead, behind, err := gitrepo.AheadBehind(r.Context(), s.Git, dir, repo.DefaultBranch, tip.Name)
50 ahead, behind, err := gitrepo.AheadBehind(r.Context(), s.Git, dir, repo.DefaultBranch, tip.Name)
38 if err == nil {
51 if err == nil {
@@ -56,8 +69,32 @@ func (s *Server) branches(w http.ResponseWriter, r *http.Request) {
56 if v.Branches[i].Default != v.Branches[j].Default {
69 if v.Branches[i].Default != v.Branches[j].Default {
57 return v.Branches[i].Default
70 return v.Branches[i].Default
58 }
71 }
72 if v.Branches[i].Unix != v.Branches[j].Unix {
73 return v.Branches[i].Unix > v.Branches[j].Unix
74 }
59 return v.Branches[i].Name < v.Branches[j].Name
75 return v.Branches[i].Name < v.Branches[j].Name
60 })
76 })
77 state := branchTab(r.URL.Query().Get("state"))
78 board := &BranchBoard{State: state}
79 for _, row := range v.Branches {
80 if branchIsStale(row.Unix, row.Default, now) {
81 board.Stale = append(board.Stale, row)
82 } else {
83 board.Active = append(board.Active, row)
84 }
85 }
86 switch state {
87 case "active":
88 board.ShowActive = true
89 case "stale":
90 board.ShowStale = true
91 case "all":
92 board.ShowActive, board.ShowStale = true, true
93 default:
94 board.ShowActive = len(board.Active) > 0 || len(board.Stale) == 0
95 board.ShowStale = len(board.Stale) > 0
96 }
97 v.Branch = board
61 tags, _ := gitrepo.Tags(r.Context(), s.Git, dir)
98 tags, _ := gitrepo.Tags(r.Context(), s.Git, dir)
62 for _, name := range tags {
99 for _, name := range tags {
63 v.Tags = append(v.Tags, TagRow{Name: name})
100 v.Tags = append(v.Tags, TagRow{Name: name})
@@ -65,6 +102,25 @@ func (s *Server) branches(w http.ResponseWriter, r *http.Request) {
65 s.render(w, "branches", v)
102 s.render(w, "branches", v)
66}
103}
67
104
105func (s *Server) branchArchive(w http.ResponseWriter, r *http.Request) {
106 _, repo, _, ok := s.guard(w, r, access.RoleReadonly)
107 if !ok {
108 return
109 }
110 name := r.URL.Query().Get("name")
111 format := r.URL.Query().Get("format")
112 if names.ValidBranch(name) != nil || (format != "zip" && format != "tar.gz") {
113 http.NotFound(w, r)
114 return
115 }
116 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
117 if gitOne(r.Context(), s.Git, dir, "rev-parse", "--verify", "--quiet", "refs/heads/"+name) == "" {
118 http.NotFound(w, r)
119 return
120 }
121 s.writeArchive(w, r, repo, dir, "refs/heads/"+name, name, format)
122}
123
68func (s *Server) createBranch(w http.ResponseWriter, r *http.Request) {
124func (s *Server) createBranch(w http.ResponseWriter, r *http.Request) {
69 u, repo, _, ok := s.guard(w, r, access.RoleDeveloper)
125 u, repo, _, ok := s.guard(w, r, access.RoleDeveloper)
70 if !ok || !s.csrfOK(w, r) {
126 if !ok || !s.csrfOK(w, r) {
@@ -101,13 +157,33 @@ func (s *Server) renameBranch(w http.ResponseWriter, r *http.Request) {
101 s.redirect(w, r, back, s.tr(r, "flash.branchRenamed"), "")
157 s.redirect(w, r, back, s.tr(r, "flash.branchRenamed"), "")
102}
158}
103
159
160func branchTab(raw string) string {
161 switch raw {
162 case "active", "stale", "all":
163 return raw
164 default:
165 return "overview"
166 }
167}
168
169func branchIsStale(unix int64, isDefault bool, now time.Time) bool {
170 if isDefault || unix <= 0 {
171 return false
172 }
173 return now.Sub(time.Unix(unix, 0)) > branchStaleAfter
174}
175
176func branchArchiveURL(repo interface{ FullPath() string }, name, format string) string {
177 return "/" + repo.FullPath() + "/-/branches/archive?name=" + url.QueryEscape(name) + "&format=" + format
178}
179
104func branchWhen(lang i18n.Lang, unixText string) (short, title string) {
180func branchWhen(lang i18n.Lang, unixText string) (short, title string) {
105 unix, err := strconv.ParseInt(strings.TrimSpace(unixText), 10, 64)
181 unix, err := strconv.ParseInt(strings.TrimSpace(unixText), 10, 64)
106 if err != nil || unix <= 0 {
182 if err != nil || unix <= 0 {
107 return "", ""
183 return "", ""
108 }
184 }
109 at := time.Unix(unix, 0).UTC()
185 at := time.Unix(unix, 0).UTC()
110 return i18n.ShortAgo(lang, unix), at.Format("2006-01-02 15:04 UTC")
186 return i18n.Ago(lang, unix), at.Format("2006-01-02 15:04 UTC")
111}
187}
112
188
113// branchLocked weigert de standaardbranch en elke beschermde branch, ook voor een beheerder.
189// branchLocked weigert de standaardbranch en elke beschermde branch, ook voor een beheerder.
internal/server/server.go +16 −4
@@ -165,6 +165,7 @@ func (s *Server) Handler() http.Handler {
165 165 mux.HandleFunc("POST /{owner}/{repo}/-/tags/delete", s.deleteTag)
166 166 mux.HandleFunc("GET /{owner}/{repo}/-/tags/archive", s.tagArchive)
167 167 mux.HandleFunc("GET /{owner}/{repo}/-/commit/{sha}", s.commit)
168 mux.HandleFunc("GET /{owner}/{repo}/-/branches/archive", s.branchArchive)
168 169 mux.HandleFunc("GET /{owner}/{repo}/-/branches", s.branches)
169 170 mux.HandleFunc("POST /{owner}/{repo}/-/branches", s.createBranch)
170 171 mux.HandleFunc("POST /{owner}/{repo}/-/branches/delete", s.deleteBranch)
@@ -523,6 +524,7 @@ type View struct {
523 524 BlobPath string
524 525 Binary bool
525 526 Branches []BranchRow
527 Branch *BranchBoard
526 528 MRs []store.MergeRequest
527 529 Flow *FlowBoard
528 530 MR *store.MergeRequest
@@ -678,9 +680,9 @@ type DiffLineView struct {
678 680
679 681 // TagRow is één tag op de tagspagina.
680 682 type TagRow struct {
681 Name, Message, SHA, Short, Subject, Date string
682 Annotated, Protected, HasRelease, CanDelete bool
683 ZipURL, TarURL string
683 Name, Message, SHA, Short, Subject, Date, When string
684 Annotated, Protected, HasRelease, CanDelete bool
685 ZipURL, TarURL string
684 686 }
685 687
686 688 // FileRow is een rij in de bestandstabel of de boom.
@@ -720,13 +722,23 @@ type EntryRow struct {
720 722 // BranchRow is een branch, met of zonder bescherming.
721 723 type BranchRow struct {
722 724 Name, SHA, Short, Subject, When, WhenTitle string
723 Protected, Default bool
725 RepoPath, ZipURL, TarURL string
726 Protected, Default, CanEdit bool
727 Target string
724 728 Ahead, Behind int
729 Unix int64
725 730 PipeID int64
726 731 PipeStatus, PipeLabel string
727 732 OpenMRs []int64
728 733 }
729 734
735 // BranchBoard is de gegroepeerde branches-pagina.
736 type BranchBoard struct {
737 State string
738 ShowActive, ShowStale bool
739 Active, Stale []BranchRow
740 }
741
730 742 // TimelineItem is één gebeurtenis of reactie op een merge request.
731 743 type TimelineItem struct {
732 744 ID int64
@@ -165,6 +165,7 @@ func (s *Server) Handler() http.Handler {
165 mux.HandleFunc("POST /{owner}/{repo}/-/tags/delete", s.deleteTag)
165 mux.HandleFunc("POST /{owner}/{repo}/-/tags/delete", s.deleteTag)
166 mux.HandleFunc("GET /{owner}/{repo}/-/tags/archive", s.tagArchive)
166 mux.HandleFunc("GET /{owner}/{repo}/-/tags/archive", s.tagArchive)
167 mux.HandleFunc("GET /{owner}/{repo}/-/commit/{sha}", s.commit)
167 mux.HandleFunc("GET /{owner}/{repo}/-/commit/{sha}", s.commit)
168 mux.HandleFunc("GET /{owner}/{repo}/-/branches/archive", s.branchArchive)
168 mux.HandleFunc("GET /{owner}/{repo}/-/branches", s.branches)
169 mux.HandleFunc("GET /{owner}/{repo}/-/branches", s.branches)
169 mux.HandleFunc("POST /{owner}/{repo}/-/branches", s.createBranch)
170 mux.HandleFunc("POST /{owner}/{repo}/-/branches", s.createBranch)
170 mux.HandleFunc("POST /{owner}/{repo}/-/branches/delete", s.deleteBranch)
171 mux.HandleFunc("POST /{owner}/{repo}/-/branches/delete", s.deleteBranch)
@@ -523,6 +524,7 @@ type View struct {
523 BlobPath string
524 BlobPath string
524 Binary bool
525 Binary bool
525 Branches []BranchRow
526 Branches []BranchRow
527 Branch *BranchBoard
526 MRs []store.MergeRequest
528 MRs []store.MergeRequest
527 Flow *FlowBoard
529 Flow *FlowBoard
528 MR *store.MergeRequest
530 MR *store.MergeRequest
@@ -678,9 +680,9 @@ type DiffLineView struct {
678
680
679// TagRow is één tag op de tagspagina.
681// TagRow is één tag op de tagspagina.
680type TagRow struct {
682type TagRow struct {
681 Name, Message, SHA, Short, Subject, Date string
683 Name, Message, SHA, Short, Subject, Date, When string
682 Annotated, Protected, HasRelease, CanDelete bool
684 Annotated, Protected, HasRelease, CanDelete bool
683 ZipURL, TarURL string
685 ZipURL, TarURL string
684}
686}
685
687
686// FileRow is een rij in de bestandstabel of de boom.
688// FileRow is een rij in de bestandstabel of de boom.
@@ -720,13 +722,23 @@ type EntryRow struct {
720// BranchRow is een branch, met of zonder bescherming.
722// BranchRow is een branch, met of zonder bescherming.
721type BranchRow struct {
723type BranchRow struct {
722 Name, SHA, Short, Subject, When, WhenTitle string
724 Name, SHA, Short, Subject, When, WhenTitle string
723 Protected, Default bool
725 RepoPath, ZipURL, TarURL string
726 Protected, Default, CanEdit bool
727 Target string
724 Ahead, Behind int
728 Ahead, Behind int
729 Unix int64
725 PipeID int64
730 PipeID int64
726 PipeStatus, PipeLabel string
731 PipeStatus, PipeLabel string
727 OpenMRs []int64
732 OpenMRs []int64
728}
733}
729
734
735// BranchBoard is de gegroepeerde branches-pagina.
736type BranchBoard struct {
737 State string
738 ShowActive, ShowStale bool
739 Active, Stale []BranchRow
740}
741
730// TimelineItem is één gebeurtenis of reactie op een merge request.
742// TimelineItem is één gebeurtenis of reactie op een merge request.
731type TimelineItem struct {
743type TimelineItem struct {
732 ID int64
744 ID int64
internal/server/static/branch.js +7 −0
@@ -53,6 +53,13 @@
53 53 var name = (row.getAttribute("data-name") || "").toLowerCase();
54 54 row.hidden = q !== "" && name.indexOf(q) < 0;
55 55 });
56 document.querySelectorAll("[data-ref-group]").forEach(function (group) {
57 var visible = false;
58 group.querySelectorAll("[data-branch-row]").forEach(function (row) {
59 if (!row.hidden) visible = true;
60 });
61 group.hidden = !visible && group.querySelector("[data-branch-row]");
62 });
56 63 });
57 64 }
58 65 })();
@@ -53,6 +53,13 @@
53 var name = (row.getAttribute("data-name") || "").toLowerCase();
53 var name = (row.getAttribute("data-name") || "").toLowerCase();
54 row.hidden = q !== "" && name.indexOf(q) < 0;
54 row.hidden = q !== "" && name.indexOf(q) < 0;
55 });
55 });
56 document.querySelectorAll("[data-ref-group]").forEach(function (group) {
57 var visible = false;
58 group.querySelectorAll("[data-branch-row]").forEach(function (row) {
59 if (!row.hidden) visible = true;
60 });
61 group.hidden = !visible && group.querySelector("[data-branch-row]");
62 });
56 });
63 });
57 }
64 }
58})();
65})();
internal/server/static/style.css +70 −0
@@ -874,6 +874,76 @@ a.btn { text-decoration: none; }
874 874 text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
875 875 }
876 876 .when-short { white-space: nowrap; }
877 .refhead {
878 display: flex; align-items: center; justify-content: space-between;
879 gap: var(--sp-3); flex-wrap: wrap; margin: 0 0 var(--sp-3);
880 }
881 .refhead h1 { margin: 0; }
882 .refhead > button { margin-left: auto; }
883 .reftabs { display: flex; flex-wrap: wrap; gap: var(--sp-4); align-items: flex-end; min-width: 0; border-bottom: 1px solid var(--line); }
884 .reftabs a {
885 text-decoration: none; color: var(--muted); font-weight: 500;
886 padding: 0.45rem 0; margin-bottom: -1px; border-bottom: 2px solid transparent;
887 }
888 .reftabs a.on { color: var(--ink); border-bottom-color: var(--ink); }
889 .refsearch {
890 display: flex; align-items: center; gap: 0.4rem; margin: 0 0 var(--sp-3);
891 border: 1px solid var(--line); border-radius: var(--radius); background: white;
892 min-height: var(--control-h); padding: 0 0.55rem;
893 }
894 .refsearch input { border: 0; min-height: 0; padding: 0; background: transparent; flex: 1; width: auto; }
895 .refsearch input:focus { outline: none; }
896 .refsearch:focus-within { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-soft); }
897 .refsearch button.refgo {
898 background: transparent; color: var(--muted); border: 0; min-height: 0; width: 28px; padding: 0;
899 }
900 .refgroup {
901 background: #f4f1f8; border: 1px solid #e4dfeb; border-radius: var(--radius-lg);
902 padding: 0.35rem 0.85rem 0.7rem; margin: 0 0 var(--sp-4);
903 }
904 .refgroup h2 { margin: 0.55rem 0.2rem; font-size: 0.95rem; }
905 .refrow {
906 display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3);
907 background: white; border: 1px solid var(--line); border-radius: var(--radius-lg);
908 padding: 0.7rem 0.85rem; margin: 0.45rem 0;
909 }
910 .refrow[hidden], .refgroup[hidden] { display: none !important; }
911 .refmain { min-width: 0; }
912 .refname { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
913 .refname a { color: var(--ink); text-decoration: none; font-weight: 650; }
914 .refname code, .refname a code { font-family: var(--mono); font-size: 0.95rem; }
915 .refcopy { min-height: 24px; width: 24px; padding: 0; }
916 .refbadge { text-transform: lowercase; background: #eef1f4; color: #57606a; border-color: transparent; }
917 .refbadge.def { background: var(--blue-soft); color: var(--blue-deep); }
918 .refmeta {
919 margin: 0.28rem 0 0; color: var(--muted); font-size: var(--fs-sm);
920 display: flex; flex-wrap: wrap; gap: 0.35rem 0.55rem; align-items: center;
921 }
922 .refmeta a { color: inherit; }
923 .refdot { color: var(--muted); }
924 .refsubject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 36rem; }
925 .refnote { margin: 0.35rem 0 0; white-space: pre-wrap; }
926 .refacts { display: flex; align-items: center; gap: 0.35rem; flex: none; }
927 .refacts .tiny {
928 min-height: 1.7rem; padding: 0 0.45rem; font-size: var(--fs-sm);
929 background: white; color: var(--ink); border: 1px solid var(--line);
930 border-radius: var(--radius); text-decoration: none; line-height: 1.2;
931 }
932 .refacts .rowmenu > summary { display: inline-flex; align-items: center; justify-content: center; min-width: 2rem; min-height: 2rem; }
933 .refdlbtn::after {
934 content: ""; width: 0.32rem; height: 0.32rem; margin-left: 0.2rem;
935 border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
936 transform: translateY(-1px) rotate(45deg);
937 }
938 .menu-panel.refdl a { display: block; padding: 0.4rem 0.15rem; text-decoration: none; color: var(--ink); white-space: nowrap; }
939 .menu-panel.refdl[popover]:popover-open { width: max-content; min-width: 8.5rem; max-width: 14rem; padding: 0.35rem 0.9rem; }
940 .rowmenu .menu-panel a { display: block; padding: 0.35rem 0.2rem; text-decoration: none; color: var(--ink); }
941 .refempty { margin: 0.4rem 0.2rem 0.6rem; }
942 @media (max-width: 800px) {
943 .refrow { flex-direction: column; }
944 .refacts { flex-wrap: wrap; }
945 .refsubject { max-width: 100%; }
946 }
877 947 .mergewhy {
878 948 border: 1px solid var(--line); border-radius: var(--radius);
879 949 padding: 0.7rem 0.9rem; margin: 0.6rem 0; background: #fff8f0;
@@ -874,6 +874,76 @@ a.btn { text-decoration: none; }
874 text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
874 text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
875}
875}
876.when-short { white-space: nowrap; }
876.when-short { white-space: nowrap; }
877.refhead {
878 display: flex; align-items: center; justify-content: space-between;
879 gap: var(--sp-3); flex-wrap: wrap; margin: 0 0 var(--sp-3);
880}
881.refhead h1 { margin: 0; }
882.refhead > button { margin-left: auto; }
883.reftabs { display: flex; flex-wrap: wrap; gap: var(--sp-4); align-items: flex-end; min-width: 0; border-bottom: 1px solid var(--line); }
884.reftabs a {
885 text-decoration: none; color: var(--muted); font-weight: 500;
886 padding: 0.45rem 0; margin-bottom: -1px; border-bottom: 2px solid transparent;
887}
888.reftabs a.on { color: var(--ink); border-bottom-color: var(--ink); }
889.refsearch {
890 display: flex; align-items: center; gap: 0.4rem; margin: 0 0 var(--sp-3);
891 border: 1px solid var(--line); border-radius: var(--radius); background: white;
892 min-height: var(--control-h); padding: 0 0.55rem;
893}
894.refsearch input { border: 0; min-height: 0; padding: 0; background: transparent; flex: 1; width: auto; }
895.refsearch input:focus { outline: none; }
896.refsearch:focus-within { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-soft); }
897.refsearch button.refgo {
898 background: transparent; color: var(--muted); border: 0; min-height: 0; width: 28px; padding: 0;
899}
900.refgroup {
901 background: #f4f1f8; border: 1px solid #e4dfeb; border-radius: var(--radius-lg);
902 padding: 0.35rem 0.85rem 0.7rem; margin: 0 0 var(--sp-4);
903}
904.refgroup h2 { margin: 0.55rem 0.2rem; font-size: 0.95rem; }
905.refrow {
906 display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3);
907 background: white; border: 1px solid var(--line); border-radius: var(--radius-lg);
908 padding: 0.7rem 0.85rem; margin: 0.45rem 0;
909}
910.refrow[hidden], .refgroup[hidden] { display: none !important; }
911.refmain { min-width: 0; }
912.refname { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
913.refname a { color: var(--ink); text-decoration: none; font-weight: 650; }
914.refname code, .refname a code { font-family: var(--mono); font-size: 0.95rem; }
915.refcopy { min-height: 24px; width: 24px; padding: 0; }
916.refbadge { text-transform: lowercase; background: #eef1f4; color: #57606a; border-color: transparent; }
917.refbadge.def { background: var(--blue-soft); color: var(--blue-deep); }
918.refmeta {
919 margin: 0.28rem 0 0; color: var(--muted); font-size: var(--fs-sm);
920 display: flex; flex-wrap: wrap; gap: 0.35rem 0.55rem; align-items: center;
921}
922.refmeta a { color: inherit; }
923.refdot { color: var(--muted); }
924.refsubject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 36rem; }
925.refnote { margin: 0.35rem 0 0; white-space: pre-wrap; }
926.refacts { display: flex; align-items: center; gap: 0.35rem; flex: none; }
927.refacts .tiny {
928 min-height: 1.7rem; padding: 0 0.45rem; font-size: var(--fs-sm);
929 background: white; color: var(--ink); border: 1px solid var(--line);
930 border-radius: var(--radius); text-decoration: none; line-height: 1.2;
931}
932.refacts .rowmenu > summary { display: inline-flex; align-items: center; justify-content: center; min-width: 2rem; min-height: 2rem; }
933.refdlbtn::after {
934 content: ""; width: 0.32rem; height: 0.32rem; margin-left: 0.2rem;
935 border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
936 transform: translateY(-1px) rotate(45deg);
937}
938.menu-panel.refdl a { display: block; padding: 0.4rem 0.15rem; text-decoration: none; color: var(--ink); white-space: nowrap; }
939.menu-panel.refdl[popover]:popover-open { width: max-content; min-width: 8.5rem; max-width: 14rem; padding: 0.35rem 0.9rem; }
940.rowmenu .menu-panel a { display: block; padding: 0.35rem 0.2rem; text-decoration: none; color: var(--ink); }
941.refempty { margin: 0.4rem 0.2rem 0.6rem; }
942@media (max-width: 800px) {
943 .refrow { flex-direction: column; }
944 .refacts { flex-wrap: wrap; }
945 .refsubject { max-width: 100%; }
946}
877.mergewhy {
947.mergewhy {
878 border: 1px solid var(--line); border-radius: var(--radius);
948 border: 1px solid var(--line); border-radius: var(--radius);
879 padding: 0.7rem 0.9rem; margin: 0.6rem 0; background: #fff8f0;
949 padding: 0.7rem 0.9rem; margin: 0.6rem 0; background: #fff8f0;
internal/server/static/tags.js +10 −0
@@ -24,4 +24,14 @@
24 24 dialog.close();
25 25 });
26 26 }
27 var form = document.querySelector("[data-tag-form]");
28 document.querySelectorAll("[data-tag-create]").forEach(function (btn) {
29 btn.addEventListener("click", function () {
30 if (form && form.showModal) form.showModal();
31 });
32 });
33 if (form) {
34 var shut = form.querySelector("[data-tag-form-close]");
35 if (shut) shut.addEventListener("click", function () { form.close(); });
36 }
27 37 })();
@@ -24,4 +24,14 @@
24 dialog.close();
24 dialog.close();
25 });
25 });
26 }
26 }
27 var form = document.querySelector("[data-tag-form]");
28 document.querySelectorAll("[data-tag-create]").forEach(function (btn) {
29 btn.addEventListener("click", function () {
30 if (form && form.showModal) form.showModal();
31 });
32 });
33 if (form) {
34 var shut = form.querySelector("[data-tag-form-close]");
35 if (shut) shut.addEventListener("click", function () { form.close(); });
36 }
27})();
37})();
internal/server/tags.go +14 −7
@@ -9,6 +9,7 @@ import (
9 9 "gitlab.com/Timfa/bluegit/internal/access"
10 10 "gitlab.com/Timfa/bluegit/internal/gitrepo"
11 11 "gitlab.com/Timfa/bluegit/internal/i18n"
12 "gitlab.com/Timfa/bluegit/internal/store"
12 13 )
13 14
14 15 func (s *Server) tags(w http.ResponseWriter, r *http.Request) {
@@ -41,13 +42,15 @@ func (s *Server) tags(w http.ResponseWriter, r *http.Request) {
41 42 if len(short) > 10 {
42 43 short = short[:10]
43 44 }
44 when := ""
45 when, date := "", ""
45 46 if info.Unix > 0 {
46 when = i18n.FormatDate(lang, time.Unix(info.Unix, 0).UTC())
47 at := time.Unix(info.Unix, 0).UTC()
48 when = i18n.Ago(lang, info.Unix)
49 date = i18n.FormatDate(lang, at)
47 50 }
48 51 row := TagRow{
49 52 Name: info.Name, Message: info.Message, SHA: info.CommitSHA, Short: short,
50 Subject: info.CommitSubject, Date: when, Annotated: info.Annotated,
53 Subject: info.CommitSubject, Date: date, When: when, Annotated: info.Annotated,
51 54 Protected: protected, HasRelease: released[info.Name],
52 55 CanDelete: role.CanWriteCode() && (!protected || role.CanManageSettings()),
53 56 ZipURL: tagArchiveURL(repo, info.Name, "zip"),
@@ -98,16 +101,20 @@ func (s *Server) tagArchive(w http.ResponseWriter, r *http.Request) {
98 101 http.NotFound(w, r)
99 102 return
100 103 }
101 filename := archiveFilename(repo.Name, name, format)
104 s.writeArchive(w, r, repo, dir, name, name, format)
105 }
106
107 func (s *Server) writeArchive(w http.ResponseWriter, r *http.Request, repo store.Repo, dir, rev, label, format string) {
108 filename := archiveFilename(repo.Name, label, format)
102 109 if format == "zip" {
103 110 w.Header().Set("Content-Type", "application/zip")
104 111 } else {
105 112 w.Header().Set("Content-Type", "application/gzip")
106 113 }
107 114 w.Header().Set("Content-Disposition", "attachment; filename=\""+filename+"\"")
108 prefix := repo.Name + "-" + strings.ReplaceAll(name, "/", "-")
109 if err := gitrepo.Archive(r.Context(), w, s.Git, dir, prefix, name, format); err != nil && s.Log != nil {
110 s.Log.Error("tag archief", "err", err, "tag", name)
115 prefix := repo.Name + "-" + strings.ReplaceAll(label, "/", "-")
116 if err := gitrepo.ArchiveAt(r.Context(), w, s.Git, dir, prefix, rev, format); err != nil && s.Log != nil {
117 s.Log.Error("archief", "err", err, "rev", rev)
111 118 }
112 119 }
113 120
@@ -9,6 +9,7 @@ import (
9 "gitlab.com/Timfa/bluegit/internal/access"
9 "gitlab.com/Timfa/bluegit/internal/access"
10 "gitlab.com/Timfa/bluegit/internal/gitrepo"
10 "gitlab.com/Timfa/bluegit/internal/gitrepo"
11 "gitlab.com/Timfa/bluegit/internal/i18n"
11 "gitlab.com/Timfa/bluegit/internal/i18n"
12 "gitlab.com/Timfa/bluegit/internal/store"
12)
13)
13
14
14func (s *Server) tags(w http.ResponseWriter, r *http.Request) {
15func (s *Server) tags(w http.ResponseWriter, r *http.Request) {
@@ -41,13 +42,15 @@ func (s *Server) tags(w http.ResponseWriter, r *http.Request) {
41 if len(short) > 10 {
42 if len(short) > 10 {
42 short = short[:10]
43 short = short[:10]
43 }
44 }
44 when := ""
45 when, date := "", ""
45 if info.Unix > 0 {
46 if info.Unix > 0 {
46 when = i18n.FormatDate(lang, time.Unix(info.Unix, 0).UTC())
47 at := time.Unix(info.Unix, 0).UTC()
48 when = i18n.Ago(lang, info.Unix)
49 date = i18n.FormatDate(lang, at)
47 }
50 }
48 row := TagRow{
51 row := TagRow{
49 Name: info.Name, Message: info.Message, SHA: info.CommitSHA, Short: short,
52 Name: info.Name, Message: info.Message, SHA: info.CommitSHA, Short: short,
50 Subject: info.CommitSubject, Date: when, Annotated: info.Annotated,
53 Subject: info.CommitSubject, Date: date, When: when, Annotated: info.Annotated,
51 Protected: protected, HasRelease: released[info.Name],
54 Protected: protected, HasRelease: released[info.Name],
52 CanDelete: role.CanWriteCode() && (!protected || role.CanManageSettings()),
55 CanDelete: role.CanWriteCode() && (!protected || role.CanManageSettings()),
53 ZipURL: tagArchiveURL(repo, info.Name, "zip"),
56 ZipURL: tagArchiveURL(repo, info.Name, "zip"),
@@ -98,16 +101,20 @@ func (s *Server) tagArchive(w http.ResponseWriter, r *http.Request) {
98 http.NotFound(w, r)
101 http.NotFound(w, r)
99 return
102 return
100 }
103 }
101 filename := archiveFilename(repo.Name, name, format)
104 s.writeArchive(w, r, repo, dir, name, name, format)
105}
106
107func (s *Server) writeArchive(w http.ResponseWriter, r *http.Request, repo store.Repo, dir, rev, label, format string) {
108 filename := archiveFilename(repo.Name, label, format)
102 if format == "zip" {
109 if format == "zip" {
103 w.Header().Set("Content-Type", "application/zip")
110 w.Header().Set("Content-Type", "application/zip")
104 } else {
111 } else {
105 w.Header().Set("Content-Type", "application/gzip")
112 w.Header().Set("Content-Type", "application/gzip")
106 }
113 }
107 w.Header().Set("Content-Disposition", "attachment; filename=\""+filename+"\"")
114 w.Header().Set("Content-Disposition", "attachment; filename=\""+filename+"\"")
108 prefix := repo.Name + "-" + strings.ReplaceAll(name, "/", "-")
115 prefix := repo.Name + "-" + strings.ReplaceAll(label, "/", "-")
109 if err := gitrepo.Archive(r.Context(), w, s.Git, dir, prefix, name, format); err != nil && s.Log != nil {
116 if err := gitrepo.ArchiveAt(r.Context(), w, s.Git, dir, prefix, rev, format); err != nil && s.Log != nil {
110 s.Log.Error("tag archief", "err", err, "tag", name)
117 s.Log.Error("archief", "err", err, "rev", rev)
111 }
118 }
112}
119}
113
120
internal/server/tags_test.go +3 −3
@@ -97,7 +97,7 @@ func TestTagsPage(t *testing.T) {
97 97 }
98 98 page := read(t, res)
99 99 for _, want := range []string{
100 `class="on">Tags`, `Find a tag`, `Create tag`, `No tags yet.`, `value="master"`, `/assets/tags.js`, `data-tag-dialog`,
100 `class="on">Tags`, `Find a tag`, `New tag`, `No tags yet.`, `value="master"`, `/assets/tags.js`, `data-tag-dialog`,
101 101 } {
102 102 if !strings.Contains(page, want) {
103 103 t.Fatalf("tags mist %q\n%s", want, page)
@@ -318,7 +318,7 @@ func TestTagsPage(t *testing.T) {
318 318 t.Fatal(err)
319 319 }
320 320 roPage := read(t, res)
321 if strings.Contains(roPage, "Create tag") || strings.Contains(roPage, "data-tag-dialog") || strings.Contains(roPage, "data-tag-open") {
321 if strings.Contains(roPage, "New tag") || strings.Contains(roPage, "data-tag-dialog") || strings.Contains(roPage, "data-tag-open") {
322 322 t.Fatalf("alleen-lezen ziet het formulier:\n%s", roPage)
323 323 }
324 324 res, err = roClient.PostForm(ts.URL+"/tim/tags/-/tags", url.Values{"csrf": {csrfOf(t, roPage)}, "name": {"x"}, "target": {"master"}})
@@ -354,7 +354,7 @@ func TestTagsPage(t *testing.T) {
354 354 t.Fatal(err)
355 355 }
356 356 nl := read(t, res)
357 for _, want := range []string{"Tag aanmaken", "Zoek een tag", "Zonder bericht", "Verwijderen"} {
357 for _, want := range []string{"Nieuwe tag", "Zoek een tag", "Zonder bericht", "Verwijderen"} {
358 358 if !strings.Contains(nl, want) {
359 359 t.Fatalf("nederlands mist %q\n%s", want, nl)
360 360 }
@@ -97,7 +97,7 @@ func TestTagsPage(t *testing.T) {
97 }
97 }
98 page := read(t, res)
98 page := read(t, res)
99 for _, want := range []string{
99 for _, want := range []string{
100 `class="on">Tags`, `Find a tag`, `Create tag`, `No tags yet.`, `value="master"`, `/assets/tags.js`, `data-tag-dialog`,
100 `class="on">Tags`, `Find a tag`, `New tag`, `No tags yet.`, `value="master"`, `/assets/tags.js`, `data-tag-dialog`,
101 } {
101 } {
102 if !strings.Contains(page, want) {
102 if !strings.Contains(page, want) {
103 t.Fatalf("tags mist %q\n%s", want, page)
103 t.Fatalf("tags mist %q\n%s", want, page)
@@ -318,7 +318,7 @@ func TestTagsPage(t *testing.T) {
318 t.Fatal(err)
318 t.Fatal(err)
319 }
319 }
320 roPage := read(t, res)
320 roPage := read(t, res)
321 if strings.Contains(roPage, "Create tag") || strings.Contains(roPage, "data-tag-dialog") || strings.Contains(roPage, "data-tag-open") {
321 if strings.Contains(roPage, "New tag") || strings.Contains(roPage, "data-tag-dialog") || strings.Contains(roPage, "data-tag-open") {
322 t.Fatalf("alleen-lezen ziet het formulier:\n%s", roPage)
322 t.Fatalf("alleen-lezen ziet het formulier:\n%s", roPage)
323 }
323 }
324 res, err = roClient.PostForm(ts.URL+"/tim/tags/-/tags", url.Values{"csrf": {csrfOf(t, roPage)}, "name": {"x"}, "target": {"master"}})
324 res, err = roClient.PostForm(ts.URL+"/tim/tags/-/tags", url.Values{"csrf": {csrfOf(t, roPage)}, "name": {"x"}, "target": {"master"}})
@@ -354,7 +354,7 @@ func TestTagsPage(t *testing.T) {
354 t.Fatal(err)
354 t.Fatal(err)
355 }
355 }
356 nl := read(t, res)
356 nl := read(t, res)
357 for _, want := range []string{"Tag aanmaken", "Zoek een tag", "Zonder bericht", "Verwijderen"} {
357 for _, want := range []string{"Nieuwe tag", "Zoek een tag", "Zonder bericht", "Verwijderen"} {
358 if !strings.Contains(nl, want) {
358 if !strings.Contains(nl, want) {
359 t.Fatalf("nederlands mist %q\n%s", want, nl)
359 t.Fatalf("nederlands mist %q\n%s", want, nl)
360 }
360 }
internal/server/templates/branches.html +74 −65
@@ -1,71 +1,34 @@
1 1 {{define "branches"}}
2 2 {{template "layout-start" .}}
3 <header class="pagehead">
4 <h1>{{t "title.branches"}}</h1>
3 <div class="refhead">
4 <nav class="reftabs" aria-label="{{t "branch.actions"}}">
5 <a href="/{{.Repo.FullPath}}/-/branches?state=overview"{{if eq .Branch.State "overview"}} class="on" aria-current="page"{{end}}>{{t "branch.tab.overview"}}</a>
6 <a href="/{{.Repo.FullPath}}/-/branches?state=active"{{if eq .Branch.State "active"}} class="on" aria-current="page"{{end}}>{{t "branch.tab.active"}}</a>
7 <a href="/{{.Repo.FullPath}}/-/branches?state=stale"{{if eq .Branch.State "stale"}} class="on" aria-current="page"{{end}}>{{t "branch.tab.stale"}}</a>
8 <a href="/{{.Repo.FullPath}}/-/branches?state=all"{{if eq .Branch.State "all"}} class="on" aria-current="page"{{end}}>{{t "branch.tab.all"}}</a>
9 </nav>
5 10 {{if .CanWrite}}<button type="button" data-branch-open="create">{{t "branch.create"}}</button>{{end}}
6 </header>
7 <label class="branchsearch">{{t "branch.search"}}
8 <input type="search" data-branch-filter autocomplete="off" placeholder="{{t "branch.search"}}">
9 </label>
10 <div class="hscroll">
11 <table class="branchtable">
12 <thead>
13 <tr>
14 <th>{{t "branch.name"}}</th>
15 <th>{{t "branch.last"}}</th>
16 <th>{{t "branch.compare"}}</th>
17 <th>{{t "mr.pipeline"}}</th>
18 <th>{{t "mr.title"}}</th>
19 <th>{{t "branch.actions"}}</th>
20 </tr>
21 </thead>
22 <tbody>
23 {{range .Branches}}
24 <tr data-branch-row data-name="{{.Name}}">
25 <td>
26 <a href="/{{$.Repo.FullPath}}?rev={{urlquery .Name}}">{{.Name}}</a>
27 {{if .Default}}<span class="pill">{{t "branch.default"}}</span>{{end}}
28 {{if .Protected}}<span class="pill">{{t "vis.protected"}}</span>{{end}}
29 </td>
30 <td>
31 {{if .SHA}}<a href="/{{$.Repo.FullPath}}/-/commit/{{.SHA}}"><code>{{.Short}}</code></a> <span class="subject" title="{{.Subject}}">{{.Subject}}</span> <span class="muted when-short" title="{{.WhenTitle}}">{{.When}}</span>{{end}}
32 </td>
33 <td class="nums">
34 {{if and (eq .Ahead 0) (eq .Behind 0)}}<span class="muted">{{t "branch.even"}}</span>{{else}}
35 {{if .Ahead}}<span class="addstat">{{t "branch.ahead" .Ahead}}</span>{{end}}
36 {{if .Behind}}<span class="delstat">{{t "branch.behind" .Behind}}</span>{{end}}
37 {{end}}
38 </td>
39 <td>
40 {{if .PipeStatus}}<a class="status {{.PipeStatus}}" href="/{{$.Repo.FullPath}}/-/pipelines/{{.PipeID}}"><span class="mark"></span>{{.PipeLabel}}</a>{{end}}
41 </td>
42 <td class="mrlinks">
43 {{range .OpenMRs}}<a href="/{{$.Repo.FullPath}}/-/merge-requests/{{.}}">!{{.}}</a>{{end}}
44 </td>
45 <td class="branchacts">
46 <div class="branchline">
47 {{if not .Default}}
48 <a class="tiny" href="/{{$.Repo.FullPath}}/-/compare?from={{urlquery $.Repo.DefaultBranch}}&amp;to={{urlquery .Name}}">{{t "branch.compare"}}</a>
49 {{if not .OpenMRs}}<a class="tiny" href="/{{$.Repo.FullPath}}/-/merge-requests/new?source={{urlquery .Name}}&amp;target={{urlquery $.Repo.DefaultBranch}}">{{t "branch.mrShort"}}</a>{{end}}
50 {{end}}
51 {{if and $.CanWrite (not .Default) (not .Protected)}}
52 <details class="rowmenu tiny-menu">
53 <summary aria-label="{{t "branch.more"}}">⋯</summary>
54 <div class="menu-panel">
55 <button type="button" class="ghost" data-rename="{{.Name}}">{{t "branch.rename"}}</button>
56 <button type="button" class="ghost" data-delete="{{.Name}}">{{t "branch.delete"}}</button>
57 </div>
58 </details>
59 {{end}}
60 </div>
61 </td>
62 </tr>
63 {{else}}
64 <tr><td colspan="6" class="muted">{{t "repo.noBranches"}}</td></tr>
65 {{end}}
66 </tbody>
67 </table>
68 11 </div>
12 <label class="refsearch">
13 <input type="search" data-branch-filter autocomplete="off" placeholder="{{t "branch.filter"}}" aria-label="{{t "branch.filter"}}">
14 <svg class="ico" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M11.5 7a4.5 4.5 0 1 1-9 0 4.5 4.5 0 0 1 9 0zm-.9 4.3 3.4 3.4a.75.75 0 1 0 1.1-1.1l-3.4-3.4a6 6 0 1 0-1.1 1.1z"/></svg>
15 </label>
16 {{if and (not .Branch.Active) (not .Branch.Stale)}}
17 <p class="muted">{{t "repo.noBranches"}}</p>
18 {{else}}
19 {{if .Branch.ShowActive}}
20 <section class="refgroup" data-ref-group>
21 <h2>{{t "branch.group.active"}}</h2>
22 {{range .Branch.Active}}{{template "branchrow" .}}{{else}}<p class="muted refempty">{{t "branch.none.active"}}</p>{{end}}
23 </section>
24 {{end}}
25 {{if .Branch.ShowStale}}
26 <section class="refgroup" data-ref-group>
27 <h2>{{t "branch.group.stale"}}</h2>
28 {{range .Branch.Stale}}{{template "branchrow" .}}{{else}}<p class="muted refempty">{{t "branch.none.stale"}}</p>{{end}}
29 </section>
30 {{end}}
31 {{end}}
69 32 {{if .CanWrite}}
70 33 <dialog class="branch-dialog" data-branch-dialog="create">
71 34 <form method="post" action="/{{.Repo.FullPath}}/-/branches">
@@ -112,7 +75,53 @@
112 75 </div>
113 76 </form>
114 77 </dialog>
115 <script src="/assets/branch.js"></script>
116 78 {{end}}
79 <script src="/assets/branch.js"></script>
117 80 {{template "layout-end" .}}
118 81 {{end}}
82
83 {{define "branchrow"}}
84 <article class="refrow" data-branch-row data-name="{{.Name}}">
85 <div class="refmain">
86 <div class="refname">
87 <a href="/{{.RepoPath}}?rev={{urlquery .Name}}"><code>{{.Name}}</code></a>
88 <button type="button" class="iconbtn refcopy" data-copy="{{.Name}}" aria-label="{{t "action.copy"}}"><svg class="ico" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M5.5 1A1.5 1.5 0 0 0 4 2.5V10a1.5 1.5 0 0 0 1.5 1.5h6A1.5 1.5 0 0 0 13 10V2.5A1.5 1.5 0 0 0 11.5 1h-6zM2 5.5A1.5 1.5 0 0 1 3.5 4H4v6.5A2.5 2.5 0 0 0 6.5 13H11v.5A1.5 1.5 0 0 1 9.5 15h-6A1.5 1.5 0 0 1 2 13.5v-8z"/></svg></button>
89 {{if .Default}}<span class="pill refbadge def">{{t "branch.default"}}</span>{{end}}
90 {{if .Protected}}<span class="pill refbadge">{{t "vis.protected"}}</span>{{end}}
91 </div>
92 <p class="refmeta">
93 {{if .SHA}}<a href="/{{.RepoPath}}/-/commit/{{.SHA}}"><code>{{.Short}}</code></a>{{end}}
94 {{if .Subject}}{{if .SHA}}<span class="refdot" aria-hidden="true">·</span>{{end}}<span class="refsubject" title="{{.Subject}}">{{.Subject}}</span>{{end}}
95 {{if .When}}{{if or .SHA .Subject}}<span class="refdot" aria-hidden="true">·</span>{{end}}<span class="muted when-short" title="{{.WhenTitle}}">{{.When}}</span>{{end}}
96 {{if .PipeStatus}}<a class="status {{.PipeStatus}}" href="/{{.RepoPath}}/-/pipelines/{{.PipeID}}"><span class="mark"></span>{{.PipeLabel}}</a>{{end}}
97 </p>
98 </div>
99 <div class="refacts">
100 {{if not .Default}}
101 {{if and (eq .Ahead 0) (eq .Behind 0)}}<span class="muted">{{t "branch.even"}}</span>{{else}}
102 {{if .Ahead}}<span class="addstat">{{t "branch.ahead" .Ahead}}</span>{{end}}
103 {{if .Behind}}<span class="delstat">{{t "branch.behind" .Behind}}</span>{{end}}
104 {{end}}
105 {{range .OpenMRs}}<a class="tiny" href="/{{$.RepoPath}}/-/merge-requests/{{.}}">!{{.}}</a>{{else}}
106 <a class="tiny" href="/{{$.RepoPath}}/-/merge-requests/new?source={{urlquery $.Name}}&amp;target={{urlquery $.Target}}">{{t "branch.makeMR"}}</a>
107 {{end}}
108 {{end}}
109 <details class="rowmenu">
110 <summary class="refdlbtn" aria-label="{{t "branch.download"}}"><svg class="ico" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M7.25 2.25a.75.75 0 0 1 1.5 0v6.19l1.72-1.72a.75.75 0 1 1 1.06 1.06l-3 3a.75.75 0 0 1-1.06 0l-3-3a.75.75 0 1 1 1.06-1.06l1.72 1.72V2.25zM3.75 12.5a.75.75 0 0 0 0 1.5h8.5a.75.75 0 0 0 0-1.5h-8.5z"/></svg></summary>
111 <div class="menu-panel refdl">
112 <a href="{{.ZipURL}}">{{t "tag.zip"}}</a>
113 <a href="{{.TarURL}}">{{t "tag.tgz"}}</a>
114 </div>
115 </details>
116 {{if .CanEdit}}
117 <button type="button" class="ghost tiny" data-delete="{{.Name}}">{{t "branch.delete"}}</button>
118 <details class="rowmenu tiny-menu">
119 <summary aria-label="{{t "branch.more"}}">⋯</summary>
120 <div class="menu-panel">
121 <button type="button" class="ghost" data-rename="{{.Name}}">{{t "branch.rename"}}</button>
122 </div>
123 </details>
124 {{end}}
125 </div>
126 </article>
127 {{end}}
@@ -1,71 +1,34 @@
1{{define "branches"}}
1{{define "branches"}}
2{{template "layout-start" .}}
2{{template "layout-start" .}}
3<header class="pagehead">
3<div class="refhead">
4 <h1>{{t "title.branches"}}</h1>
4 <nav class="reftabs" aria-label="{{t "branch.actions"}}">
5 <a href="/{{.Repo.FullPath}}/-/branches?state=overview"{{if eq .Branch.State "overview"}} class="on" aria-current="page"{{end}}>{{t "branch.tab.overview"}}</a>
6 <a href="/{{.Repo.FullPath}}/-/branches?state=active"{{if eq .Branch.State "active"}} class="on" aria-current="page"{{end}}>{{t "branch.tab.active"}}</a>
7 <a href="/{{.Repo.FullPath}}/-/branches?state=stale"{{if eq .Branch.State "stale"}} class="on" aria-current="page"{{end}}>{{t "branch.tab.stale"}}</a>
8 <a href="/{{.Repo.FullPath}}/-/branches?state=all"{{if eq .Branch.State "all"}} class="on" aria-current="page"{{end}}>{{t "branch.tab.all"}}</a>
9 </nav>
5 {{if .CanWrite}}<button type="button" data-branch-open="create">{{t "branch.create"}}</button>{{end}}
10 {{if .CanWrite}}<button type="button" data-branch-open="create">{{t "branch.create"}}</button>{{end}}
6</header>
7<label class="branchsearch">{{t "branch.search"}}
8 <input type="search" data-branch-filter autocomplete="off" placeholder="{{t "branch.search"}}">
9</label>
10<div class="hscroll">
11<table class="branchtable">
12 <thead>
13 <tr>
14 <th>{{t "branch.name"}}</th>
15 <th>{{t "branch.last"}}</th>
16 <th>{{t "branch.compare"}}</th>
17 <th>{{t "mr.pipeline"}}</th>
18 <th>{{t "mr.title"}}</th>
19 <th>{{t "branch.actions"}}</th>
20 </tr>
21 </thead>
22 <tbody>
23 {{range .Branches}}
24 <tr data-branch-row data-name="{{.Name}}">
25 <td>
26 <a href="/{{$.Repo.FullPath}}?rev={{urlquery .Name}}">{{.Name}}</a>
27 {{if .Default}}<span class="pill">{{t "branch.default"}}</span>{{end}}
28 {{if .Protected}}<span class="pill">{{t "vis.protected"}}</span>{{end}}
29 </td>
30 <td>
31 {{if .SHA}}<a href="/{{$.Repo.FullPath}}/-/commit/{{.SHA}}"><code>{{.Short}}</code></a> <span class="subject" title="{{.Subject}}">{{.Subject}}</span> <span class="muted when-short" title="{{.WhenTitle}}">{{.When}}</span>{{end}}
32 </td>
33 <td class="nums">
34 {{if and (eq .Ahead 0) (eq .Behind 0)}}<span class="muted">{{t "branch.even"}}</span>{{else}}
35 {{if .Ahead}}<span class="addstat">{{t "branch.ahead" .Ahead}}</span>{{end}}
36 {{if .Behind}}<span class="delstat">{{t "branch.behind" .Behind}}</span>{{end}}
37 {{end}}
38 </td>
39 <td>
40 {{if .PipeStatus}}<a class="status {{.PipeStatus}}" href="/{{$.Repo.FullPath}}/-/pipelines/{{.PipeID}}"><span class="mark"></span>{{.PipeLabel}}</a>{{end}}
41 </td>
42 <td class="mrlinks">
43 {{range .OpenMRs}}<a href="/{{$.Repo.FullPath}}/-/merge-requests/{{.}}">!{{.}}</a>{{end}}
44 </td>
45 <td class="branchacts">
46 <div class="branchline">
47 {{if not .Default}}
48 <a class="tiny" href="/{{$.Repo.FullPath}}/-/compare?from={{urlquery $.Repo.DefaultBranch}}&amp;to={{urlquery .Name}}">{{t "branch.compare"}}</a>
49 {{if not .OpenMRs}}<a class="tiny" href="/{{$.Repo.FullPath}}/-/merge-requests/new?source={{urlquery .Name}}&amp;target={{urlquery $.Repo.DefaultBranch}}">{{t "branch.mrShort"}}</a>{{end}}
50 {{end}}
51 {{if and $.CanWrite (not .Default) (not .Protected)}}
52 <details class="rowmenu tiny-menu">
53 <summary aria-label="{{t "branch.more"}}">⋯</summary>
54 <div class="menu-panel">
55 <button type="button" class="ghost" data-rename="{{.Name}}">{{t "branch.rename"}}</button>
56 <button type="button" class="ghost" data-delete="{{.Name}}">{{t "branch.delete"}}</button>
57 </div>
58 </details>
59 {{end}}
60 </div>
61 </td>
62 </tr>
63 {{else}}
64 <tr><td colspan="6" class="muted">{{t "repo.noBranches"}}</td></tr>
65 {{end}}
66 </tbody>
67</table>
68</div>
11</div>
12<label class="refsearch">
13 <input type="search" data-branch-filter autocomplete="off" placeholder="{{t "branch.filter"}}" aria-label="{{t "branch.filter"}}">
14 <svg class="ico" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M11.5 7a4.5 4.5 0 1 1-9 0 4.5 4.5 0 0 1 9 0zm-.9 4.3 3.4 3.4a.75.75 0 1 0 1.1-1.1l-3.4-3.4a6 6 0 1 0-1.1 1.1z"/></svg>
15</label>
16{{if and (not .Branch.Active) (not .Branch.Stale)}}
17<p class="muted">{{t "repo.noBranches"}}</p>
18{{else}}
19 {{if .Branch.ShowActive}}
20 <section class="refgroup" data-ref-group>
21 <h2>{{t "branch.group.active"}}</h2>
22 {{range .Branch.Active}}{{template "branchrow" .}}{{else}}<p class="muted refempty">{{t "branch.none.active"}}</p>{{end}}
23 </section>
24 {{end}}
25 {{if .Branch.ShowStale}}
26 <section class="refgroup" data-ref-group>
27 <h2>{{t "branch.group.stale"}}</h2>
28 {{range .Branch.Stale}}{{template "branchrow" .}}{{else}}<p class="muted refempty">{{t "branch.none.stale"}}</p>{{end}}
29 </section>
30 {{end}}
31{{end}}
69{{if .CanWrite}}
32{{if .CanWrite}}
70<dialog class="branch-dialog" data-branch-dialog="create">
33<dialog class="branch-dialog" data-branch-dialog="create">
71 <form method="post" action="/{{.Repo.FullPath}}/-/branches">
34 <form method="post" action="/{{.Repo.FullPath}}/-/branches">
@@ -112,7 +75,53 @@
112 </div>
75 </div>
113 </form>
76 </form>
114</dialog>
77</dialog>
115<script src="/assets/branch.js"></script>
116{{end}}
78{{end}}
79<script src="/assets/branch.js"></script>
117{{template "layout-end" .}}
80{{template "layout-end" .}}
118{{end}}
81{{end}}
82
83{{define "branchrow"}}
84<article class="refrow" data-branch-row data-name="{{.Name}}">
85 <div class="refmain">
86 <div class="refname">
87 <a href="/{{.RepoPath}}?rev={{urlquery .Name}}"><code>{{.Name}}</code></a>
88 <button type="button" class="iconbtn refcopy" data-copy="{{.Name}}" aria-label="{{t "action.copy"}}"><svg class="ico" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M5.5 1A1.5 1.5 0 0 0 4 2.5V10a1.5 1.5 0 0 0 1.5 1.5h6A1.5 1.5 0 0 0 13 10V2.5A1.5 1.5 0 0 0 11.5 1h-6zM2 5.5A1.5 1.5 0 0 1 3.5 4H4v6.5A2.5 2.5 0 0 0 6.5 13H11v.5A1.5 1.5 0 0 1 9.5 15h-6A1.5 1.5 0 0 1 2 13.5v-8z"/></svg></button>
89 {{if .Default}}<span class="pill refbadge def">{{t "branch.default"}}</span>{{end}}
90 {{if .Protected}}<span class="pill refbadge">{{t "vis.protected"}}</span>{{end}}
91 </div>
92 <p class="refmeta">
93 {{if .SHA}}<a href="/{{.RepoPath}}/-/commit/{{.SHA}}"><code>{{.Short}}</code></a>{{end}}
94 {{if .Subject}}{{if .SHA}}<span class="refdot" aria-hidden="true">·</span>{{end}}<span class="refsubject" title="{{.Subject}}">{{.Subject}}</span>{{end}}
95 {{if .When}}{{if or .SHA .Subject}}<span class="refdot" aria-hidden="true">·</span>{{end}}<span class="muted when-short" title="{{.WhenTitle}}">{{.When}}</span>{{end}}
96 {{if .PipeStatus}}<a class="status {{.PipeStatus}}" href="/{{.RepoPath}}/-/pipelines/{{.PipeID}}"><span class="mark"></span>{{.PipeLabel}}</a>{{end}}
97 </p>
98 </div>
99 <div class="refacts">
100 {{if not .Default}}
101 {{if and (eq .Ahead 0) (eq .Behind 0)}}<span class="muted">{{t "branch.even"}}</span>{{else}}
102 {{if .Ahead}}<span class="addstat">{{t "branch.ahead" .Ahead}}</span>{{end}}
103 {{if .Behind}}<span class="delstat">{{t "branch.behind" .Behind}}</span>{{end}}
104 {{end}}
105 {{range .OpenMRs}}<a class="tiny" href="/{{$.RepoPath}}/-/merge-requests/{{.}}">!{{.}}</a>{{else}}
106 <a class="tiny" href="/{{$.RepoPath}}/-/merge-requests/new?source={{urlquery $.Name}}&amp;target={{urlquery $.Target}}">{{t "branch.makeMR"}}</a>
107 {{end}}
108 {{end}}
109 <details class="rowmenu">
110 <summary class="refdlbtn" aria-label="{{t "branch.download"}}"><svg class="ico" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M7.25 2.25a.75.75 0 0 1 1.5 0v6.19l1.72-1.72a.75.75 0 1 1 1.06 1.06l-3 3a.75.75 0 0 1-1.06 0l-3-3a.75.75 0 1 1 1.06-1.06l1.72 1.72V2.25zM3.75 12.5a.75.75 0 0 0 0 1.5h8.5a.75.75 0 0 0 0-1.5h-8.5z"/></svg></summary>
111 <div class="menu-panel refdl">
112 <a href="{{.ZipURL}}">{{t "tag.zip"}}</a>
113 <a href="{{.TarURL}}">{{t "tag.tgz"}}</a>
114 </div>
115 </details>
116 {{if .CanEdit}}
117 <button type="button" class="ghost tiny" data-delete="{{.Name}}">{{t "branch.delete"}}</button>
118 <details class="rowmenu tiny-menu">
119 <summary aria-label="{{t "branch.more"}}">⋯</summary>
120 <div class="menu-panel">
121 <button type="button" class="ghost" data-rename="{{.Name}}">{{t "branch.rename"}}</button>
122 </div>
123 </details>
124 {{end}}
125 </div>
126</article>
127{{end}}
internal/server/templates/pages.html +50 −43
@@ -509,54 +509,61 @@
509 509
510 510 {{define "tags"}}
511 511 {{template "layout-start" .}}
512 <header class="pagehead"><h1>{{t "title.tags"}}</h1></header>
513 <form class="bar" method="get" action="/{{.Repo.FullPath}}/-/tags">
512 <div class="refhead">
513 <h1>{{t "title.tags"}}</h1>
514 {{if .CanWrite}}<button type="button" data-tag-create>{{t "tag.create"}}</button>{{end}}
515 </div>
516 <form class="refsearch" method="get" action="/{{.Repo.FullPath}}/-/tags">
514 517 <input type="search" name="q" value="{{.Query}}" placeholder="{{t "tag.search"}}" aria-label="{{t "tag.search"}}">
518 <button class="refgo" type="submit" aria-label="{{t "tag.search"}}"><svg class="ico" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M11.5 7a4.5 4.5 0 1 1-9 0 4.5 4.5 0 0 1 9 0zm-.9 4.3 3.4 3.4a.75.75 0 1 0 1.1-1.1l-3.4-3.4a6 6 0 1 0-1.1 1.1z"/></svg></button>
515 519 </form>
516 {{if .CanWrite}}
517 <form class="panel" method="post" action="/{{.Repo.FullPath}}/-/tags">
518 <input type="hidden" name="csrf" value="{{.CSRF}}">
519 <div class="row">
520 <input name="name" placeholder="{{t "tag.name"}}" aria-label="{{t "tag.name"}}" required>
521 <input name="target" list="tag-targets" placeholder="{{t "tag.target"}}" aria-label="{{t "tag.target"}}" value="{{.Rev}}" required>
522 <input name="message" placeholder="{{t "tag.message"}}" aria-label="{{t "tag.message"}}">
523 <button type="submit">{{t "tag.create"}}</button>
524 </div>
525 </form>
526 <datalist id="tag-targets">{{range .Branches}}<option value="{{.Name}}"></option>{{end}}</datalist>
527 {{end}}
528 520 {{if .Tags}}
529 <div class="hscroll">
530 <table class="tags">
531 <thead>
532 <tr>
533 <th>{{t "tag.name"}}</th>
534 <th>{{t "tag.commit"}}</th>
535 <th>{{t "tag.date"}}</th>
536 <th>{{t "tag.message"}}</th>
537 <th></th>
538 </tr>
539 </thead>
540 <tbody>
541 {{range .Tags}}
542 <tr>
543 <td><code>{{.Name}}</code> {{if .Protected}}<span class="pill">{{t "vis.protected"}}</span>{{end}}</td>
544 <td>{{if .SHA}}<a href="/{{$.Repo.FullPath}}/-/commit/{{.SHA}}"><code>{{.Short}}</code> {{.Subject}}</a>{{end}}</td>
545 <td>{{.Date}}</td>
546 <td>{{if .Annotated}}<span class="pill">{{t "tag.annotated"}}</span> {{if .Message}}<span class="tagmsg">{{.Message}}</span>{{end}}{{else}}<span class="muted">{{t "tag.lightweight"}}</span>{{end}}</td>
547 <td class="acts">
548 {{if .HasRelease}}<a href="/{{$.Repo.FullPath}}/-/releases#{{.Name}}">{{t "tag.release"}}</a>{{end}}
549 <a href="{{.ZipURL}}">{{t "tag.zip"}}</a>
550 <a href="{{.TarURL}}">{{t "tag.tgz"}}</a>
551 {{if .CanDelete}}<button type="button" class="ghost" data-tag-open data-tag="{{.Name}}">{{t "tag.delete"}}</button>{{end}}
552 </td>
553 </tr>
554 {{end}}
555 </tbody>
556 </table>
557 </div>
521 <section class="refgroup">
522 {{range .Tags}}
523 <article class="refrow">
524 <div class="refmain">
525 <div class="refname">
526 <code>{{.Name}}</code>
527 <button type="button" class="iconbtn refcopy" data-copy="{{.Name}}" aria-label="{{t "action.copy"}}"><svg class="ico" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M5.5 1A1.5 1.5 0 0 0 4 2.5V10a1.5 1.5 0 0 0 1.5 1.5h6A1.5 1.5 0 0 0 13 10V2.5A1.5 1.5 0 0 0 11.5 1h-6zM2 5.5A1.5 1.5 0 0 1 3.5 4H4v6.5A2.5 2.5 0 0 0 6.5 13H11v.5A1.5 1.5 0 0 1 9.5 15h-6A1.5 1.5 0 0 1 2 13.5v-8z"/></svg></button>
528 {{if .Protected}}<span class="pill refbadge">{{t "vis.protected"}}</span>{{end}}
529 </div>
530 <p class="refmeta">
531 {{if .SHA}}<a href="/{{$.Repo.FullPath}}/-/commit/{{.SHA}}"><code>{{.Short}}</code></a>{{end}}
532 {{if .Subject}}{{if .SHA}}<span class="refdot" aria-hidden="true">·</span>{{end}}<span class="refsubject" title="{{.Subject}}">{{.Subject}}</span>{{end}}
533 {{if .When}}{{if or .SHA .Subject}}<span class="refdot" aria-hidden="true">·</span>{{end}}<span class="muted when-short" title="{{.Date}}">{{.When}}</span>{{end}}
534 </p>
535 {{if .Annotated}}<p class="refnote"><span class="pill">{{t "tag.annotated"}}</span> {{.Message}}</p>{{else}}<p class="muted refnote">{{t "tag.lightweight"}}</p>{{end}}
536 {{if .HasRelease}}<p class="refnote"><a href="/{{$.Repo.FullPath}}/-/releases#{{.Name}}">{{t "tag.release"}}</a></p>{{end}}
537 </div>
538 <div class="refacts">
539 <details class="rowmenu">
540 <summary class="refdlbtn" aria-label="{{t "branch.download"}}"><svg class="ico" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M7.25 2.25a.75.75 0 0 1 1.5 0v6.19l1.72-1.72a.75.75 0 1 1 1.06 1.06l-3 3a.75.75 0 0 1-1.06 0l-3-3a.75.75 0 1 1 1.06-1.06l1.72 1.72V2.25zM3.75 12.5a.75.75 0 0 0 0 1.5h8.5a.75.75 0 0 0 0-1.5h-8.5z"/></svg></summary>
541 <div class="menu-panel refdl">
542 <a href="{{.ZipURL}}">{{t "tag.zip"}}</a>
543 <a href="{{.TarURL}}">{{t "tag.tgz"}}</a>
544 </div>
545 </details>
546 {{if .CanDelete}}<button type="button" class="ghost tiny" data-tag-open data-tag="{{.Name}}">{{t "tag.delete"}}</button>{{end}}
547 </div>
548 </article>
549 {{end}}
550 </section>
558 551 {{else if .Query}}<p class="muted">{{t "tag.noMatch"}}</p>{{else}}<p class="muted">{{t "repo.noTags"}}</p>{{end}}
559 552 {{if .CanWrite}}
553 <dialog class="branch-dialog" data-tag-form>
554 <form method="post" action="/{{.Repo.FullPath}}/-/tags">
555 <h2>{{t "tag.create"}}</h2>
556 <input type="hidden" name="csrf" value="{{.CSRF}}">
557 <label>{{t "tag.name"}} <input name="name" required autocomplete="off"></label>
558 <label>{{t "tag.target"}} <input name="target" list="tag-targets" value="{{.Rev}}" required></label>
559 <datalist id="tag-targets">{{range .Branches}}<option value="{{.Name}}"></option>{{end}}</datalist>
560 <label>{{t "tag.message"}} <input name="message" autocomplete="off"></label>
561 <div class="row">
562 <button type="submit">{{t "tag.create"}}</button>
563 <button type="button" class="ghost" data-tag-form-close>{{t "action.cancel"}}</button>
564 </div>
565 </form>
566 </dialog>
560 567 <dialog class="danger-modal" data-tag-dialog>
561 568 <form method="post" action="/{{.Repo.FullPath}}/-/tags/delete">
562 569 <input type="hidden" name="csrf" value="{{.CSRF}}">
@@ -509,54 +509,61 @@
509
509
510{{define "tags"}}
510{{define "tags"}}
511{{template "layout-start" .}}
511{{template "layout-start" .}}
512<header class="pagehead"><h1>{{t "title.tags"}}</h1></header>
512<div class="refhead">
513<form class="bar" method="get" action="/{{.Repo.FullPath}}/-/tags">
513 <h1>{{t "title.tags"}}</h1>
514 {{if .CanWrite}}<button type="button" data-tag-create>{{t "tag.create"}}</button>{{end}}
515</div>
516<form class="refsearch" method="get" action="/{{.Repo.FullPath}}/-/tags">
514 <input type="search" name="q" value="{{.Query}}" placeholder="{{t "tag.search"}}" aria-label="{{t "tag.search"}}">
517 <input type="search" name="q" value="{{.Query}}" placeholder="{{t "tag.search"}}" aria-label="{{t "tag.search"}}">
518 <button class="refgo" type="submit" aria-label="{{t "tag.search"}}"><svg class="ico" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M11.5 7a4.5 4.5 0 1 1-9 0 4.5 4.5 0 0 1 9 0zm-.9 4.3 3.4 3.4a.75.75 0 1 0 1.1-1.1l-3.4-3.4a6 6 0 1 0-1.1 1.1z"/></svg></button>
515</form>
519</form>
516{{if .CanWrite}}
517<form class="panel" method="post" action="/{{.Repo.FullPath}}/-/tags">
518 <input type="hidden" name="csrf" value="{{.CSRF}}">
519 <div class="row">
520 <input name="name" placeholder="{{t "tag.name"}}" aria-label="{{t "tag.name"}}" required>
521 <input name="target" list="tag-targets" placeholder="{{t "tag.target"}}" aria-label="{{t "tag.target"}}" value="{{.Rev}}" required>
522 <input name="message" placeholder="{{t "tag.message"}}" aria-label="{{t "tag.message"}}">
523 <button type="submit">{{t "tag.create"}}</button>
524 </div>
525</form>
526<datalist id="tag-targets">{{range .Branches}}<option value="{{.Name}}"></option>{{end}}</datalist>
527{{end}}
528{{if .Tags}}
520{{if .Tags}}
529<div class="hscroll">
521<section class="refgroup">
530<table class="tags">
522 {{range .Tags}}
531 <thead>
523 <article class="refrow">
532 <tr>
524 <div class="refmain">
533 <th>{{t "tag.name"}}</th>
525 <div class="refname">
534 <th>{{t "tag.commit"}}</th>
526 <code>{{.Name}}</code>
535 <th>{{t "tag.date"}}</th>
527 <button type="button" class="iconbtn refcopy" data-copy="{{.Name}}" aria-label="{{t "action.copy"}}"><svg class="ico" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M5.5 1A1.5 1.5 0 0 0 4 2.5V10a1.5 1.5 0 0 0 1.5 1.5h6A1.5 1.5 0 0 0 13 10V2.5A1.5 1.5 0 0 0 11.5 1h-6zM2 5.5A1.5 1.5 0 0 1 3.5 4H4v6.5A2.5 2.5 0 0 0 6.5 13H11v.5A1.5 1.5 0 0 1 9.5 15h-6A1.5 1.5 0 0 1 2 13.5v-8z"/></svg></button>
536 <th>{{t "tag.message"}}</th>
528 {{if .Protected}}<span class="pill refbadge">{{t "vis.protected"}}</span>{{end}}
537 <th></th>
529 </div>
538 </tr>
530 <p class="refmeta">
539 </thead>
531 {{if .SHA}}<a href="/{{$.Repo.FullPath}}/-/commit/{{.SHA}}"><code>{{.Short}}</code></a>{{end}}
540 <tbody>
532 {{if .Subject}}{{if .SHA}}<span class="refdot" aria-hidden="true">·</span>{{end}}<span class="refsubject" title="{{.Subject}}">{{.Subject}}</span>{{end}}
541 {{range .Tags}}
533 {{if .When}}{{if or .SHA .Subject}}<span class="refdot" aria-hidden="true">·</span>{{end}}<span class="muted when-short" title="{{.Date}}">{{.When}}</span>{{end}}
542 <tr>
534 </p>
543 <td><code>{{.Name}}</code> {{if .Protected}}<span class="pill">{{t "vis.protected"}}</span>{{end}}</td>
535 {{if .Annotated}}<p class="refnote"><span class="pill">{{t "tag.annotated"}}</span> {{.Message}}</p>{{else}}<p class="muted refnote">{{t "tag.lightweight"}}</p>{{end}}
544 <td>{{if .SHA}}<a href="/{{$.Repo.FullPath}}/-/commit/{{.SHA}}"><code>{{.Short}}</code> {{.Subject}}</a>{{end}}</td>
536 {{if .HasRelease}}<p class="refnote"><a href="/{{$.Repo.FullPath}}/-/releases#{{.Name}}">{{t "tag.release"}}</a></p>{{end}}
545 <td>{{.Date}}</td>
537 </div>
546 <td>{{if .Annotated}}<span class="pill">{{t "tag.annotated"}}</span> {{if .Message}}<span class="tagmsg">{{.Message}}</span>{{end}}{{else}}<span class="muted">{{t "tag.lightweight"}}</span>{{end}}</td>
538 <div class="refacts">
547 <td class="acts">
539 <details class="rowmenu">
548 {{if .HasRelease}}<a href="/{{$.Repo.FullPath}}/-/releases#{{.Name}}">{{t "tag.release"}}</a>{{end}}
540 <summary class="refdlbtn" aria-label="{{t "branch.download"}}"><svg class="ico" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M7.25 2.25a.75.75 0 0 1 1.5 0v6.19l1.72-1.72a.75.75 0 1 1 1.06 1.06l-3 3a.75.75 0 0 1-1.06 0l-3-3a.75.75 0 1 1 1.06-1.06l1.72 1.72V2.25zM3.75 12.5a.75.75 0 0 0 0 1.5h8.5a.75.75 0 0 0 0-1.5h-8.5z"/></svg></summary>
549 <a href="{{.ZipURL}}">{{t "tag.zip"}}</a>
541 <div class="menu-panel refdl">
550 <a href="{{.TarURL}}">{{t "tag.tgz"}}</a>
542 <a href="{{.ZipURL}}">{{t "tag.zip"}}</a>
551 {{if .CanDelete}}<button type="button" class="ghost" data-tag-open data-tag="{{.Name}}">{{t "tag.delete"}}</button>{{end}}
543 <a href="{{.TarURL}}">{{t "tag.tgz"}}</a>
552 </td>
544 </div>
553 </tr>
545 </details>
554 {{end}}
546 {{if .CanDelete}}<button type="button" class="ghost tiny" data-tag-open data-tag="{{.Name}}">{{t "tag.delete"}}</button>{{end}}
555 </tbody>
547 </div>
556</table>
548 </article>
557</div>
549 {{end}}
550</section>
558{{else if .Query}}<p class="muted">{{t "tag.noMatch"}}</p>{{else}}<p class="muted">{{t "repo.noTags"}}</p>{{end}}
551{{else if .Query}}<p class="muted">{{t "tag.noMatch"}}</p>{{else}}<p class="muted">{{t "repo.noTags"}}</p>{{end}}
559{{if .CanWrite}}
552{{if .CanWrite}}
553<dialog class="branch-dialog" data-tag-form>
554 <form method="post" action="/{{.Repo.FullPath}}/-/tags">
555 <h2>{{t "tag.create"}}</h2>
556 <input type="hidden" name="csrf" value="{{.CSRF}}">
557 <label>{{t "tag.name"}} <input name="name" required autocomplete="off"></label>
558 <label>{{t "tag.target"}} <input name="target" list="tag-targets" value="{{.Rev}}" required></label>
559 <datalist id="tag-targets">{{range .Branches}}<option value="{{.Name}}"></option>{{end}}</datalist>
560 <label>{{t "tag.message"}} <input name="message" autocomplete="off"></label>
561 <div class="row">
562 <button type="submit">{{t "tag.create"}}</button>
563 <button type="button" class="ghost" data-tag-form-close>{{t "action.cancel"}}</button>
564 </div>
565 </form>
566</dialog>
560<dialog class="danger-modal" data-tag-dialog>
567<dialog class="danger-modal" data-tag-dialog>
561 <form method="post" action="/{{.Repo.FullPath}}/-/tags/delete">
568 <form method="post" action="/{{.Repo.FullPath}}/-/tags/delete">
562 <input type="hidden" name="csrf" value="{{.CSRF}}">
569 <input type="hidden" name="csrf" value="{{.CSRF}}">