feat(routing): create GitHub destination repo before configuring push-mirror
Gitea's push-mirror cannot push to a non-existent remote — it just runs 'git push' against whatever URL it's given. So a project_create flow that only configures the mirror leaves the GitHub side as an unfulfillable URL. New internal/githubclient package: single-purpose client that POSTs /user/repos to create an empty private repo (auto_init=false so the first mirror push doesn't conflict with a generated README). Treats 422 'name already exists' as idempotent success via ErrAlreadyExists. 401/403 are surfaced as 'PAT missing repo scope or invalid' so the operator sees the real cause instead of a vague upstream error. Skill wiring: - New stepCreateGitHub between stepCreateRepo and stepMirror in the orchestrator. - Skipped entirely when Config.GitHub is nil (degraded mode — the routing pod runs without GITHUB_PAT, mirror config still lands, but the actual sync to github fails until the repo exists). - cmd/routing/main.go constructs githubclient.New(GitHubPAT) only when the PAT is set; the skill receives nil otherwise. Tests: - happy path: fake github 201 + assertions that the 'reached' array is [create_repo, create_github_repo, mirror, infra_commit, issue]. - github 422 already-exists: idempotent, all gitea steps still run. - github 401: returns failed_step=create_github_repo, no mirror or later steps. - degraded mode (Config.GitHub nil): reached omits create_github_repo, rest of the flow runs unchanged. Updated existing tests to read [skill, gh] from newSkill instead of just skill, and adjusted reached-array expectations to include the new step. Tracks #10.
This commit is contained in:
@@ -9,17 +9,26 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/mathiasbq/supervisor/internal/githubclient"
|
||||
"github.com/mathiasbq/supervisor/internal/mcpclient"
|
||||
"github.com/mathiasbq/supervisor/internal/registry"
|
||||
)
|
||||
|
||||
// Config holds the orchestration dependencies for the project skill.
|
||||
type Config struct {
|
||||
// Client talks to the gitea-mcp server. project_create makes 4 sequential
|
||||
// calls (create_project_from_template, repo_mirror_push, file_write_branch,
|
||||
// issue_create) through this client.
|
||||
// Client talks to the gitea-mcp server. project_create makes
|
||||
// sequential calls (create_project_from_template, repo_mirror_push,
|
||||
// file_write_branch, issue_create) through this client.
|
||||
Client *mcpclient.Client
|
||||
|
||||
// GitHub is the client used to create the empty destination repo on
|
||||
// GitHub before the push-mirror is configured. Gitea's push-mirror
|
||||
// cannot push to a non-existent remote, so this step is mandatory
|
||||
// when GitHubPAT is set. Pass nil to skip github repo creation
|
||||
// entirely (degraded mode — mirror config will land but the actual
|
||||
// sync to github will fail until the repo exists).
|
||||
GitHub *githubclient.Client
|
||||
|
||||
// GiteaOwner is the org/user that owns the new repo and the infra repo
|
||||
// the namespace manifest is committed to (typically "mathias").
|
||||
GiteaOwner string
|
||||
@@ -29,7 +38,8 @@ type Config struct {
|
||||
GitHubOwner string
|
||||
|
||||
// GitHubPAT is the personal access token used as the push-mirror
|
||||
// password. Must have `repo` scope. Never logged.
|
||||
// password and to create the destination repo on GitHub. Must have
|
||||
// `repo` scope. Never logged.
|
||||
GitHubPAT string
|
||||
|
||||
// InfraRepo is the name of the infra repo on Gitea where the
|
||||
|
||||
Reference in New Issue
Block a user