Block + ref components on public GitHub repos
This commit is contained in:
@@ -34,8 +34,19 @@ run "public_repo_defaults" {
|
||||
}
|
||||
|
||||
assert {
|
||||
condition = keys(module.repository[".github"].rulesets) == ["branch-protection", "tag-protection"] && length(module.team["maintainers"].membership) == 2
|
||||
error_message = "public repo must get only the generated branch-protection and tag-protection rulesets"
|
||||
condition = keys(module.repository[".github"].rulesets) == ["branch-protection", "ref-names-branch", "ref-names-tag", "tag-protection"] && length(module.team["maintainers"].membership) == 2
|
||||
error_message = "public repo must get only the generated branch-protection, ref-names and tag-protection rulesets"
|
||||
}
|
||||
|
||||
assert {
|
||||
condition = alltrue([for t, prefix in { branch = "refs/heads", tag = "refs/tags" } : (
|
||||
module.repository[".github"].rulesets["ref-names-${t}"].target == t &&
|
||||
module.repository[".github"].rulesets["ref-names-${t}"].enforcement == "active" &&
|
||||
module.repository[".github"].rulesets["ref-names-${t}"].conditions[0].ref_name[0].include == tolist(["${prefix}/**/+", "${prefix}/**/+/**/*"]) &&
|
||||
module.repository[".github"].rulesets["ref-names-${t}"].rules[0].creation &&
|
||||
!module.repository[".github"].rulesets["ref-names-${t}"].rules[0].deletion
|
||||
)])
|
||||
error_message = "ref-names rulesets must block creating branches and tags with a + path component"
|
||||
}
|
||||
|
||||
assert {
|
||||
@@ -115,8 +126,8 @@ run "generated_and_custom_rulesets" {
|
||||
}
|
||||
|
||||
assert {
|
||||
condition = toset(keys(module.repository["checked"].rulesets)) == toset(["required-checks", "signed"])
|
||||
error_message = "required_checks with protections off yields only required-checks plus custom rulesets"
|
||||
condition = toset(keys(module.repository["checked"].rulesets)) == toset(["required-checks", "ref-names-branch", "ref-names-tag", "signed"])
|
||||
error_message = "required_checks with protections off yields only required-checks, ref-names plus custom rulesets"
|
||||
}
|
||||
|
||||
assert {
|
||||
@@ -152,7 +163,7 @@ run "public_tag_protection_only" {
|
||||
}
|
||||
|
||||
assert {
|
||||
condition = keys(module.repository["tags"].rulesets) == ["tag-protection"]
|
||||
condition = keys(module.repository["tags"].rulesets) == ["ref-names-branch", "ref-names-tag", "tag-protection"]
|
||||
error_message = "tag_protection defaults on for public repos independently of branch_protection"
|
||||
}
|
||||
}
|
||||
@@ -219,6 +230,19 @@ run "reserved_ruleset_name_rejected" {
|
||||
expect_failures = [var.ruleset]
|
||||
}
|
||||
|
||||
run "reserved_ref_names_rejected" {
|
||||
command = plan
|
||||
|
||||
variables {
|
||||
ruleset = {
|
||||
ref-names-tag = { name = "ref-names-tag", target = "tag", rules = { deletion = true } }
|
||||
}
|
||||
repository = {}
|
||||
}
|
||||
|
||||
expect_failures = [var.ruleset]
|
||||
}
|
||||
|
||||
run "unknown_ruleset_rejected" {
|
||||
command = plan
|
||||
|
||||
|
||||
Reference in New Issue
Block a user