Skip to content

Commit

Permalink
Adds do_not_enforce_on_create option for github_repository_ruleset (#…
Browse files Browse the repository at this point in the history
…2525)

Co-authored-by: Keegan Campbell <me@kfcampbell.com>
  • Loading branch information
lfventura and kfcampbell authored Jan 13, 2025
1 parent dead927 commit 4b77944
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions github/resource_github_repository_ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions github/resource_github_repository_ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions github/respository_rules_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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}
}
}
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/repository_ruleset.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4b77944

Please sign in to comment.