BlueGit

timfa bluegit

Files

bluegit / internal / server / server.go

server.go

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