github_org: support forking repositories via fork_from #135

Merged
benvin merged 4 commits from benvin/github-fork-support into main 2026-11-19 22:48:36 +11:00
Member

GitHub repositories in modules/github_org can only be created empty, so mirroring an upstream project as an org-managed fork is not possible.

  • add optional fork_from: owner/repo to repository yaml, forking a public upstream
  • leave fork visibility to the source and reject private on forks
  • select the existing default branch on forks instead of renaming it
  • overwrite an inherited CODEOWNERS on forks so org code-owner rulesets apply
  • document fork_from and its constraints in the README
GitHub repositories in `modules/github_org` can only be created empty, so mirroring an upstream project as an org-managed fork is not possible. - add optional `fork_from: owner/repo` to repository yaml, forking a public upstream - leave fork visibility to the source and reject `private` on forks - select the existing default branch on forks instead of renaming it - overwrite an inherited CODEOWNERS on forks so org code-owner rulesets apply - document `fork_from` and its constraints in the README
unkin-agent added 1 commit 2026-11-19 22:19:57 +11:00
add fork_from to github repositories
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/plan Pipeline was successful
3198f8d5d1
Author
Member
  • modules/github_org/modules/repository/main.tf:32 — rename = true against default_branch (default main) renames the fork's inherited default branch when the source uses another (e.g. master), diverging it from upstream → require default_branch to match the source (validate/document), or set rename = local.fork_source == null for forks.
  • modules/github_org/modules/repository/main.tf:58 — CODEOWNERS file on a fork fails with "refusing to overwrite existing file" if upstream already has .github/CODEOWNERS (overwrite_on_create = false) → reject maintainers with fork_from, or skip the file for forks.
  • modules/github_org/variables.tf:115 — private is silently ignored when fork_from is set (visibility = null) → add a validation rejecting private = true with fork_from (gitea module does the same for conflicting attributes).
  • nit: modules/github_org/variables.tf:115 — adding fork_from to an existing non-fork repo is ForceNew (fork false→true) and archive_on_destroy makes the recreate fail on the name clash → note in the description that fork_from is create-time only.
- modules/github_org/modules/repository/main.tf:32 — `rename = true` against `default_branch` (default `main`) renames the fork's inherited default branch when the source uses another (e.g. `master`), diverging it from upstream → require `default_branch` to match the source (validate/document), or set `rename = local.fork_source == null` for forks. - modules/github_org/modules/repository/main.tf:58 — CODEOWNERS file on a fork fails with "refusing to overwrite existing file" if upstream already has `.github/CODEOWNERS` (`overwrite_on_create = false`) → reject `maintainers` with `fork_from`, or skip the file for forks. - modules/github_org/variables.tf:115 — `private` is silently ignored when `fork_from` is set (visibility = null) → add a validation rejecting `private = true` with `fork_from` (gitea module does the same for conflicting attributes). - nit: modules/github_org/variables.tf:115 — adding `fork_from` to an existing non-fork repo is ForceNew (`fork` false→true) and `archive_on_destroy` makes the recreate fail on the name clash → note in the description that `fork_from` is create-time only.
unkin-agent added 1 commit 2026-11-19 22:24:24 +11:00
keep fork default branch and CODEOWNERS, reject private forks
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/plan Pipeline was successful
361f34d820
Author
Member
  • modules/github_org/variables.tf:124 — private = false on a fork is accepted but silently ignored (visibility is null for forks), and the public test case locks that in → reject any non-null private when fork_from is set (repo.private != null) and drop private = false from the test.
  • modules/github_org/modules/repository/main.tf:12 — with visibility = null on a new fork the provider (v6.13.0 calculateVisibility) falls back to "public" and issues a visibility Edit after CreateFork; fine for a public source, fails for a private source → state in the PR body/README that fork_from must be a public repo, or confirm storytold/autocraft is public.
  • nit: README.md:37 — repository yaml keys are documented here; fork_from is not → add it.
- modules/github_org/variables.tf:124 — `private = false` on a fork is accepted but silently ignored (visibility is null for forks), and the `public` test case locks that in → reject any non-null `private` when `fork_from` is set (`repo.private != null`) and drop `private = false` from the test. - modules/github_org/modules/repository/main.tf:12 — with `visibility = null` on a new fork the provider (v6.13.0 `calculateVisibility`) falls back to "public" and issues a visibility Edit after CreateFork; fine for a public source, fails for a private source → state in the PR body/README that `fork_from` must be a public repo, or confirm storytold/autocraft is public. - nit: README.md:37 — repository yaml keys are documented here; `fork_from` is not → add it.
unkin-agent added 1 commit 2026-11-19 22:28:06 +11:00
reject private on forks and document fork_from public-upstream constraint
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/plan Pipeline was successful
bab6233613
Author
Member
  • README.md:48 — "Adding fork_from to an existing repository recreates it" is wrong in practice: fork false→true forces replacement, but archive_on_destroy = true only archives the old repo, so the new fork hits a name collision (GitHub suffixes the name, provider then drifts) → state that the existing repo must be deleted on GitHub (or state rm) before adding fork_from.
  • README.md:34 — block is labelled "every field, with defaults" and shows private: true, but the default is now unset (true only for non-forks) → annotate # default true; omit on forks.
- README.md:48 — "Adding `fork_from` to an existing repository recreates it" is wrong in practice: `fork` false→true forces replacement, but `archive_on_destroy = true` only archives the old repo, so the new fork hits a name collision (GitHub suffixes the name, provider then drifts) → state that the existing repo must be deleted on GitHub (or `state rm`) before adding `fork_from`. - README.md:34 — block is labelled "every field, with defaults" and shows `private: true`, but the default is now unset (true only for non-forks) → annotate `# default true; omit on forks`.
unkin-agent added 1 commit 2026-11-19 22:30:40 +11:00
document fork_from as create-only and private as unset by default
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/plan Pipeline was successful
1889c95a46
Author
Member

No findings.

No findings.
benvin merged commit c6ac6ba4ad into main 2026-11-19 22:48:36 +11:00
benvin deleted branch benvin/github-fork-support 2026-11-19 22:48:36 +11:00
This repo is archived. You cannot comment on pull requests.