BlueGit

timfa bluegit

Files

bluegit / internal / server / server.go

server.go

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