docs(readme): update CLI flags and architecture diagrams for GitHub-primary flow

- Document inverted -o/--org (GitHub), --gitea-org, and --gitea-mirror flags

- Update examples and Mermaid sequence diagrams for GitHub-primary + Gitea pull mirror
This commit is contained in:
kiskaadee committed 2026-11-25 16:39:00 -05:00
1 parent 4c5820bace
commit f2613b0b3a
1 file changed
+59 -68
+59 -68
View File
@@ -1,10 +1,10 @@
# `new-repo` — Automated Repository Provisioning CLI # `new-repo` — Automated Repository Provisioning CLI
`new-repo` is a portable, zero-dependency Python 3 command-line utility designed to automate repository provisioning across a dual-forge Git topology: `new-repo` is a portable, zero-dependency Python 3 command-line utility designed to automate repository provisioning across a dual-forge Git topology:
- **Primary Forge**: A self-hosted Gitea instance for local sovereignty and CI/CD automation. - **Primary Forge**: **GitHub** for cloud availability, issue/project planning, and CI/CD automation.
- **Backup Forge**: GitHub for offsite redundancy via automated server-side push mirroring. - **Backup Forge**: Self-hosted **Gitea** for homelab redundancy via automated server-side **pull mirroring**.
It automates the multi-step setup required to create a repository, establish push mirroring, and prepare a local working tree in a single command. It automates the multi-step setup required to create a repository on GitHub, prepare a local working tree, and attach a Gitea pull mirror in a single command.
--- ---
@@ -13,7 +13,7 @@ It automates the multi-step setup required to create a repository, establish pus
1. **Zero External Dependencies**: Built strictly with Python 3 standard library modules (`urllib.request`, `argparse`, `json`, `subprocess`, `dataclasses`, `typing`). Requires no virtual environment, compilation step, or third-party package installation. 1. **Zero External Dependencies**: Built strictly with Python 3 standard library modules (`urllib.request`, `argparse`, `json`, `subprocess`, `dataclasses`, `typing`). Requires no virtual environment, compilation step, or third-party package installation.
2. **Universal Portability (12-Factor)**: Standard environment variables (`GITEA_TOKEN`, `GITHUB_TOKEN`) and optional `.env` files serve as the primary configuration contract. The utility runs out-of-the-box on any POSIX system, container, or CI/CD runner. 2. **Universal Portability (12-Factor)**: Standard environment variables (`GITEA_TOKEN`, `GITHUB_TOKEN`) and optional `.env` files serve as the primary configuration contract. The utility runs out-of-the-box on any POSIX system, container, or CI/CD runner.
3. **In-Memory Credential Safety**: Tokens are injected exclusively via native HTTPS authorization headers. Secrets are never passed as command-line arguments to subprocesses, preventing exposure in system process tables (`ps`, `/proc/$PID/cmdline`) or persistent disk logs. 3. **In-Memory Credential Safety**: Tokens are injected exclusively via native HTTPS authorization headers. Secrets are never passed as command-line arguments to subprocesses, preventing exposure in system process tables (`ps`, `/proc/$PID/cmdline`) or persistent disk logs.
4. **Resilient Failure Recovery**: Adheres to a *retain-and-report* policy. If backup mirror provisioning or push mirror registration encounters an error after the primary repository is created, the primary repository is preserved and diagnostic URLs are printed for manual review. 4. **Resilient Failure Recovery**: Adheres to a *retain-and-report* policy. If homelab Gitea pull-mirror registration encounters an error after the primary GitHub repository is created, the GitHub repository is preserved and diagnostic URLs are printed for manual review or `--gitea-mirror` retry.
5. **Strict Static Typing**: Enforces full static type hints validated via **Pyright** and formatted/linted via **Ruff**. 5. **Strict Static Typing**: Enforces full static type hints validated via **Pyright** and formatted/linted via **Ruff**.
Architecture Decision Records (ADRs) are maintained in [`docs/adr/`](docs/adr/): Architecture Decision Records (ADRs) are maintained in [`docs/adr/`](docs/adr/):
@@ -35,52 +35,48 @@ Arguments:
name Optional repository name ('[org/]repo', defaults to current directory if omitted or '.') name Optional repository name ('[org/]repo', defaults to current directory if omitted or '.')
Options: Options:
-o, --org ORG Target Gitea organization to own the repository (auto-created if missing) -o, --org ORG Target GitHub organization to own the repository (defaults to personal GITHUB_USER)
--github-org ORG Optional GitHub organization for the offsite backup mirror (defaults to personal GITHUB_USER) --gitea-org ORG Optional Gitea organization for the homelab pull mirror (auto-created if missing; defaults to GITEA_USER)
--migrate [URL] Migrate an existing GitHub repo to Gitea with automated push mirroring (URL or auto-detect from local origin) --gitea-mirror [URL] Attach a Gitea pull mirror to an existing GitHub repository (URL or auto-detect from local origin)
-p, --private Make repository private (default: public) -p, --private Make repository private (default: public)
-d, --description Optional repository description string -d, --description Optional repository description string
-l, --license License template identifier (default: Unlicense, pass "" to disable) -l, --license GitHub license template identifier (default: unlicense, pass "" to disable)
-t, --template Optional Gitea template repository ('[owner/]template-name') -t, --template Optional GitHub template repository ('[owner/]template-name')
-M, --no-mirror Disable automatic offsite push mirroring to GitHub -M, --no-mirror Disable automatic homelab pull mirroring to Gitea
--no-clone Skip cloning the repository locally after creation --no-clone Skip cloning the repository locally after creation
--as PERSONA Persona / login identity to provision as (matches tea login or SOPS persona, e.g. anneux) --as PERSONA Persona / login identity to provision as (e.g. anneux)
-h, --help Show help message and exit -h, --help Show help message and exit
``` ```
### Examples ### Examples
```bash ```bash
# 1. Standard greenfield creation (Public Gitea + GitHub push mirror + Unlicense + auto-clone) # 1. Standard greenfield creation (Public GitHub + Gitea pull mirror + unlicense + auto-clone)
new-repo service-api new-repo service-api
# 2. Provision as a specific agent persona (binds Gitea/GitHub credentials and SSH keys to persona) # 2. Provision as a specific agent persona (binds GitHub/Gitea credentials and SSH keys to persona)
new-repo frontend-app --as anneux new-repo frontend-app --as anneux
# 2. Provision under a Gitea organization (via shorthand or -o/--org flag; auto-creates org if missing) # 3. Provision under a GitHub organization (via shorthand or -o/--org flag)
new-repo homelab/core new-repo my-org/core
new-repo core -o homelab new-repo core -o my-org
# 3. Attach remotes & push an existing local repository (into personal account or organization) # 4. Attach remotes & push an existing local repository (into personal account or organization)
cd ~/Projects/my-existing-app cd ~/Projects/my-existing-app
new-repo -o homelab new-repo -o my-org
# 4. Provision from an existing Gitea template # 5. Provision from an existing GitHub template
new-repo web-client --template template-react-app new-repo web-client --template template-react-app
# 5. Local-only repository (no GitHub mirror) # 6. GitHub-only repository (no Gitea pull mirror)
new-repo private-notes --no-mirror new-repo cloud-only --no-mirror
# 6. Private repository with MIT license # 7. Private repository with MIT license
new-repo utility-lib --private --license MIT new-repo utility-lib --private --license mit
# 7. Migrate an existing GitHub repository to Gitea (personal or organization) with push mirror # 8. Attach a Gitea pull mirror to an existing GitHub repository (explicit URL or local origin)
new-repo --migrate https://github.com/my-org/existing-service new-repo --gitea-mirror https://github.com/my-org/existing-service
new-repo homelab/existing-service --migrate https://github.com/my-org/existing-service cd ~/Projects/existing-service && new-repo --gitea-mirror
# 8. Migrate repository in-place from inside a local checkout
cd ~/Projects/existing-service
new-repo --migrate
``` ```
--- ---
@@ -132,61 +128,56 @@ sequenceDiagram
actor User as Developer / CI Runner actor User as Developer / CI Runner
participant CLI as new-repo (Python 3) participant CLI as new-repo (Python 3)
participant SP as SecretProvider (Env / .env / SOPS) participant SP as SecretProvider (Env / .env / SOPS)
participant Gitea as Gitea API (Primary) participant GitHub as GitHub API (Primary)
participant GitHub as GitHub API (Backup)
participant Git as Local Git participant Git as Local Git
participant Gitea as Gitea API (Pull Mirror)
User->>CLI: new-repo <repo-name> [flags] User->>CLI: new-repo <repo-name> [flags]
CLI->>SP: Resolve API credentials CLI->>SP: Resolve API credentials
SP-->>CLI: Credentials (Gitea token, GitHub token) SP-->>CLI: Credentials (GitHub token, Gitea token)
alt Template Repo Specified (-t <template>) alt Existing Local Git Repo
CLI->>Gitea: POST /api/v1/repos/{owner}/{template}/generate CLI->>GitHub: POST /user/repos or /orgs/{org}/repos (auto_init=False)
Gitea-->>CLI: Primary repository generated GitHub-->>CLI: Empty primary repository created
else Standard Repository CLI->>Git: git remote add/set-url origin git@github.com:<owner>/<repo>.git && git push -u origin <branch>
CLI->>Gitea: POST /api/v1/user/repos (with license & auto-init) else Template Repo Specified (-t <template>)
Gitea-->>CLI: Primary repository created CLI->>GitHub: POST /repos/{owner}/{template}/generate
GitHub-->>CLI: Primary repository generated
else Standard Greenfield Repository
CLI->>GitHub: POST /user/repos or /orgs/{org}/repos (auto_init=True, license_template)
GitHub-->>CLI: Primary repository created
end end
opt Push Mirroring Enabled (Default) opt Local Clone Enabled (Greenfield Default)
CLI->>GitHub: POST https://api.github.com/user/repos (empty target) CLI->>Git: git clone git@github.com:<owner>/<repo>.git
GitHub-->>CLI: Mirror target created
CLI->>Gitea: POST /api/v1/repos/{owner}/{repo}/push_mirrors
Gitea-->>CLI: Push mirror registered (sync on commit)
end
opt Local Clone Enabled (Default)
CLI->>Git: git clone git@<gitea-host>:<user>/<repo>.git
Git-->>CLI: Working tree cloned to ./<repo-name> Git-->>CLI: Working tree cloned to ./<repo-name>
end end
opt Homelab Pull Mirror Enabled (Default)
CLI->>Gitea: POST /api/v1/repos/migrate (mirror=True, service=github, auth_token=gh_token)
Gitea->>GitHub: Server-to-server pull mirror sync
Gitea-->>CLI: Pull mirror registered
end
``` ```
### Migration Workflow (`--migrate`) ### Attach Pull Mirror Workflow (`--gitea-mirror`)
```mermaid ```mermaid
sequenceDiagram sequenceDiagram
autonumber autonumber
actor User as Developer actor User as Developer
participant CLI as new-repo (--migrate) participant CLI as new-repo (--gitea-mirror)
participant Gitea as Gitea API (Primary) participant Gitea as Gitea API (Pull Mirror)
participant GitHub as GitHub (Source) participant GitHub as GitHub (Primary)
participant Git as Local Working Tree
User->>CLI: new-repo --migrate [github-target] User->>CLI: new-repo --gitea-mirror [github-target]
CLI->>Gitea: GET /api/v1/repos/{user}/{repo} (Conflict Check) CLI->>Gitea: GET /api/v1/repos/{owner}/{repo} (Conflict Check)
alt Repo Exists alt Repo Exists on Gitea
Gitea-->>CLI: 200 OK (Abort migration) Gitea-->>CLI: 200 OK (Abort to avoid overwriting)
else Repo Does Not Exist else Repo Does Not Exist
CLI->>Gitea: POST /api/v1/repos/migrate (mirror=False, auth_token=gh_token) CLI->>Gitea: POST /api/v1/repos/migrate (mirror=True, auth_token=gh_token)
Gitea->>GitHub: Server-to-server clone of branches, tags, and commits Gitea->>GitHub: Server-to-server pull mirror sync
Gitea-->>CLI: Repository imported Gitea-->>CLI: Pull mirror created
CLI->>Gitea: POST /api/v1/repos/{user}/{repo}/push_mirrors
Gitea-->>CLI: Push mirror registered (sync on commit)
opt Inside Local Git Repo
CLI->>Git: Rename remote 'origin' -> 'github'
CLI->>Git: Add remote 'origin' -> Gitea clone URL
CLI->>Git: git branch --set-upstream-to=origin/<branch>
end
end end
``` ```