Add fork_from to repository config
ci/woodpecker/pr/plan Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful

Express a fork as an optional fork_from key on the repository yaml, so a
forked repo is declared the same way as any other repo.

- add fork_from "<owner>/<repo>" to the repository module and object type
- create gitea_fork instead of gitea_repository when fork_from is set
- validate the source repo name matches the config file name, since a fork
  inherits the source name
- move gitea_repository.this to index 0 for the count refactor
- index existing repository import targets to match
This commit is contained in:
2026-09-19 15:55:12 +10:00
parent 66823a939a
commit 9ab540719e
6 changed files with 72 additions and 35 deletions
@@ -1,4 +1,10 @@
locals {
fork_source = var.fork_from == null ? null : split("/", var.fork_from)
}
resource "gitea_repository" "this" {
count = var.fork_from == null ? 1 : 0
username = var.organisation
name = var.name
description = var.description
@@ -33,3 +39,16 @@ resource "gitea_repository" "this" {
ignore_changes = [migration_mirror_interval]
}
}
moved {
from = gitea_repository.this
to = gitea_repository.this[0]
}
resource "gitea_fork" "this" {
count = var.fork_from == null ? 0 : 1
owner = local.fork_source[0]
repo = local.fork_source[1]
organization = var.organisation
}
@@ -1,3 +1,3 @@
output "id" {
value = gitea_repository.this.id
value = one(concat(gitea_repository.this[*].id, gitea_fork.this[*].id))
}
@@ -6,6 +6,22 @@ variable "organisation" {
type = string
}
variable "fork_from" {
description = "Source repository to fork, as \"<owner>/<repo>\". When set, a fork is created instead of a new repository."
type = string
default = null
validation {
condition = var.fork_from == null || can(regex("^[^/]+/[^/]+$", var.fork_from))
error_message = "fork_from must be \"<owner>/<repo>\"."
}
validation {
condition = var.fork_from == null || try(split("/", var.fork_from)[1], null) == var.name
error_message = "fork_from source repository must be named \"${var.name}\": a fork inherits the source name, so it cannot differ from the config file name."
}
}
variable "description" {
type = string
default = null