Skip to content

feat: auto-create library repo via go-github in librarystore (#459) - #461

Merged
antoinetoussaint-byte merged 2 commits into
mainfrom
issue-459-librarystore-auto-create-library-repo-via-go-github
Aug 23, 2026
Merged

feat: auto-create library repo via go-github in librarystore (#459)#461
antoinetoussaint-byte merged 2 commits into
mainfrom
issue-459-librarystore-auto-create-library-repo-via-go-github

Conversation

@antoinetoussaint-byte

Copy link
Copy Markdown
Contributor

Closes#459.

Summary

  • pkg/librarystore published library content over raw git but assumed the target repository already existed, erroring out otherwise. Repository creation is a GitHub platform operation git can't perform, so Publish now runs a "create if missing" step over the go-github/v89 API (already a direct dependency) before the unchanged git clone/commit/tag/push flow.
  • Creation is idempotent (existing repo → no-op via Repositories.Get), org-owned, and private by default so an automated publish never makes an org's history public as a side effect. A non-404 lookup error is surfaced rather than mistaken for a missing repo.
  • When no token is available, creation is skipped and the clone falls back to today's "create the library repository first" message; when a token lacks creation scope, Repositories.Create fails with an actionable error naming the missing scope.

The token/client plumbing (GITHUB_TOKEN/GH_TOKEN, then gh auth token) mirrors the existing resolver in cmd/agents/versions.go; consolidating both into a shared helper is #457's job and is intentionally left out of scope here.

Test plan

  • TestGitHubStorePublishCreatesMissingRepositoryBeforeCloning — creation runs before the clone; the git path then publishes normally.
  • TestGitHubStorePublishAbortsWhenRepositoryCreationFails — a creation failure aborts before any git operation.
  • TestEnsureRepositoryExists — existing repo is a no-op, absent repo is created org-owned, a non-404 lookup surfaces an error, and a no-scope token yields an actionable error (httptest, real go-github).
  • go build ./pkg/librarystore/, go vet ./pkg/librarystore/, go test ./pkg/librarystore/ all pass; no go.mod/go.sum changes.

🤖 Generated with Claude Code

Publish assumed the target repository already existed and errored out
otherwise. Repository creation is a GitHub platform operation git cannot
perform, so it now runs a "create if missing" step over the go-github API
before the existing git clone/commit/tag/push path.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…able (#459)
Review of the initial auto-create change surfaced defects where the
"safe-looking" defaults quietly broke the feature. Fixes, highest severity
first:
- Split auth: the API token created the repo but never reached git, so a host
authenticated only by GITHUB_TOKEN created a repo it then could not
clone/push. The resolved credential now also authenticates github.com HTTPS
git ops, injected via GIT_CONFIG_* env (scoped to github.com, kept out of
argv) so create and content-push share one credential.
- Visibility: repos were created private, which makes the `go get
github.com/owner/name-go` install hint Publish returns fail for consumers —
contradicting the store's own contract. Repos are now created public.
- Default branch: created empty, so the published default branch was whatever
the publishing host's init.defaultBranch happened to be. AutoInit makes it
deterministic and host-independent.
- Idempotency: a create losing the lookup/create race (422) is now the
idempotent success the contract promises, not a misleading "needs scope"
error.
- Owner type: Create routed everything through the org endpoint, 404ing for a
user owner the struct documents as supported; owner type now selects the org
vs authenticated-user endpoint.
- Testability: the token source is injectable, so the no-token degrade path and
the real ensureRepository wiring are covered without shelling out to `gh`.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

librarystore: auto-create library repo via go-github API (keep git for content)

1 participant

@antoinetoussaint-byte