BlueGit

timfa bluegit

Files

bluegit / internal / server / server.go

server.go

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