BlueGit

timfa bluegit

Files

bluegit / internal / server / server.go

server.go

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