BlueGit

timfa bluegit

Files

bluegit / internal / server / info.go

info.go

feat: voeg een issue-tracker per repository toe
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
f3222d5f History
info.go 1.6 KiB Download Raw
1package server
2
3import (
4 "html/template"
5 "net/http"
6
7 "gitlab.com/Timfa/bluegit/internal/cispec"
8 "gitlab.com/Timfa/bluegit/internal/i18n"
9 "gitlab.com/Timfa/bluegit/internal/images"
10 "gitlab.com/Timfa/bluegit/internal/webhook"
11)
12
13func (s *Server) infoPage(w http.ResponseWriter, r *http.Request) {
14 doc, raw, err := s.ciDocument(s.langOf(r))
15 if err != nil {
16 http.Error(w, err.Error(), http.StatusInternalServerError)
17 return
18 }
19 v := s.view(w, r, "title.info")
20 v.Page = "info"
21 v.Info = true
22 v.Spec = doc
23 v.SpecJSON = template.JS(raw)
24 v.APIJSON = template.JS(apiIndex())
25 v.HookDoc = webhook.Example()
26 v.IssueDoc = webhook.IssueExample()
27 s.attachUpdate(&v, s.langOf(r))
28 s.render(w, "info", v)
29}
30
31func (s *Server) webhookSpec(w http.ResponseWriter, r *http.Request) {
32 w.Header().Set("Content-Type", "application/json; charset=utf-8")
33 w.Header().Set("Cache-Control", "no-store")
34 _, _ = w.Write(webhook.OpenAPI())
35}
36
37func (s *Server) ciSpec(w http.ResponseWriter, r *http.Request) {
38 lang := i18n.EN
39 if q := r.URL.Query().Get("lang"); q != "" {
40 lang = i18n.Parse(q)
41 }
42 _, raw, err := s.ciDocument(lang)
43 if err != nil {
44 http.Error(w, err.Error(), http.StatusInternalServerError)
45 return
46 }
47 w.Header().Set("Content-Type", "application/json; charset=utf-8")
48 w.Header().Set("Cache-Control", "no-store")
49 _, _ = w.Write(raw)
50}
51
52func (s *Server) ciDocument(lang i18n.Lang) (cispec.Doc, []byte, error) {
53 set, err := images.Effective(s.Cfg.CI.ImageOverrides())
54 if err != nil {
55 return cispec.Doc{}, nil, err
56 }
57 doc := cispec.Build(lang, set)
58 return doc, cispec.Marshal(doc), nil
59}