BlueGit

timfa bluegit

Files

bluegit / internal / server / server.go

server.go

fix: compacte token- en SSH-knoppen op /settings
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
25146e27 History
server.go 20.7 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 "date": func(t time.Time) string { return i18n.FormatDate(l, t) },
215 "tn": func(n int, one, many string) string {
216 key := many
217 if n == 1 {
218 key = one
219 }
220 return i18n.T(l, key, n)
221 },
222 "roleName": func(r access.Role) string { return i18n.T(l, "role."+string(r)) },
223 "visName": func(v string) string { return i18n.T(l, "vis."+v) },
224 "presetName": func(id string) string {
225 label := i18n.T(l, "set.preset."+id)
226 if label == "set.preset."+id {
227 return id
228 }
229 return label
230 },
231 }).ParseFS(webFS, "templates/*.html"))
232 }
233 s.tmpl = s.byLang[string(i18n.EN)]
234}
235
236func (s *Server) asset(w http.ResponseWriter, r *http.Request) {
237 name := r.PathValue("file")
238 if name == "" || strings.Contains(name, "/") || strings.Contains(name, "..") {
239 http.NotFound(w, r)
240 return
241 }
242 sub, err := fs.Sub(webFS, "static")
243 if err != nil {
244 http.Error(w, "assets", http.StatusInternalServerError)
245 return
246 }
247 http.ServeFileFS(w, r, sub, name)
248}
249
250func (s *Server) secure(next http.Handler) http.Handler {
251 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
252 w.Header().Set("X-Content-Type-Options", "nosniff")
253 w.Header().Set("X-Frame-Options", "DENY")
254 w.Header().Set("Referrer-Policy", "strict-origin-when-cross-origin")
255 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'")
256 next.ServeHTTP(w, r)
257 })
258}
259
260func (s *Server) withSession(next http.Handler) http.Handler {
261 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
262 p := principal{}
263 if c, err := r.Cookie("bluegit_session"); err == nil && c.Value != "" {
264 sess, err := s.Store.Session(r.Context(), c.Value)
265 if err == nil && sess.ExpiresAt.After(time.Now()) {
266 p.Session = sess
267 p.User = sess.User
268 p.OK = true
269 s.maybeExtend(r.Context(), sess)
270 }
271 }
272 next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), ctxKey{}, p)))
273 })
274}
275
276func (s *Server) maybeExtend(ctx context.Context, sess store.Session) {
277 if time.Until(sess.ExpiresAt) > 6*time.Hour {
278 return
279 }
280 sec, err := s.Auth.Extend(ctx, sess.AccessToken)
281 if err != nil || sec <= 0 {
282 return
283 }
284 _ = s.Store.UpdateSessionExpiry(ctx, sess.ID, time.Now().Add(time.Duration(sec)*time.Second))
285}
286
287func (s *Server) who(r *http.Request) principal {
288 p, _ := r.Context().Value(ctxKey{}).(principal)
289 return p
290}
291
292func (s *Server) csrfOK(w http.ResponseWriter, r *http.Request) bool {
293 if err := r.ParseForm(); err != nil {
294 http.Error(w, s.tr(r, "err.badForm"), http.StatusBadRequest)
295 return false
296 }
297 p := s.who(r)
298 if !p.OK || r.FormValue("csrf") == "" || r.FormValue("csrf") != p.Session.CSRF {
299 http.Error(w, s.tr(r, "err.badCSRF"), http.StatusBadRequest)
300 return false
301 }
302 return true
303}
304
305func (s *Server) loginRequired(w http.ResponseWriter, r *http.Request) (store.User, bool) {
306 p := s.who(r)
307 if !p.OK {
308 http.Redirect(w, r, "/login", http.StatusFound)
309 return store.User{}, false
310 }
311 return p.User, true
312}
313
314func (s *Server) setSessionCookie(w http.ResponseWriter, id string, exp time.Time) {
315 http.SetCookie(w, &http.Cookie{
316 Name: "bluegit_session",
317 Value: id,
318 Path: "/",
319 HttpOnly: true,
320 SameSite: http.SameSiteLaxMode,
321 Secure: strings.HasPrefix(s.Cfg.BaseURL, "https://"),
322 Expires: exp,
323 })
324}
325
326func (s *Server) flash(w http.ResponseWriter, notice, problem string) {
327 secure := strings.HasPrefix(s.Cfg.BaseURL, "https://")
328 if notice != "" {
329 http.SetCookie(w, &http.Cookie{Name: "bluegit_notice", Value: url.QueryEscape(notice), Path: "/", MaxAge: 120, HttpOnly: true, Secure: secure, SameSite: http.SameSiteLaxMode})
330 }
331 if problem != "" {
332 http.SetCookie(w, &http.Cookie{Name: "bluegit_error", Value: url.QueryEscape(problem), Path: "/", MaxAge: 120, HttpOnly: true, Secure: secure, SameSite: http.SameSiteLaxMode})
333 }
334}
335
336func (s *Server) takeFlash(w http.ResponseWriter, r *http.Request) (string, string) {
337 notice, problem := flashVal(r, "bluegit_notice"), flashVal(r, "bluegit_error")
338 if notice != "" {
339 http.SetCookie(w, &http.Cookie{Name: "bluegit_notice", Value: "", Path: "/", MaxAge: -1})
340 }
341 if problem != "" {
342 http.SetCookie(w, &http.Cookie{Name: "bluegit_error", Value: "", Path: "/", MaxAge: -1})
343 }
344 return notice, problem
345}
346
347func cookieVal(r *http.Request, name string) string {
348 c, err := r.Cookie(name)
349 if err != nil {
350 return ""
351 }
352 return c.Value
353}
354
355func flashVal(r *http.Request, name string) string {
356 raw := cookieVal(r, name)
357 if raw == "" {
358 return ""
359 }
360 v, err := url.QueryUnescape(raw)
361 if err != nil {
362 return raw
363 }
364 return v
365}
366
367func (s *Server) redirect(w http.ResponseWriter, r *http.Request, path, notice, problem string) {
368 s.flash(w, notice, problem)
369 http.Redirect(w, r, path, http.StatusSeeOther)
370}
371
372func (s *Server) langOf(r *http.Request) i18n.Lang {
373 if p := s.who(r); p.OK {
374 return i18n.Parse(p.User.Language)
375 }
376 return i18n.EN
377}
378
379func (s *Server) tr(r *http.Request, key string, args ...any) string {
380 return i18n.T(s.langOf(r), key, args...)
381}
382
383func (s *Server) trErr(r *http.Request, err error) string {
384 return i18n.Text(s.langOf(r), err)
385}
386
387func (s *Server) view(w http.ResponseWriter, r *http.Request, title string) View {
388 notice, problem := s.takeFlash(w, r)
389 lang := s.langOf(r)
390 if strings.HasPrefix(title, "title.") {
391 title = i18n.T(lang, title)
392 }
393 name := strings.TrimSpace(s.Cfg.Runner.Name)
394 if name == "" {
395 name = "Steve"
396 }
397 v := View{
398 Title: title, BaseURL: s.Cfg.BaseURL, RunnerName: name, Notice: notice, Err: problem,
399 StorageUnset: s.StoragePath() == "", Lang: string(lang), HTMLLang: htmlLang(lang),
400 Cunei: lang == i18n.Cuneiform,
401 }
402 for _, l := range i18n.All() {
403 v.Langs = append(v.Langs, LangChoice{Code: string(l), Label: l.Name()})
404 }
405 if p := s.who(r); p.OK {
406 u := p.User
407 v.User = &u
408 v.CSRF = p.Session.CSRF
409 }
410 return v
411}
412
413func htmlLang(l i18n.Lang) string {
414 switch l {
415 case i18n.NL:
416 return "nl"
417 case i18n.DE:
418 return "de"
419 case i18n.FR:
420 return "fr"
421 default:
422 return "en"
423 }
424}
425
426func (s *Server) render(w http.ResponseWriter, name string, v View) {
427 w.Header().Set("Content-Type", "text/html; charset=utf-8")
428 tmpl := s.byLang[v.Lang]
429 if tmpl == nil {
430 tmpl = s.tmpl
431 }
432 if err := tmpl.ExecuteTemplate(w, name, v); err != nil && s.Log != nil {
433 s.Log.Error("sjabloon", "name", name, "err", err)
434 }
435}
436
437func randomState() (string, error) {
438 b := make([]byte, 32)
439 if _, err := rand.Read(b); err != nil {
440 return "", err
441 }
442 return hex.EncodeToString(b), nil
443}
444
445// View is de gegevensset voor elk scherm.
446type View struct {
447 Title string
448 BaseURL string
449 RunnerName string
450 User *store.User
451 CSRF string
452 Notice string
453 Err string
454 Repos []store.Repo
455 Groups []store.Group
456 Repo *store.Repo
457 Role access.Role
458 CanWrite bool
459 CanAdmin bool
460 CanMerge bool
461 CanComment bool
462 CanApply bool
463 Commits []CommitRow
464 Commit *CommitRow
465 CommitDiff *CommitDiff
466 Entries []EntryRow
467 TreePath string
468 Blob string
469 BlobPath string
470 Binary bool
471 Branches []BranchRow
472 MRs []store.MergeRequest
473 MR *store.MergeRequest
474 MRPipe *PipeRow
475 MergeBlocks []string
476 Approval *ApprovalView
477 Reviews []ReviewRow
478 CanReview bool
479 CanApprove bool
480 CanDismiss bool
481 CanClose bool
482 CanReopen bool
483 IsOwner bool
484 Candidates []store.Member
485 Diff string
486 DiffFiles []DiffFileView
487 Pipes []store.Pipeline
488 PipeRows []PipeRow
489 Pipe *store.Pipeline
490 PipeStatus string
491 PipeLabel string
492 PipeJobs []JobLink
493 Live bool
494 LiveURL string
495 Jobs []store.Job
496 JobPage *JobPage
497 Editor *CIEditor
498 Releases []store.Release
499 Members []store.Member
500 Secrets []store.SecretMeta
501 Hooks []HookView
502 Patterns []string
503 TagPatterns []string
504 Tags []TagRow
505 Tokens []store.TokenInfo
506 ShowExpiry bool
507 Keys []store.SSHKey
508 CloneHTTP string
509 CloneSSH string
510 Group *store.Group
511 Tab string
512 Rev string
513 NewToken string
514 StorageUnset bool
515 StoragePath string
516 StorageFree string
517 StorageTotal string
518 MinFree string
519 Wide bool
520 Info bool
521 ShowUpdate bool
522 Update *UpdateView
523 Spec cispec.Doc
524 SpecJSON template.JS
525 Page string
526 Lang string
527 HTMLLang string
528 Cunei bool
529 Langs []LangChoice
530 Query string
531 SortDir string
532 FlipDir string
533 Cards []RepoCard
534 Head *CommitRow
535 Files []FileRow
536 Tree []FileRow
537 Readme template.HTML
538 ReadmeName string
539 LicensePath string
540 NCommits int
541 NBranches int
542 NTags int
543 NReleases int
544 Created string
545 Lines []CodeLine
546 BlobSize string
547 FileName string
548 RevProtected bool
549 Heat *activity.Calendar
550 Notes []NoteRow
551 Profile *store.User
552 DescHTML template.HTML
553 Timeline []TimelineItem
554 CompareFrom string
555 CompareTo string
556 FormTitle string
557 Labels []string
558 CanEditMR bool
559}
560
561// LangChoice is één taal in de instellingen.
562type LangChoice struct {
563 Code, Label string
564}
565
566// RepoCard is een repository in een groepslijst.
567type RepoCard struct {
568 Repo store.Repo
569 Stars int
570 Starred bool
571 When string
572}
573
574// NoteRow is een reactie in de interface.
575type NoteRow struct {
576 ID int64
577 Author, Body, When, Path string
578 Start, End int
579 HasSuggestion bool
580 ParentID int64
581 HTML template.HTML
582 Replies []NoteRow
583 At time.Time
584}
585
586// DiffFileView is één bestand in de merge-request-diff.
587type DiffFileView struct {
588 Path string
589 Lines []DiffLineView
590}
591
592// DiffLineView is één diffregel, met de reacties die op het nieuwe regelnummer eindigen.
593type DiffLineView struct {
594 Kind string
595 Text string
596 Old int
597 New int
598 Notes []NoteRow
599}
600
601// TagRow is één tag op de tagspagina.
602type TagRow struct {
603 Name, Message, SHA, Short, Subject, Date string
604 Annotated, Protected, HasRelease, CanDelete bool
605 ZipURL, TarURL string
606}
607
608// FileRow is een rij in de bestandstabel of de boom.
609type FileRow struct {
610 Name, Path, Icon, Subject, When, SHA string
611 Dir bool
612 Depth int
613 Active bool
614}
615
616// CodeLine is één regel broncode.
617type CodeLine struct {
618 N int
619 HTML template.HTML
620}
621
622// CommitRow is een commit in de interface.
623// Author is de gekoppelde gebruiker, of anders de ruwe git-naam.
624// RawName en PushedBy zijn gezet als de pusher de fallback is en de git-naam afwijkt.
625type CommitRow struct {
626 SHA, Short, Author, Date, Subject, Body, When string
627 UserURL, Avatar, Initial, RawName, PushedBy string
628 PipeID int64
629 PipeStatus, PipeLabel string
630}
631
632// EntryRow is een bestand of map.
633type EntryRow struct {
634 Name, Type, Path string
635}
636
637// BranchRow is een branch, met of zonder bescherming.
638type BranchRow struct {
639 Name, SHA, Short, Subject, When string
640 Protected, Default bool
641 Ahead, Behind int
642 PipeID int64
643 PipeStatus, PipeLabel string
644 MRNumber int64
645}
646
647// TimelineItem is één gebeurtenis of reactie op een merge request.
648type TimelineItem struct {
649 ID int64
650 Kind string
651 Actor, Text string
652 When string
653 Body string
654 HTML template.HTML
655 URL string
656 Replies []TimelineItem
657 At time.Time
658 Rank int
659}
660
661// HookView is een webhook plus de laatste pogingen.
662type HookView struct {
663 ID int64
664 Name string
665 Preset string
666 URL string
667 Method string
668 Filter string
669 Events string
670 Deliveries []store.Delivery
671}
672
673func repoURL(repo store.Repo) string { return "/" + repo.FullPath() }