keep fork default branch and CODEOWNERS, reject private forks
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/plan Pipeline was successful

This commit is contained in:
2026-11-19 22:24:19 +11:00
parent 3198f8d5d1
commit 361f34d820
4 changed files with 48 additions and 12 deletions
+10 -9
View File
@@ -10,7 +10,7 @@ resource "github_repository" "this" {
name = var.config.name
description = var.config.description
# a fork's visibility follows its source and cannot be changed
visibility = local.fork_source == null ? (var.config.private ? "private" : "public") : null
visibility = local.fork_source == null ? (coalesce(var.config.private, true) ? "private" : "public") : null
has_issues = true
has_wiki = false
has_projects = false
@@ -28,8 +28,8 @@ resource "github_repository" "this" {
resource "github_branch_default" "this" {
repository = github_repository.this.name
branch = var.config.default_branch
# auto_init only creates main; rename it instead of pointing at a missing branch
rename = true
# auto_init only creates main so rename it; a fork must select an existing branch
rename = local.fork_source == null
wait_for_rename = true
}
@@ -58,12 +58,13 @@ resource "github_repository_collaborators" "this" {
resource "github_repository_file" "codeowners" {
count = length(var.config.maintainers) > 0 ? 1 : 0
repository = github_repository.this.name
branch = github_branch_default.this.branch
file = ".github/CODEOWNERS"
content = "* ${join(" ", [for e in var.config.maintainers : startswith(e, "@") ? "@${var.owner}/${var.team_slugs[trimprefix(e, "@")]}" : "@${e}"])}\n"
commit_message = "add initial CODEOWNERS"
overwrite_on_create = false
repository = github_repository.this.name
branch = github_branch_default.this.branch
file = ".github/CODEOWNERS"
content = "* ${join(" ", [for e in var.config.maintainers : startswith(e, "@") ? "@${var.owner}/${var.team_slugs[trimprefix(e, "@")]}" : "@${e}"])}\n"
commit_message = "add initial CODEOWNERS"
# a fork may inherit the upstream CODEOWNERS; ours must win for code-owner rulesets
overwrite_on_create = local.fork_source != null
lifecycle {
ignore_changes = [content]
@@ -6,7 +6,7 @@ variable "config" {
type = object({
name = string
description = string
private = bool
private = optional(bool)
default_branch = string
maintainers = list(string)
codeowners = list(string)