BlueGit

timfa bluegit

Files

bluegit / internal / server / server.go

server.go

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