vole
Clone
Read only, no credentials:
https://rodent.software/git/vole.git
Write over SSH with a registered key:
git clone ssh://git@0.0.0.0:2222/vole.git
A free and open-source forge that lives in your Git repo.
refactor
c5902451905acdaa478f8476844ccd4a510d9ca9 · Keenan Nemetz · 16d ago · parent ec2aba4b
internal/web/web.go → server/web/web.go +19−38
| @@ -15,15 +15,15 @@ import ( | |||
| 15 | 15 | "time" | |
| 16 | 16 | "unicode/utf8" | |
| 17 | 17 | ||
| 18 | "github.com/rodent-software/vole/internal/acl" | ||
| 19 | "github.com/rodent-software/vole/internal/config" | ||
| 20 | "github.com/rodent-software/vole/internal/gitx" | ||
| 21 | "github.com/rodent-software/vole/internal/identity" | ||
| 22 | "github.com/rodent-software/vole/internal/index" | ||
| 23 | "github.com/rodent-software/vole/internal/lfs" | ||
| 24 | "github.com/rodent-software/vole/internal/locks" | ||
| 25 | "github.com/rodent-software/vole/internal/repo" | ||
| 26 | "github.com/rodent-software/vole/internal/runs" | ||
| 18 | "github.com/rodent-software/vole/ci/runs" | ||
| 19 | "github.com/rodent-software/vole/core/git" | ||
| 20 | "github.com/rodent-software/vole/core/lfs" | ||
| 21 | "github.com/rodent-software/vole/forge/access" | ||
| 22 | "github.com/rodent-software/vole/forge/config" | ||
| 23 | "github.com/rodent-software/vole/forge/identity" | ||
| 24 | "github.com/rodent-software/vole/forge/index" | ||
| 25 | "github.com/rodent-software/vole/forge/repo" | ||
| 26 | "github.com/rodent-software/vole/internal/format" | ||
| 27 | 27 | ) | |
| 28 | 28 | ||
| 29 | 29 | type Web struct { | |
| @@ -32,7 +32,7 @@ type Web struct { | |||
| 32 | 32 | Ident *identity.Store | |
| 33 | 33 | Runs *runs.Store | |
| 34 | 34 | LFS *lfs.Store | |
| 35 | Locks *locks.Store | ||
| 35 | Locks *lfs.LockStore | ||
| 36 | 36 | Cfg *config.Config | |
| 37 | 37 | Tmpl *template.Template | |
| 38 | 38 | Logger func(format string, args ...any) | |
| @@ -44,9 +44,9 @@ type Web struct { | |||
| 44 | 44 | func New(repos *repo.Store, ix *index.Store, ident *identity.Store, rs *runs.Store, cfg *config.Config) (*Web, error) { | |
| 45 | 45 | t, err := template.New("vole").Funcs(template.FuncMap{ | |
| 46 | 46 | "since": humanSince, | |
| 47 | "short": shortSHA, | ||
| 47 | "short": format.SHA, | ||
| 48 | 48 | "esc": url.PathEscape, | |
| 49 | "bytes": humanBytes, | ||
| 49 | "bytes": format.Bytes, | ||
| 50 | 50 | }).Parse(templates) | |
| 51 | 51 | if err != nil { | |
| 52 | 52 | return nil, err | |
| @@ -70,7 +70,7 @@ func (w *Web) public(m *repo.Meta) bool { | |||
| 70 | 70 | if err != nil { | |
| 71 | 71 | return false | |
| 72 | 72 | } | |
| 73 | return a.Can("", acl.Read) | ||
| 73 | return a.Can("", access.Read) | ||
| 74 | 74 | } | |
| 75 | 75 | ||
| 76 | 76 | func (w *Web) render(rw http.ResponseWriter, name string, data any, status int) { | |
| @@ -131,8 +131,8 @@ func (w *Web) Repo(rw http.ResponseWriter, r *http.Request) { | |||
| 131 | 131 | ref = m.DefaultBranch | |
| 132 | 132 | } | |
| 133 | 133 | commit, _ := g.RevParse(ref) | |
| 134 | var entries []gitx.Entry | ||
| 135 | var commits []gitx.Commit | ||
| 134 | var entries []git.Entry | ||
| 135 | var commits []git.Commit | ||
| 136 | 136 | count := 0 | |
| 137 | 137 | if commit != "" { | |
| 138 | 138 | entries, _ = g.LsTree(commit) | |
| @@ -194,8 +194,8 @@ func (w *Web) Repo(rw http.ResponseWriter, r *http.Request) { | |||
| 194 | 194 | Ref string | |
| 195 | 195 | CloneURL string | |
| 196 | 196 | SSHURL string | |
| 197 | Entries []gitx.Entry | ||
| 198 | Commits []gitx.Commit | ||
| 197 | Entries []git.Entry | ||
| 198 | Commits []git.Commit | ||
| 199 | 199 | Commit string | |
| 200 | 200 | Count int | |
| 201 | 201 | Branches []string | |
| @@ -256,7 +256,7 @@ func (w *Web) Tree(rw http.ResponseWriter, r *http.Request) { | |||
| 256 | 256 | Name string | |
| 257 | 257 | Ref string | |
| 258 | 258 | Path string | |
| 259 | Entries []gitx.Entry | ||
| 259 | Entries []git.Entry | ||
| 260 | 260 | Crumbs []crumb | |
| 261 | 261 | }{w.base(m.Name + " · " + ref), m.Name, ref, p, entries, crumbs(p)}, 0) | |
| 262 | 262 | } | |
| @@ -341,7 +341,7 @@ func (w *Web) Commits(rw http.ResponseWriter, r *http.Request) { | |||
| 341 | 341 | Page | |
| 342 | 342 | Name string | |
| 343 | 343 | Ref string | |
| 344 | Commits []gitx.Commit | ||
| 344 | Commits []git.Commit | ||
| 345 | 345 | }{w.base(m.Name + " · history"), m.Name, ref, commits}, 0) | |
| 346 | 346 | } | |
| 347 | 347 | ||
| @@ -407,25 +407,6 @@ func crumbs(p string) []crumb { | |||
| 407 | 407 | return out | |
| 408 | 408 | } | |
| 409 | 409 | ||
| 410 | func shortSHA(s string) string { | ||
| 411 | if len(s) > 8 { | ||
| 412 | return s[:8] | ||
| 413 | } | ||
| 414 | return s | ||
| 415 | } | ||
| 416 | |||
| 417 | // humanBytes renders a size for a table cell. A reader comparing two artifacts | ||
| 418 | // wants "1.4 MiB", not 1468006. | ||
| 419 | func humanBytes(n int64) string { | ||
| 420 | switch { | ||
| 421 | case n >= 1<<20: | ||
| 422 | return fmt.Sprintf("%.1f MiB", float64(n)/(1<<20)) | ||
| 423 | case n >= 1<<10: | ||
| 424 | return fmt.Sprintf("%.1f KiB", float64(n)/(1<<10)) | ||
| 425 | } | ||
| 426 | return fmt.Sprintf("%d B", n) | ||
| 427 | } | ||
| 428 | |||
| 429 | 410 | func humanSince(t int64) string { | |
| 430 | 411 | if t == 0 { | |
| 431 | 412 | return "" | |