BlueGit

timfa bluegit

Files

bluegit / internal / server / server.go

server.go

feat: breid branches en merge requests uit
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
Failed 7cb4d08b History
server.go 20.3 KiB Download Raw
1// Package server is de webinterface, de git-HTTP-server en de API.
2package server
3
4import (
5 "context"
6 "crypto/rand"
7 "embed"
8 "encoding/hex"
9 "html/template"
10 "io/fs"
11 "log/slog"
12 "net/http"
13 "net/url"
14 "strings"
15 "sync"
16 "time"
17 "unicode/utf8"
18
19 "gitlab.com/Timfa/bluegit/internal/access"
20 "gitlab.com/Timfa/bluegit/internal/activity"
21 "gitlab.com/Timfa/bluegit/internal/auth"
22 "gitlab.com/Timfa/bluegit/internal/cispec"
23 "gitlab.com/Timfa/bluegit/internal/config"
24 "gitlab.com/Timfa/bluegit/internal/i18n"
25 "gitlab.com/Timfa/bluegit/internal/realip"
26 "gitlab.com/Timfa/bluegit/internal/runner"
27 "gitlab.com/Timfa/bluegit/internal/store"
28)
29
30//go:embed templates/*.html static/*
31var webFS embed.FS
32
33// Server bedient BlueGit.
34type Server struct {
35 Cfg config.Config
36 Store *store.Store
37 Auth auth.Provider
38 Mail auth.Mailer
39 Dev bool
40 Git string
41 HookBin string
42 Runner *runner.Runner
43 Log *slog.Logger
44 // StateDir is de map met database en het bestand storage_path.
45 StateDir string
46 // AfterStorage krijgt het nieuwe datadisk-pad, voor runner en SSH.
47 AfterStorage func(path string)
48 tmpl *template.Template
49 byLang map[string]*template.Template
50
51 storageMu sync.RWMutex
52 storage string
53 storageSet bool
54}
55
56type principal struct {
57 User store.User
58 Session store.Session
59 OK bool
60}
61
62type ctxKey struct{}
63
64// Handler is de HTTP-handler met sessies en koppen.
65func (s *Server) Handler() http.Handler {
66 s.mustTemplates()
67 mux := http.NewServeMux()
68 mux.HandleFunc("GET /assets/{file}", s.asset)
69 mux.HandleFunc("GET /-/info", s.infoPage)
70 mux.HandleFunc("GET /api/v1/ci/spec", s.ciSpec)
71 mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) {
72 w.WriteHeader(http.StatusOK)
73 _, _ = w.Write([]byte("ok\n"))
74 })
75 mux.HandleFunc("GET /login", s.login)
76 mux.HandleFunc("GET /auth/callback", s.callback)
77 mux.HandleFunc("POST /logout", s.logout)
78 mux.HandleFunc("GET /{$}", s.home)
79 mux.HandleFunc("GET /new", s.newPage)
80 mux.HandleFunc("GET /new/slug", s.slugPreview)
81 mux.HandleFunc("POST /new/repo", s.createRepo)
82 mux.HandleFunc("POST /new/group", s.createGroup)
83 mux.HandleFunc("GET /setup", s.setupPage)
84 mux.HandleFunc("POST /setup", s.setupSave)
85 mux.HandleFunc("GET /settings", s.account)
86 mux.HandleFunc("POST /settings/language", s.saveLanguage)
87 mux.HandleFunc("POST /settings/tokens", s.createToken)
88 mux.HandleFunc("POST /settings/tokens/delete", s.deleteToken)
89 mux.HandleFunc("POST /settings/ssh", s.addSSH)
90 mux.HandleFunc("POST /settings/ssh/delete", s.deleteSSH)
91 mux.HandleFunc("GET /settings/export", s.export)
92 mux.HandleFunc("GET /users/{username}", s.profile)
93 mux.HandleFunc("GET /groups/{path}", s.groupPage)
94 mux.HandleFunc("GET /groups/{path}/logo", s.groupLogo)
95 mux.HandleFunc("POST /groups/{path}/settings", s.saveGroup)
96 mux.HandleFunc("POST /groups/{path}/approvals", s.saveGroupApproval)
97 mux.HandleFunc("POST /groups/{path}/owner", s.transferGroup)
98 mux.HandleFunc("POST /groups/{path}/logo", s.uploadGroupLogo)
99 mux.HandleFunc("POST /groups/{path}/members", s.groupMember)
100 mux.HandleFunc("POST /groups/{path}/members/remove", s.groupMemberRemove)
101 mux.HandleFunc("POST /groups/{path}/secrets", s.groupSecret)
102 mux.HandleFunc("POST /groups/{path}/secrets/delete", s.groupSecretDelete)
103 mux.HandleFunc("POST /groups/{path}/webhooks", s.groupWebhook)
104 mux.HandleFunc("POST /groups/{path}/webhooks/delete", s.groupWebhookDelete)
105
106 mux.HandleFunc("GET /{owner}/{repo}/info/refs", s.gitHTTP)
107 mux.HandleFunc("POST /{owner}/{repo}/git-upload-pack", s.gitHTTP)
108 mux.HandleFunc("POST /{owner}/{repo}/git-receive-pack", s.gitHTTP)
109 mux.HandleFunc("POST /api/v1/repos/{owner}/{repo}/releases", s.createRelease)
110
111 mux.HandleFunc("GET /{owner}/{repo}", s.repoHome)
112 mux.HandleFunc("GET /{owner}/{repo}/-/tree", s.treeRoot)
113 mux.HandleFunc("GET /{owner}/{repo}/-/tree/{path...}", s.tree)
114 mux.HandleFunc("GET /{owner}/{repo}/-/blob/{path...}", s.blob)
115 mux.HandleFunc("GET /{owner}/{repo}/-/commits", s.commits)
116 mux.HandleFunc("GET /{owner}/{repo}/-/tags", s.tags)
117 mux.HandleFunc("POST /{owner}/{repo}/-/tags", s.createTag)
118 mux.HandleFunc("POST /{owner}/{repo}/-/tags/delete", s.deleteTag)
119 mux.HandleFunc("GET /{owner}/{repo}/-/tags/archive", s.tagArchive)
120 mux.HandleFunc("GET /{owner}/{repo}/-/commit/{sha}", s.commit)
121 mux.HandleFunc("GET /{owner}/{repo}/-/branches", s.branches)
122 mux.HandleFunc("POST /{owner}/{repo}/-/branches", s.createBranch)
123 mux.HandleFunc("POST /{owner}/{repo}/-/branches/delete", s.deleteBranch)
124 mux.HandleFunc("POST /{owner}/{repo}/-/branches/rename", s.renameBranch)
125 mux.HandleFunc("GET /{owner}/{repo}/-/compare", s.compare)
126 mux.HandleFunc("POST /{owner}/{repo}/-/markdown", s.previewMarkdown)
127 mux.HandleFunc("GET /{owner}/{repo}/-/merge-requests", s.mergeRequests)
128 mux.HandleFunc("GET /{owner}/{repo}/-/merge-requests/new", s.newMR)
129 mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests", s.createMR)
130 mux.HandleFunc("GET /{owner}/{repo}/-/merge-requests/{number}", s.showMR)
131 mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}", s.updateMR)
132 mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}/merge", s.mergeMR)
133 mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}/close", s.closeMR)
134 mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}/reopen", s.reopenMR)
135 mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}/reviews", s.postReview)
136 mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}/reviews/dismiss", s.dismissReview)
137 mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}/notes", s.createNote)
138 mux.HandleFunc("POST /{owner}/{repo}/-/merge-requests/{number}/suggestions", s.applySuggestions)
139 mux.HandleFunc("GET /{owner}/{repo}/-/pipelines", s.pipelines)
140 mux.HandleFunc("POST /{owner}/{repo}/-/pipelines", s.runPipeline)
141 mux.HandleFunc("GET /{owner}/{repo}/-/pipelines/{id}", s.pipeline)
142 mux.HandleFunc("GET /{owner}/{repo}/-/pipelines/{id}/jobs/{job}", s.showJob)
143 mux.HandleFunc("GET /{owner}/{repo}/-/pipelines/{id}/jobs/{job}/log", s.jobLog)
144 mux.HandleFunc("POST /{owner}/{repo}/-/pipelines/{id}/jobs/{job}/play", s.playJob)
145 mux.HandleFunc("GET /{owner}/{repo}/-/ci/editor", s.ciEditor)
146 mux.HandleFunc("POST /{owner}/{repo}/-/ci/editor", s.saveCIEditor)
147 mux.HandleFunc("POST /{owner}/{repo}/-/ci/lint", s.lintCI)
148 mux.HandleFunc("GET /{owner}/{repo}/-/releases", s.releases)
149 mux.HandleFunc("GET /{owner}/{repo}/-/releases/{tag}/assets/{name}", s.releaseAsset)
150 mux.HandleFunc("GET /{owner}/{repo}/-/logo", s.repoLogo)
151 mux.HandleFunc("POST /{owner}/{repo}/-/logo", s.uploadRepoLogo)
152 mux.HandleFunc("POST /{owner}/{repo}/-/star", s.toggleStar)
153 mux.HandleFunc("GET /{owner}/{repo}/-/settings", s.settings)
154 mux.HandleFunc("POST /{owner}/{repo}/-/settings", s.updateRepo)
155 mux.HandleFunc("POST /{owner}/{repo}/-/approvals", s.saveRepoApproval)
156 mux.HandleFunc("POST /{owner}/{repo}/-/members", s.repoMember)
157 mux.HandleFunc("POST /{owner}/{repo}/-/members/remove", s.repoMemberRemove)
158 mux.HandleFunc("POST /{owner}/{repo}/-/protected", s.addProtected)
159 mux.HandleFunc("POST /{owner}/{repo}/-/protected/remove", s.removeProtected)
160 mux.HandleFunc("POST /{owner}/{repo}/-/protected-tags", s.addProtectedTag)
161 mux.HandleFunc("POST /{owner}/{repo}/-/protected-tags/remove", s.removeProtectedTag)
162 mux.HandleFunc("POST /{owner}/{repo}/-/secrets", s.repoSecret)
163 mux.HandleFunc("POST /{owner}/{repo}/-/secrets/delete", s.repoSecretDelete)
164 mux.HandleFunc("POST /{owner}/{repo}/-/webhooks", s.repoWebhook)
165 mux.HandleFunc("POST /{owner}/{repo}/-/webhooks/delete", s.repoWebhookDelete)
166 mux.HandleFunc("POST /{owner}/{repo}/-/delete", s.deleteRepo)
167
168 return s.realIP(s.withSession(s.secure(s.gate(mux))))
169}
170
171func (s *Server) realIP(next http.Handler) http.Handler {
172 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
173 realip.Apply(r, s.Cfg.ProxySet())
174 next.ServeHTTP(w, r)
175 })
176}
177
178func (s *Server) mustTemplates() {
179 if s.byLang != nil {
180 return
181 }
182 s.byLang = map[string]*template.Template{}
183 for _, lang := range i18n.All() {
184 l := lang
185 s.byLang[string(l)] = template.Must(template.New("web").Funcs(template.FuncMap{
186 "short": func(v string) string {
187 if len(v) > 10 {
188 return v[:10]
189 }
190 return v
191 },
192 "join": strings.Join,
193 "initial": func(s string) string {
194 s = strings.TrimSpace(s)
195 if s == "" {
196 return "?"
197 }
198 r, _ := utf8.DecodeRuneInString(s)
199 return strings.ToUpper(string(r))
200 },
201 "splitPath": func(p string) []string {
202 if p == "" {
203 return nil
204 }
205 return strings.Split(p, "/")
206 },
207 "iconOf": func(name string) string { return fileIcon(name, "blob") },
208 "t": func(key string, args ...any) string { return i18n.T(l, key, args...) },
209 "tn": func(n int, one, many string) string {
210 key := many
211 if n == 1 {
212 key = one
213 }
214 return i18n.T(l, key, n)
215 },
216 "roleName": func(r access.Role) string { return i18n.T(l, "role."+string(r)) },
217 "visName": func(v string) string { return i18n.T(l, "vis."+v) },
218 "presetName": func(id string) string {
219 label := i18n.T(l, "set.preset."+id)
220 if label == "set.preset."+id {
221 return id
222 }
223 return label
224 },
225 }).ParseFS(webFS, "templates/*.html"))
226 }
227 s.tmpl = s.byLang[string(i18n.EN)]
228}
229
230func (s *Server) asset(w http.ResponseWriter, r *http.Request) {
231 name := r.PathValue("file")
232 if name == "" || strings.Contains(name, "/") || strings.Contains(name, "..") {
233 http.NotFound(w, r)
234 return
235 }
236 sub, err := fs.Sub(webFS, "static")
237 if err != nil {
238 http.Error(w, "assets", http.StatusInternalServerError)
239 return
240 }
241 http.ServeFileFS(w, r, sub, name)
242}
243
244func (s *Server) secure(next http.Handler) http.Handler {
245 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
246 w.Header().Set("X-Content-Type-Options", "nosniff")
247 w.Header().Set("X-Frame-Options", "DENY")
248 w.Header().Set("Referrer-Policy", "strict-origin-when-cross-origin")
249 w.Header().Set("Content-Security-Policy", "default-src 'self'; img-src 'self' https://auth.timfalken.com data:; style-src 'self'; form-action 'self'; base-uri 'self'; frame-ancestors 'none'")
250 next.ServeHTTP(w, r)
251 })
252}
253
254func (s *Server) withSession(next http.Handler) http.Handler {
255 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
256 p := principal{}
257 if c, err := r.Cookie("bluegit_session"); err == nil && c.Value != "" {
258 sess, err := s.Store.Session(r.Context(), c.Value)
259 if err == nil && sess.ExpiresAt.After(time.Now()) {
260 p.Session = sess
261 p.User = sess.User
262 p.OK = true
263 s.maybeExtend(r.Context(), sess)
264 }
265 }
266 next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), ctxKey{}, p)))
267 })
268}
269
270func (s *Server) maybeExtend(ctx context.Context, sess store.Session) {
271 if time.Until(sess.ExpiresAt) > 6*time.Hour {
272 return
273 }
274 sec, err := s.Auth.Extend(ctx, sess.AccessToken)
275 if err != nil || sec <= 0 {
276 return
277 }
278 _ = s.Store.UpdateSessionExpiry(ctx, sess.ID, time.Now().Add(time.Duration(sec)*time.Second))
279}
280
281func (s *Server) who(r *http.Request) principal {
282 p, _ := r.Context().Value(ctxKey{}).(principal)
283 return p
284}
285
286func (s *Server) csrfOK(w http.ResponseWriter, r *http.Request) bool {
287 if err := r.ParseForm(); err != nil {
288 http.Error(w, s.tr(r, "err.badForm"), http.StatusBadRequest)
289 return false
290 }
291 p := s.who(r)
292 if !p.OK || r.FormValue("csrf") == "" || r.FormValue("csrf") != p.Session.CSRF {
293 http.Error(w, s.tr(r, "err.badCSRF"), http.StatusBadRequest)
294 return false
295 }
296 return true
297}
298
299func (s *Server) loginRequired(w http.ResponseWriter, r *http.Request) (store.User, bool) {
300 p := s.who(r)
301 if !p.OK {
302 http.Redirect(w, r, "/login", http.StatusFound)
303 return store.User{}, false
304 }
305 return p.User, true
306}
307
308func (s *Server) setSessionCookie(w http.ResponseWriter, id string, exp time.Time) {
309 http.SetCookie(w, &http.Cookie{
310 Name: "bluegit_session",
311 Value: id,
312 Path: "/",
313 HttpOnly: true,
314 SameSite: http.SameSiteLaxMode,
315 Secure: strings.HasPrefix(s.Cfg.BaseURL, "https://"),
316 Expires: exp,
317 })
318}
319
320func (s *Server) flash(w http.ResponseWriter, notice, problem string) {
321 secure := strings.HasPrefix(s.Cfg.BaseURL, "https://")
322 if notice != "" {
323 http.SetCookie(w, &http.Cookie{Name: "bluegit_notice", Value: url.QueryEscape(notice), Path: "/", MaxAge: 120, HttpOnly: true, Secure: secure, SameSite: http.SameSiteLaxMode})
324 }
325 if problem != "" {
326 http.SetCookie(w, &http.Cookie{Name: "bluegit_error", Value: url.QueryEscape(problem), Path: "/", MaxAge: 120, HttpOnly: true, Secure: secure, SameSite: http.SameSiteLaxMode})
327 }
328}
329
330func (s *Server) takeFlash(w http.ResponseWriter, r *http.Request) (string, string) {
331 notice, problem := flashVal(r, "bluegit_notice"), flashVal(r, "bluegit_error")
332 if notice != "" {
333 http.SetCookie(w, &http.Cookie{Name: "bluegit_notice", Value: "", Path: "/", MaxAge: -1})
334 }
335 if problem != "" {
336 http.SetCookie(w, &http.Cookie{Name: "bluegit_error", Value: "", Path: "/", MaxAge: -1})
337 }
338 return notice, problem
339}
340
341func cookieVal(r *http.Request, name string) string {
342 c, err := r.Cookie(name)
343 if err != nil {
344 return ""
345 }
346 return c.Value
347}
348
349func flashVal(r *http.Request, name string) string {
350 raw := cookieVal(r, name)
351 if raw == "" {
352 return ""
353 }
354 v, err := url.QueryUnescape(raw)
355 if err != nil {
356 return raw
357 }
358 return v
359}
360
361func (s *Server) redirect(w http.ResponseWriter, r *http.Request, path, notice, problem string) {
362 s.flash(w, notice, problem)
363 http.Redirect(w, r, path, http.StatusSeeOther)
364}
365
366func (s *Server) langOf(r *http.Request) i18n.Lang {
367 if p := s.who(r); p.OK {
368 return i18n.Parse(p.User.Language)
369 }
370 return i18n.EN
371}
372
373func (s *Server) tr(r *http.Request, key string, args ...any) string {
374 return i18n.T(s.langOf(r), key, args...)
375}
376
377func (s *Server) trErr(r *http.Request, err error) string {
378 return i18n.Text(s.langOf(r), err)
379}
380
381func (s *Server) view(w http.ResponseWriter, r *http.Request, title string) View {
382 notice, problem := s.takeFlash(w, r)
383 lang := s.langOf(r)
384 if strings.HasPrefix(title, "title.") {
385 title = i18n.T(lang, title)
386 }
387 name := strings.TrimSpace(s.Cfg.Runner.Name)
388 if name == "" {
389 name = "Steve"
390 }
391 v := View{
392 Title: title, BaseURL: s.Cfg.BaseURL, RunnerName: name, Notice: notice, Err: problem,
393 StorageUnset: s.StoragePath() == "", Lang: string(lang), HTMLLang: htmlLang(lang),
394 Cunei: lang == i18n.Cuneiform,
395 }
396 for _, l := range i18n.All() {
397 v.Langs = append(v.Langs, LangChoice{Code: string(l), Label: l.Name()})
398 }
399 if p := s.who(r); p.OK {
400 u := p.User
401 v.User = &u
402 v.CSRF = p.Session.CSRF
403 }
404 return v
405}
406
407func htmlLang(l i18n.Lang) string {
408 switch l {
409 case i18n.NL:
410 return "nl"
411 case i18n.DE:
412 return "de"
413 case i18n.FR:
414 return "fr"
415 default:
416 return "en"
417 }
418}
419
420func (s *Server) render(w http.ResponseWriter, name string, v View) {
421 w.Header().Set("Content-Type", "text/html; charset=utf-8")
422 tmpl := s.byLang[v.Lang]
423 if tmpl == nil {
424 tmpl = s.tmpl
425 }
426 if err := tmpl.ExecuteTemplate(w, name, v); err != nil && s.Log != nil {
427 s.Log.Error("sjabloon", "name", name, "err", err)
428 }
429}
430
431func randomState() (string, error) {
432 b := make([]byte, 32)
433 if _, err := rand.Read(b); err != nil {
434 return "", err
435 }
436 return hex.EncodeToString(b), nil
437}
438
439// View is de gegevensset voor elk scherm.
440type View struct {
441 Title string
442 BaseURL string
443 RunnerName string
444 User *store.User
445 CSRF string
446 Notice string
447 Err string
448 Repos []store.Repo
449 Groups []store.Group
450 Repo *store.Repo
451 Role access.Role
452 CanWrite bool
453 CanAdmin bool
454 CanMerge bool
455 CanComment bool
456 CanApply bool
457 Commits []CommitRow
458 Commit *CommitRow
459 CommitDiff *CommitDiff
460 Entries []EntryRow
461 TreePath string
462 Blob string
463 BlobPath string
464 Binary bool
465 Branches []BranchRow
466 MRs []store.MergeRequest
467 MR *store.MergeRequest
468 MRPipe *PipeRow
469 MergeBlocks []string
470 Approval *ApprovalView
471 Reviews []ReviewRow
472 CanReview bool
473 CanApprove bool
474 CanDismiss bool
475 CanClose bool
476 CanReopen bool
477 IsOwner bool
478 Candidates []store.Member
479 Diff string
480 DiffFiles []DiffFileView
481 Pipes []store.Pipeline
482 PipeRows []PipeRow
483 Pipe *store.Pipeline
484 PipeStatus string
485 PipeLabel string
486 PipeJobs []JobLink
487 Live bool
488 LiveURL string
489 Jobs []store.Job
490 JobPage *JobPage
491 Editor *CIEditor
492 Releases []store.Release
493 Members []store.Member
494 Secrets []store.SecretMeta
495 Hooks []HookView
496 Patterns []string
497 TagPatterns []string
498 Tags []TagRow
499 Tokens []store.TokenInfo
500 Keys []store.SSHKey
501 CloneHTTP string
502 CloneSSH string
503 Group *store.Group
504 Tab string
505 Rev string
506 NewToken string
507 StorageUnset bool
508 StoragePath string
509 StorageFree string
510 StorageTotal string
511 MinFree string
512 Wide bool
513 Info bool
514 Spec cispec.Doc
515 SpecJSON template.JS
516 Page string
517 Lang string
518 HTMLLang string
519 Cunei bool
520 Langs []LangChoice
521 Query string
522 SortDir string
523 FlipDir string
524 Cards []RepoCard
525 Head *CommitRow
526 Files []FileRow
527 Tree []FileRow
528 Readme template.HTML
529 ReadmeName string
530 LicensePath string
531 NCommits int
532 NBranches int
533 NTags int
534 NReleases int
535 Created string
536 Lines []CodeLine
537 BlobSize string
538 FileName string
539 RevProtected bool
540 Heat *activity.Calendar
541 Notes []NoteRow
542 Profile *store.User
543 DescHTML template.HTML
544 Timeline []TimelineItem
545 CompareFrom string
546 CompareTo string
547 FormTitle string
548 Labels []string
549 CanEditMR bool
550}
551
552// LangChoice is één taal in de instellingen.
553type LangChoice struct {
554 Code, Label string
555}
556
557// RepoCard is een repository in een groepslijst.
558type RepoCard struct {
559 Repo store.Repo
560 Stars int
561 Starred bool
562 When string
563}
564
565// NoteRow is een reactie in de interface.
566type NoteRow struct {
567 ID int64
568 Author, Body, When, Path string
569 Start, End int
570 HasSuggestion bool
571 ParentID int64
572 HTML template.HTML
573 Replies []NoteRow
574 At time.Time
575}
576
577// DiffFileView is één bestand in de merge-request-diff.
578type DiffFileView struct {
579 Path string
580 Lines []DiffLineView
581}
582
583// DiffLineView is één diffregel, met de reacties die op het nieuwe regelnummer eindigen.
584type DiffLineView struct {
585 Kind string
586 Text string
587 Old int
588 New int
589 Notes []NoteRow
590}
591
592// TagRow is één tag op de tagspagina.
593type TagRow struct {
594 Name, Message, SHA, Short, Subject, Date string
595 Annotated, Protected, HasRelease, CanDelete bool
596 ZipURL, TarURL string
597}
598
599// FileRow is een rij in de bestandstabel of de boom.
600type FileRow struct {
601 Name, Path, Icon, Subject, When, SHA string
602 Dir bool
603 Depth int
604 Active bool
605}
606
607// CodeLine is één regel broncode.
608type CodeLine struct {
609 N int
610 HTML template.HTML
611}
612
613// CommitRow is een commit in de interface.
614// Author is de gekoppelde gebruiker, of anders de ruwe git-naam.
615// RawName en PushedBy zijn gezet als de pusher de fallback is en de git-naam afwijkt.
616type CommitRow struct {
617 SHA, Short, Author, Date, Subject, Body, When string
618 UserURL, Avatar, Initial, RawName, PushedBy string
619 PipeID int64
620 PipeStatus, PipeLabel string
621}
622
623// EntryRow is een bestand of map.
624type EntryRow struct {
625 Name, Type, Path string
626}
627
628// BranchRow is een branch, met of zonder bescherming.
629type BranchRow struct {
630 Name, SHA, Short, Subject, When string
631 Protected, Default bool
632 Ahead, Behind int
633 PipeID int64
634 PipeStatus, PipeLabel string
635 MRNumber int64
636}
637
638// TimelineItem is één gebeurtenis of reactie op een merge request.
639type TimelineItem struct {
640 ID int64
641 Kind string
642 Actor, Text string
643 When string
644 Body string
645 HTML template.HTML
646 URL string
647 Replies []TimelineItem
648 At time.Time
649 Rank int
650}
651
652// HookView is een webhook plus de laatste pogingen.
653type HookView struct {
654 ID int64
655 Name string
656 Preset string
657 URL string
658 Method string
659 Filter string
660 Events string
661 Deliveries []store.Delivery
662}
663
664func repoURL(repo store.Repo) string { return "/" + repo.FullPath() }