From bab6233613c40f206caab59bc05fccb52bec7acf Mon Sep 17 00:00:00 2001 From: unkin-agent Date: Thu, 19 Nov 2026 22:28:01 +1100 Subject: [PATCH] reject private on forks and document fork_from public-upstream constraint --- README.md | 3 +++ modules/github_org/tests/github_org.tftest.hcl | 13 ++++++++++++- modules/github_org/variables.tf | 8 ++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 401d911..cb0850b 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,11 @@ merge_type: squash # squash | merge | rebase delete_branch_on_merge: true rulesets: [] # opt-in rulesets from ruleset/ exclude_rulesets: [] # opt out of non-mandatory all_repos rulesets +fork_from: null # owner/repo: fork a public upstream (see below) ``` +`fork_from: owner/repo` creates the repository as a fork of a public upstream. Visibility follows the source, so `private` must be omitted. `default_branch` must match the upstream default branch. Adding `fork_from` to an existing repository recreates it. + `ruleset/.yaml`: ```yaml diff --git a/modules/github_org/tests/github_org.tftest.hcl b/modules/github_org/tests/github_org.tftest.hcl index 1b72dc2..ef329fc 100644 --- a/modules/github_org/tests/github_org.tftest.hcl +++ b/modules/github_org/tests/github_org.tftest.hcl @@ -119,7 +119,6 @@ run "fork_from_source" { autocraft = { name = "autocraft", fork_from = "storytold/autocraft", maintainers = ["@maintainers"] } plain = { name = "plain" } secret = { name = "secret", maintainers = ["@maintainers"] } - public = { name = "public", private = false, fork_from = "storytold/public" } } } @@ -176,6 +175,18 @@ run "private_fork_rejected" { expect_failures = [var.repository] } +run "public_fork_rejected" { + command = plan + + variables { + repository = { + bad = { name = "bad", fork_from = "storytold/autocraft", private = false } + } + } + + expect_failures = [var.repository] +} + run "invalid_fork_from_rejected" { command = plan diff --git a/modules/github_org/variables.tf b/modules/github_org/variables.tf index e6f6cca..95297bd 100644 --- a/modules/github_org/variables.tf +++ b/modules/github_org/variables.tf @@ -96,7 +96,7 @@ variable "ruleset" { } variable "repository" { - description = "Map of repositories to create, keyed by name" + description = "Map of repositories to create, keyed by name; fork_from (owner/repo) forks a public upstream and requires private to be omitted" type = map(object({ name = string description = optional(string, "") @@ -114,12 +114,12 @@ variable "repository" { validation { condition = alltrue([for repo in var.repository : repo.fork_from == null || can(regex("^[^/]+/[^/]+$", repo.fork_from))]) - error_message = "fork_from must be \"/\": ${join(", ", [for name, repo in var.repository : name if repo.fork_from != null && !can(regex("^[^/]+/[^/]+$", coalesce(repo.fork_from, "-")))])}." + error_message = "fork_from must be \"/\" of a public upstream: ${join(", ", [for name, repo in var.repository : name if repo.fork_from != null && !can(regex("^[^/]+/[^/]+$", coalesce(repo.fork_from, "-")))])}." } validation { - condition = alltrue([for repo in var.repository : !(repo.fork_from != null && repo.private == true)]) - error_message = "private cannot be set on a fork, its visibility follows the source: ${join(", ", [for name, repo in var.repository : name if repo.fork_from != null && repo.private == true])}." + condition = alltrue([for repo in var.repository : repo.fork_from == null || repo.private == null]) + error_message = "private cannot be set on a fork, its visibility follows the source and only public upstreams can be forked: ${join(", ", [for name, repo in var.repository : name if repo.fork_from != null && repo.private != null])}." } validation {