docs: document Gitea organization binding and add adr 0006

- Add ADR 0006 detailing Gitea organization binding, auto-provisioning, and decoupled GitHub mirror defaults
- Update CLI specification and usage examples in README.md
This commit is contained in:
kiskaadee committed 2026-10-18 08:00:38 -05:00
1 parent 412fc3e77b
commit 06cc3254c0
2 files changed
+63 -9

No files matched your search

+17 -9
View File
@@ -22,6 +22,7 @@ Architecture Decision Records (ADRs) are maintained in [`docs/adr/`](docs/adr/):
- [**ADR 003**: Dual-Forge Topology with Automated Push Mirroring and Retain-and-Report Error Policy](docs/adr/0003-dual-forge-topology-with-automated-push-mirroring.md) - [**ADR 003**: Dual-Forge Topology with Automated Push Mirroring and Retain-and-Report Error Policy](docs/adr/0003-dual-forge-topology-with-automated-push-mirroring.md)
- [**ADR 004**: Existing Repository Linking and Auto-Detection](docs/adr/0004-existing-repository-linking-and-auto-detection.md) - [**ADR 004**: Existing Repository Linking and Auto-Detection](docs/adr/0004-existing-repository-linking-and-auto-detection.md)
- [**ADR 005**: GitHub-to-Gitea Migration with Automated Push Mirroring](docs/adr/0005-github-to-gitea-migration-with-automated-push-mirroring.md) - [**ADR 005**: GitHub-to-Gitea Migration with Automated Push Mirroring](docs/adr/0005-github-to-gitea-migration-with-automated-push-mirroring.md)
- [**ADR 006**: Gitea Organization Binding and Auto-Provisioning](docs/adr/0006-gitea-organization-binding.md)
--- ---
@@ -31,9 +32,11 @@ Architecture Decision Records (ADRs) are maintained in [`docs/adr/`](docs/adr/):
Usage: new-repo [NAME] [OPTIONS] Usage: new-repo [NAME] [OPTIONS]
Arguments: Arguments:
name Optional repository name (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)
--github-org ORG Optional GitHub organization for the offsite backup mirror (defaults to personal GITHUB_USER)
--migrate [URL] Migrate an existing GitHub repo to Gitea with automated push mirroring (URL or auto-detect from local origin) --migrate [URL] Migrate an existing GitHub repo to Gitea with automated push mirroring (URL or auto-detect from local origin)
-p, --public Make repository public (default: private) -p, --public Make repository public (default: private)
-d, --description Optional repository description string -d, --description Optional repository description string
@@ -50,23 +53,28 @@ Options:
# 1. Standard greenfield creation (Private Gitea + GitHub push mirror + UNLICENSE + auto-clone) # 1. Standard greenfield creation (Private Gitea + GitHub push mirror + UNLICENSE + auto-clone)
new-repo service-api new-repo service-api
# 2. Attach remotes & push an existing local repository # 2. Provision under a Gitea organization (via shorthand or -o/--org flag; auto-creates org if missing)
cd ~/Projects/my-existing-app new-repo homelab/core
new-repo new-repo core -o homelab
# 3. Provision from an existing Gitea template # 3. Attach remotes & push an existing local repository (into personal account or organization)
cd ~/Projects/my-existing-app
new-repo -o homelab
# 4. Provision from an existing Gitea template
new-repo web-client --template template-react-app new-repo web-client --template template-react-app
# 4. Local-only repository (no GitHub mirror) # 5. Local-only repository (no GitHub mirror)
new-repo private-notes --no-mirror new-repo private-notes --no-mirror
# 5. Public open-source repository with MIT license # 6. Public open-source repository with MIT license
new-repo utility-lib --public --license MIT new-repo utility-lib --public --license MIT
# 6. Migrate an existing GitHub repository to Gitea with push mirror # 7. Migrate an existing GitHub repository to Gitea (personal or organization) with push mirror
new-repo --migrate https://github.com/my-org/existing-service new-repo --migrate https://github.com/my-org/existing-service
new-repo homelab/existing-service --migrate https://github.com/my-org/existing-service
# 7. Migrate repository in-place from inside a local checkout # 8. Migrate repository in-place from inside a local checkout
cd ~/Projects/existing-service cd ~/Projects/existing-service
new-repo --migrate new-repo --migrate
``` ```
@@ -0,0 +1,46 @@
# 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):
1. **Flexible CLI Target Specification**:
- Support both an explicit `-o` / `--org <ORG>` flag and positional `<org>/<repo>` shorthand (e.g., `new-repo homelab/core` or `new-repo core -o homelab`).
- Validate and reject conflicting organization names if both forms are provided with mismatched values.
2. **Automatic Organization Provisioning on Gitea**:
- Before provisioning or migrating a repository under a target organization, `new-repo` checks whether the organization exists via `GET /api/v1/orgs/{org}`.
- If the organization returns `404 Not Found`, `new-repo` automatically provisions it via `POST /api/v1/orgs` with visibility matching the repository's privacy flag (`private` by default, or `public` when `--public` is passed).
3. **Endpoint Routing Across Workflows**:
- **Standard & Existing Git Creation**: Routes to `POST /api/v1/orgs/{org}/repos` when an organization is specified, or `POST /api/v1/user/repos` otherwise.
- **Template Generation**: Passes `"owner": gitea_owner` to `POST /api/v1/repos/{tmpl_owner}/{tmpl_name}/generate`.
- **GitHub Migration**: Passes `"repo_owner": gitea_owner` to `POST /api/v1/repos/migrate` and checks `GET /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`.
4. **Decoupled GitHub Mirror Ownership**:
- Offsite GitHub backup mirrors continue to default to the personal `GITHUB_USER` account (`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 to `POST /orgs/{org}/repos` when desired.
5. **Flat Local Directory Resolution**:
- Local clones and working tree detection remain flat (`<cwd>/<repo_name>` or `<cwd>` if already inside `<repo_name>`), matching standard `git clone` ergonomics regardless of whether an organization prefix was used.
## 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/repo` shorthand and explicit `-o org` flags (useful when inferring the repo name from the current directory via `new-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 include `write:organization` (or `admin: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`).