From 4b779444f21a6f66230140ffcf3cc25721c65a9b Mon Sep 17 00:00:00 2001 From: Lucas Ventura Date: Mon, 13 Jan 2025 20:05:24 -0300 Subject: [PATCH] Adds do_not_enforce_on_create option for github_repository_ruleset (#2525) Co-authored-by: Keegan Campbell --- github/resource_github_repository_ruleset.go | 6 ++++++ github/resource_github_repository_ruleset_test.go | 2 ++ github/respository_rules_utils.go | 3 +++ website/docs/r/repository_ruleset.html.markdown | 2 ++ 4 files changed, 13 insertions(+) diff --git a/github/resource_github_repository_ruleset.go b/github/resource_github_repository_ruleset.go index e1bc9fc3ac..5fe4c2b37a 100644 --- a/github/resource_github_repository_ruleset.go +++ b/github/resource_github_repository_ruleset.go @@ -249,6 +249,12 @@ func resourceGithubRepositoryRuleset() *schema.Resource { Optional: true, Description: "Whether pull requests targeting a matching branch must be tested with the latest code. This setting will not take effect unless at least one status check is enabled. Defaults to `false`.", }, + "do_not_enforce_on_create": { + Type: schema.TypeBool, + Optional: true, + Description: "Allow repositories and branches to be created if a check would otherwise prohibit it.", + Default: false, + }, }, }, }, diff --git a/github/resource_github_repository_ruleset_test.go b/github/resource_github_repository_ruleset_test.go index a51682507f..35bc80fbd1 100644 --- a/github/resource_github_repository_ruleset_test.go +++ b/github/resource_github_repository_ruleset_test.go @@ -70,6 +70,7 @@ func TestGithubRepositoryRulesets(t *testing.T) { } strict_required_status_checks_policy = true + do_not_enforce_on_create = true } non_fast_forward = true @@ -319,6 +320,7 @@ func TestGithubRepositoryRulesets(t *testing.T) { } strict_required_status_checks_policy = true + do_not_enforce_on_create = true } non_fast_forward = true diff --git a/github/respository_rules_utils.go b/github/respository_rules_utils.go index cfb8ceb462..9d95161752 100644 --- a/github/respository_rules_utils.go +++ b/github/respository_rules_utils.go @@ -324,9 +324,11 @@ func expandRules(input []interface{}, org bool) []*github.RepositoryRule { } } + doNotEnforceOnCreate := requiredStatusMap["do_not_enforce_on_create"].(bool) params := &github.RequiredStatusChecksRuleParameters{ RequiredStatusChecks: requiredStatusChecks, StrictRequiredStatusChecksPolicy: requiredStatusMap["strict_required_status_checks_policy"].(bool), + DoNotEnforceOnCreate: &doNotEnforceOnCreate, } rulesSlice = append(rulesSlice, github.NewRequiredStatusChecksRule(params)) } @@ -503,6 +505,7 @@ func flattenRules(rules []*github.RepositoryRule, org bool) []interface{} { rule := make(map[string]interface{}) rule["required_check"] = requiredStatusChecksSlice rule["strict_required_status_checks_policy"] = params.StrictRequiredStatusChecksPolicy + rule["do_not_enforce_on_create"] = params.DoNotEnforceOnCreate rulesMap[v.Type] = []map[string]interface{}{rule} } } diff --git a/website/docs/r/repository_ruleset.html.markdown b/website/docs/r/repository_ruleset.html.markdown index c26d5759ef..09ff72ee1c 100644 --- a/website/docs/r/repository_ruleset.html.markdown +++ b/website/docs/r/repository_ruleset.html.markdown @@ -175,6 +175,8 @@ The `rules` block supports the following: * `strict_required_status_checks_policy` - (Optional) (Boolean) Whether pull requests targeting a matching branch must be tested with the latest code. This setting will not take effect unless at least one status check is enabled. Defaults to `false`. +* `do_not_enforce_on_create` - (Optional) (Boolean) Allow repositories and branches to be created if a check would otherwise prohibit it. Defaults to `false`. + #### rules.required_status_checks.required_check #### * `context` - (Required) (String) The status check context name that must be present on the commit.