Stop perpetual drift on mirrors and whitelist teams #122
@@ -73,5 +73,10 @@ pre-commit:
|
||||
test:
|
||||
@tofu -chdir=modules/github_org init -backend=false -input=false >/dev/null && \
|
||||
tofu -chdir=modules/github_org test
|
||||
@tofu -chdir=modules/gitea_instance/modules/repository init -backend=false -input=false >/dev/null && \
|
||||
tofu -chdir=modules/gitea_instance/modules/repository test
|
||||
@terragrunt render --working-dir environments/au/syd1 --json --out /dev/stdout 2>/dev/null | \
|
||||
python3 -c 'import json,sys; i=json.loads(sys.stdin.read().splitlines()[-1])["inputs"]; bad=[k for m in i.values() for k in m if k.startswith("github.com/")]; sys.exit(f"github.com config in gitea inputs: {bad}" if bad else 0)'
|
||||
@# Gitea silently drops whitelist teams without access to the repo, so they would drift on every apply.
|
||||
@terragrunt render --working-dir environments/au/syd1 --json --out /dev/stdout 2>/dev/null | \
|
||||
python3 -c 'import json,sys; i=json.loads(sys.stdin.read().splitlines()[-1])["inputs"]; t=i["team"]; ok=lambda b,n: (lambda m: m.get("include_all_repositories") or b["repository"] in (m.get("repositories") or []))(t.get(b["gitea_url"]+"/"+b["organisation"]+"/"+n, {})); bad=[k+": "+n for k,b in i["branch_protection"].items() for f in ("push","merge","approval") for n in b.get(f+"_whitelist_teams") or [] if not ok(b,n)]; sys.exit(f"whitelist teams without repo access: {bad}" if bad else 0)'
|
||||
|
||||
@@ -11,5 +11,4 @@ branch_protection:
|
||||
status_check_contexts:
|
||||
- "ci/woodpecker/pr/build"
|
||||
approval_whitelist_teams:
|
||||
- "docker"
|
||||
- "forgebot"
|
||||
|
||||
@@ -11,5 +11,4 @@ branch_protection:
|
||||
status_check_contexts:
|
||||
- "ci/woodpecker/pr/build"
|
||||
approval_whitelist_teams:
|
||||
- "docker"
|
||||
- "forgebot"
|
||||
|
||||
@@ -11,5 +11,4 @@ branch_protection:
|
||||
status_check_contexts:
|
||||
- "ci/woodpecker/pr/build"
|
||||
approval_whitelist_teams:
|
||||
- "docker"
|
||||
- "forgebot"
|
||||
|
||||
@@ -10,5 +10,3 @@ branch_protection:
|
||||
enable_push: false
|
||||
status_check_contexts:
|
||||
- "ci/woodpecker/pr/build"
|
||||
approval_whitelist_teams:
|
||||
- "docker"
|
||||
|
||||
@@ -10,5 +10,3 @@ branch_protection:
|
||||
enable_push: false
|
||||
status_check_contexts:
|
||||
- "ci/woodpecker/pr/build"
|
||||
approval_whitelist_teams:
|
||||
- "docker"
|
||||
|
||||
@@ -1,28 +1,31 @@
|
||||
locals {
|
||||
fork_source = var.fork_from == null ? null : split("/", var.fork_from)
|
||||
# Gitea stores merge settings in the pull-request unit; without it they read back false.
|
||||
no_prs = var.has_pull_requests == false
|
||||
}
|
||||
|
||||
resource "gitea_repository" "this" {
|
||||
count = var.fork_from == null ? 1 : 0
|
||||
|
||||
username = var.organisation
|
||||
name = var.name
|
||||
description = var.description
|
||||
private = var.private
|
||||
default_branch = var.default_branch
|
||||
has_issues = var.has_issues
|
||||
has_wiki = var.has_wiki
|
||||
has_pull_requests = var.has_pull_requests
|
||||
has_projects = var.has_projects
|
||||
allow_merge_commits = var.allow_merge_commits
|
||||
allow_rebase = var.allow_rebase
|
||||
allow_rebase_explicit = var.allow_rebase_explicit
|
||||
allow_squash_merge = var.allow_squash_merge
|
||||
archived = var.archived
|
||||
repo_template = var.repo_template
|
||||
website = var.website
|
||||
autodetect_manual_merge = var.autodetect_manual_merge
|
||||
archive_on_destroy = true
|
||||
username = var.organisation
|
||||
name = var.name
|
||||
description = var.description
|
||||
private = var.private
|
||||
default_branch = var.default_branch
|
||||
has_issues = var.has_issues
|
||||
has_wiki = var.has_wiki
|
||||
has_pull_requests = var.has_pull_requests
|
||||
has_projects = var.has_projects
|
||||
allow_merge_commits = local.no_prs ? false : var.allow_merge_commits
|
||||
allow_rebase = local.no_prs ? false : var.allow_rebase
|
||||
allow_rebase_explicit = local.no_prs ? false : var.allow_rebase_explicit
|
||||
allow_squash_merge = local.no_prs ? false : var.allow_squash_merge
|
||||
ignore_whitespace_conflicts = local.no_prs ? false : null
|
||||
archived = var.archived
|
||||
repo_template = var.repo_template
|
||||
website = var.website
|
||||
autodetect_manual_merge = var.autodetect_manual_merge
|
||||
archive_on_destroy = true
|
||||
|
||||
mirror = var.mirror
|
||||
migration_clone_address = var.migration_clone_address
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
mock_provider "gitea" {}
|
||||
|
||||
variables {
|
||||
name = "example"
|
||||
organisation = "unkin"
|
||||
}
|
||||
|
||||
run "no_pull_requests_disables_merge_settings" {
|
||||
command = plan
|
||||
|
||||
variables {
|
||||
has_pull_requests = false
|
||||
allow_merge_commits = true
|
||||
allow_squash_merge = true
|
||||
}
|
||||
|
||||
assert {
|
||||
condition = !anytrue([
|
||||
gitea_repository.this[0].allow_merge_commits,
|
||||
gitea_repository.this[0].allow_rebase,
|
||||
gitea_repository.this[0].allow_rebase_explicit,
|
||||
gitea_repository.this[0].allow_squash_merge,
|
||||
gitea_repository.this[0].ignore_whitespace_conflicts,
|
||||
])
|
||||
error_message = "merge settings must be false when the pull-request unit is disabled"
|
||||
}
|
||||
}
|
||||
|
||||
run "pull_requests_keep_merge_settings" {
|
||||
command = plan
|
||||
|
||||
variables {
|
||||
allow_merge_commits = true
|
||||
}
|
||||
|
||||
assert {
|
||||
condition = gitea_repository.this[0].allow_merge_commits && gitea_repository.this[0].allow_squash_merge
|
||||
error_message = "merge settings must pass through when pull requests are enabled"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user