keep fork default branch and CODEOWNERS, reject private forks
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user