BlueGit

timfa bluegit

Files

bluegit / internal / server / info.go

info.go

feat: stuur volledige details mee in webhook-payloads
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
3ca4d219 History
info.go 1.5 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 s.attachUpdate(&v, s.langOf(r))
27 s.render(w, "info", v)
28}
29
30func (s *Server) webhookSpec(w http.ResponseWriter, r *http.Request) {
31 w.Header().Set("Content-Type", "application/json; charset=utf-8")
32 w.Header().Set("Cache-Control", "no-store")
33 _, _ = w.Write(webhook.OpenAPI())
34}
35
36func (s *Server) ciSpec(w http.ResponseWriter, r *http.Request) {
37 lang := i18n.EN
38 if q := r.URL.Query().Get("lang"); q != "" {
39 lang = i18n.Parse(q)
40 }
41 _, raw, err := s.ciDocument(lang)
42 if err != nil {
43 http.Error(w, err.Error(), http.StatusInternalServerError)
44 return
45 }
46 w.Header().Set("Content-Type", "application/json; charset=utf-8")
47 w.Header().Set("Cache-Control", "no-store")
48 _, _ = w.Write(raw)
49}
50
51func (s *Server) ciDocument(lang i18n.Lang) (cispec.Doc, []byte, error) {
52 set, err := images.Effective(s.Cfg.CI.ImageOverrides())
53 if err != nil {
54 return cispec.Doc{}, nil, err
55 }
56 doc := cispec.Build(lang, set)
57 return doc, cispec.Marshal(doc), nil
58}