BlueGit

timfa bluegit

Files

bluegit / internal / server / server.go

server.go

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