add a page for tickets from gitea (#2)
Co-authored-by: Blake Ridgway <blake@blakeridgway.com> Reviewed-on: #2
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -13,11 +14,19 @@ import (
|
||||
"ridgwaysystems.org/website/internal/blog"
|
||||
"ridgwaysystems.org/website/internal/changelog"
|
||||
"ridgwaysystems.org/website/internal/feed"
|
||||
"ridgwaysystems.org/website/internal/gitea"
|
||||
"ridgwaysystems.org/website/internal/mailer"
|
||||
"ridgwaysystems.org/website/internal/status"
|
||||
"ridgwaysystems.org/website/internal/uptime"
|
||||
)
|
||||
|
||||
// streamData is passed to the stream template.
|
||||
type streamData struct {
|
||||
Channel string
|
||||
Live bool
|
||||
Parent string // hostname for Twitch embed parent= param
|
||||
}
|
||||
|
||||
const postsPerPage = 10
|
||||
|
||||
// indexData is passed to the index template.
|
||||
@@ -158,6 +167,22 @@ func (h *Handler) Infrastructure(w http.ResponseWriter, r *http.Request) {
|
||||
h.render(w, "infrastructure", nil)
|
||||
}
|
||||
|
||||
func (h *Handler) Stream(w http.ResponseWriter, r *http.Request) {
|
||||
if h.twitch == nil {
|
||||
h.renderErr(w, http.StatusNotFound, "Stream page not configured.")
|
||||
return
|
||||
}
|
||||
host := r.Host
|
||||
if h, _, err := net.SplitHostPort(host); err == nil {
|
||||
host = h
|
||||
}
|
||||
h.render(w, "stream", streamData{
|
||||
Channel: h.twitch.Channel(),
|
||||
Live: h.twitch.IsLive(),
|
||||
Parent: host,
|
||||
})
|
||||
}
|
||||
|
||||
// serviceHistory bundles per-service uptime data for the status template.
|
||||
type serviceHistory struct {
|
||||
Blocks []uptime.DayBlock
|
||||
@@ -166,9 +191,10 @@ type serviceHistory struct {
|
||||
|
||||
// statusData is passed to the status template.
|
||||
type statusData struct {
|
||||
Page *status.Page
|
||||
LastChecked string
|
||||
History map[string]serviceHistory // keyed by service name
|
||||
Page *status.Page
|
||||
LastChecked string
|
||||
History map[string]serviceHistory // keyed by service name
|
||||
PlannedOutages []gitea.Issue
|
||||
}
|
||||
|
||||
func (h *Handler) Status(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -188,7 +214,17 @@ func (h *Handler) Status(w http.ResponseWriter, r *http.Request) {
|
||||
UptimePct: uptime.UptimePct(uptimePath, svc.Name),
|
||||
}
|
||||
}
|
||||
h.render(w, "status", statusData{Page: p, LastChecked: lastChecked, History: history})
|
||||
// Fetch planned outages from Gitea — best-effort, failure is non-fatal.
|
||||
var plannedOutages []gitea.Issue
|
||||
if h.gitea != nil && h.giteaOwner != "" && h.giteaRepo != "" {
|
||||
if issues, err := h.gitea.ListIssuesByLabel(h.giteaOwner, h.giteaRepo, h.giteaLabel); err == nil {
|
||||
plannedOutages = issues
|
||||
} else {
|
||||
log.Printf("status: gitea planned outages: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
h.render(w, "status", statusData{Page: p, LastChecked: lastChecked, History: history, PlannedOutages: plannedOutages})
|
||||
}
|
||||
|
||||
// changelogData is passed to the changelog template.
|
||||
|
||||
Reference in New Issue
Block a user