generated from mathias/template-go-web
feat(atlas): surface the user's own Gitea repos on stage 05 (#10)
Adds the repos panel from #4's "Not yet shipped" list, following the shipped
issues slice (b2761a4) structurally rather than inventing a second approach:
- internal/atlas/repos.go — RepoNodes(), a pure parser over an already-decoded
/user/repos response. Archived repos are dropped: the atlas shows where work
happens, and an archived repo is by definition somewhere it does not.
- internal/gitea/client.go — MyRepos(), same PAT and same contract as MyIssues:
errors when GITEA_TOKEN is unset so the caller skips the overlay rather than
issuing an unauthenticated request. That unset path is the one running in
prod today (#4), so it is tested, not assumed.
- internal/web/handler.go — wired into liveOverlay().
Stage 05 is the right home — repos are what the execution stage acts on — but
#11 had just claimed its `generate` key for stuck-badges, and a stage could
only name one source. So `generate` now accepts either spelling:
"generate": "ci-jobs"
"generate": ["stuck-badges", "gitea-repos"]
The bare string stays valid and marshals back as a bare string, so no authored
stage is rewritten and the frontend contract is unchanged. Stages 04 and 08
already share stuck-badges between them; this is the same growth one level in.
The overlay merge also moves out of the handler into atlas.PrependGenerated,
which is unit-testable where the inline loop was not — it sat behind a network
call. It covers the issues path too, and fixes a latent aliasing bug there: the
old `append(liveNodes, authored...)` wrote into the live slice's backing array,
so two stages sharing a key would corrupt each other. That shape is no longer
hypothetical now that stuck-badges spans three stages.
Verified end-to-end both ways: without GITEA_TOKEN the atlas returns 200 with
stage 05's authored nodes intact; with a real token stage 05 serves both
overlays at once — stuck badges, then eight live repos, then the authored
nodes — and a repo with no language emits one tag rather than an empty pill.
task check green (golangci-lint 0 issues, vet, -race).
Closes #10.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package atlas_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.d-ma.be/mathias/cad-atlas/internal/atlas"
|
||||
)
|
||||
|
||||
func stagedAtlas() *atlas.Atlas {
|
||||
return &atlas.Atlas{Stages: []atlas.Stage{
|
||||
{No: "STAGE 03", Generate: atlas.GenerateKeys{"gitea-issues"}, Nodes: []atlas.Node{{Title: "authored issue node"}}},
|
||||
{No: "STAGE 05", Generate: atlas.GenerateKeys{"gitea-repos"}, Nodes: []atlas.Node{{Title: "authored repo node"}}},
|
||||
{No: "STAGE 08", Nodes: []atlas.Node{{Title: "untouched"}}},
|
||||
}}
|
||||
}
|
||||
|
||||
func TestPrependGenerated_LiveNodesComeFirstAndAuthoredSurvive(t *testing.T) {
|
||||
a := stagedAtlas()
|
||||
|
||||
atlas.PrependGenerated(a, "gitea-repos", []atlas.Node{{Title: "live repo"}})
|
||||
|
||||
got := a.Stages[1].Nodes
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("want 2 nodes, got %d: %+v", len(got), got)
|
||||
}
|
||||
if got[0].Title != "live repo" || got[1].Title != "authored repo node" {
|
||||
t.Fatalf("order wrong: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrependGenerated_OnlyTouchesMatchingStage(t *testing.T) {
|
||||
a := stagedAtlas()
|
||||
|
||||
atlas.PrependGenerated(a, "gitea-repos", []atlas.Node{{Title: "live repo"}})
|
||||
|
||||
if len(a.Stages[0].Nodes) != 1 || a.Stages[0].Nodes[0].Title != "authored issue node" {
|
||||
t.Fatalf("stage 03 disturbed: %+v", a.Stages[0].Nodes)
|
||||
}
|
||||
if len(a.Stages[2].Nodes) != 1 || a.Stages[2].Nodes[0].Title != "untouched" {
|
||||
t.Fatalf("stage 08 disturbed: %+v", a.Stages[2].Nodes)
|
||||
}
|
||||
}
|
||||
|
||||
// The graceful-skip contract: with GITEA_TOKEN unset the overlay yields no
|
||||
// nodes, and the atlas must still render its authored placeholders unchanged.
|
||||
func TestPrependGenerated_NoLiveNodesLeavesAuthoredIntact(t *testing.T) {
|
||||
a := stagedAtlas()
|
||||
|
||||
atlas.PrependGenerated(a, "gitea-repos", nil)
|
||||
|
||||
if len(a.Stages[1].Nodes) != 1 || a.Stages[1].Nodes[0].Title != "authored repo node" {
|
||||
t.Fatalf("authored nodes lost on empty overlay: %+v", a.Stages[1].Nodes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrependGenerated_UnknownKeyIsANoop(t *testing.T) {
|
||||
a := stagedAtlas()
|
||||
|
||||
atlas.PrependGenerated(a, "no-such-key", []atlas.Node{{Title: "live"}})
|
||||
|
||||
for i, s := range a.Stages {
|
||||
if len(s.Nodes) != 1 {
|
||||
t.Fatalf("stage %d changed: %+v", i, s.Nodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user