- Add ADR 0006 detailing Gitea organization binding, auto-provisioning, and decoupled GitHub mirror defaults - Update CLI specification and usage examples in README.md
3.9 KiB
ADR 006: Gitea Organization Binding and Auto-Provisioning
Status
Accepted (2026-10-18)
Context
As projects scale beyond flat personal repositories into structured domains (such as homelab infrastructure, sites, or shared tooling), organizing repositories under Gitea organizations provides logical grouping, cleaner namespace separation, and fine-grained team/access control.
Previously, new-repo hardcoded creds.gitea_user across all Gitea API endpoints (/api/v1/user/repos, template generation, migration, and push mirror registration) and local SSH remote URLs (git@<host>:<user>/<repo>.git). Creating a repository under a Gitea organization required manual creation via the Gitea web UI followed by manual remote and mirror configuration.
Decision
We extend new-repo to support binding repositories to a Gitea organization across all provisioning workflows (standard greenfield creation, existing local repository linking, template generation, and GitHub-to-Gitea migration):
-
Flexible CLI Target Specification:
- Support both an explicit
-o/--org <ORG>flag and positional<org>/<repo>shorthand (e.g.,new-repo homelab/coreornew-repo core -o homelab). - Validate and reject conflicting organization names if both forms are provided with mismatched values.
- Support both an explicit
-
Automatic Organization Provisioning on Gitea:
- Before provisioning or migrating a repository under a target organization,
new-repochecks whether the organization exists viaGET /api/v1/orgs/{org}. - If the organization returns
404 Not Found,new-repoautomatically provisions it viaPOST /api/v1/orgswith visibility matching the repository's privacy flag (privateby default, orpublicwhen--publicis passed).
- Before provisioning or migrating a repository under a target organization,
-
Endpoint Routing Across Workflows:
- Standard & Existing Git Creation: Routes to
POST /api/v1/orgs/{org}/reposwhen an organization is specified, orPOST /api/v1/user/reposotherwise. - Template Generation: Passes
"owner": gitea_ownertoPOST /api/v1/repos/{tmpl_owner}/{tmpl_name}/generate. - GitHub Migration: Passes
"repo_owner": gitea_ownertoPOST /api/v1/repos/migrateand checksGET /api/v1/repos/{gitea_owner}/{dest_name}for pre-flight conflict detection. - Push Mirroring: Registers push mirrors at
POST /api/v1/repos/{gitea_owner}/{repo_name}/push_mirrors.
- Standard & Existing Git Creation: Routes to
-
Decoupled GitHub Mirror Ownership:
- Offsite GitHub backup mirrors continue to default to the personal
GITHUB_USERaccount (POST /user/repos) so users do not need matching GitHub organizations for internal Gitea namespaces. - An optional
--github-org <GITHUB_ORG>flag allows routing the GitHub mirror target toPOST /orgs/{org}/reposwhen desired.
- Offsite GitHub backup mirrors continue to default to the personal
-
Flat Local Directory Resolution:
- Local clones and working tree detection remain flat (
<cwd>/<repo_name>or<cwd>if already inside<repo_name>), matching standardgit cloneergonomics regardless of whether an organization prefix was used.
- Local clones and working tree detection remain flat (
Consequences
Good
- Zero-Friction Namespace Organization: Repositories can be grouped under existing or brand-new Gitea organizations in a single CLI invocation.
- Ergonomic CLI: Supports both intuitive
org/reposhorthand and explicit-o orgflags (useful when inferring the repo name from the current directory vianew-repo -o homelab). - Decoupled Forge Topologies: Gitea organizations can be used freely for self-hosted categorization without forcing corresponding organization setup on GitHub.
Bad
- Requires the Gitea Personal Access Token (
GITEA_TOKEN) to includewrite:organization(oradmin:org) scope when checking or auto-creating organizations.
Neutral
- If two different Gitea organizations contain repositories with the exact same name and both mirror to the same personal GitHub account, a naming collision on GitHub will occur (mitigated by
new-repo's retain-and-report policy or--no-mirror/--github-org).