Files
cad-atlas/internal/gitea/client.go
T
mathiasandClaude Opus 4.8 995e428eba
CD / Detect unsubstituted template (push) Successful in 0s
CD / Lint / Test / Vet (push) Successful in 4s
CD / Build & Import (push) Successful in 14s
CD / Deploy via GitOps (push) Has been skipped
feat(atlas): Phase C — recent-runs timeline
A strip of the last 12 runs (aggregate pass/fail/running per run) below the
substrate ribbon, coloured, newest-first, run # on hover. Parsed from the same
Gitea /actions/tasks fetch (RecentRuns, test-first; State refactored to share
the aggregate). No new RBAC. Hidden when no live data.

Verified: build/vet/lint(0)/test green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-20 07:45:59 +02:00

40 lines
1.1 KiB
Go

// Package gitea reads the repo's own Gitea Actions run history from the
// in-cluster Gitea service (public read — no token), so the atlas can show the
// pipeline's live executions.
package gitea
import (
"fmt"
"io"
"net/http"
"os"
"time"
)
// base is the in-cluster Gitea service by default; override with GITEA_BASE.
func base() string {
if b := os.Getenv("GITEA_BASE"); b != "" {
return b
}
return "http://gitea-http.gitea.svc.cluster.local:3000"
}
// Runs returns the raw /actions/tasks JSON for mathias/cad-atlas (newest first).
func Runs() ([]byte, error) {
url := base() + "/api/v1/repos/mathias/cad-atlas/actions/tasks?limit=50"
client := &http.Client{Timeout: 5 * time.Second}
resp, err := client.Get(url) //nolint:noctx // short-lived, timeout on the client
if err != nil {
return nil, err
}
defer func() { _ = resp.Body.Close() }()
body, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("gitea runs: %s", resp.Status)
}
return body, nil
}