Skip to content

Commit

Permalink
feat: add ruleset option do_not_enforce_on_create
Browse files Browse the repository at this point in the history
Optional attribute added to rules.required_status_checks.
  • Loading branch information
MattMencel committed Aug 22, 2024
1 parent c3b7085 commit 2404cf7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions github/resource_github_repository_ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ func resourceGithubRepositoryRuleset() *schema.Resource {
},
},
},
"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.",
},
"strict_required_status_checks_policy": {
Type: schema.TypeBool,
Optional: true,
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 @@ -64,6 +64,7 @@ func TestGithubRepositoryRulesets(t *testing.T) {
}
required_status_checks {
do_not_enforce_on_create = true
required_check {
context = "ci"
Expand Down Expand Up @@ -313,6 +314,7 @@ func TestGithubRepositoryRulesets(t *testing.T) {
}
required_status_checks {
do_not_enforce_on_create = true
required_check {
context = "ci"
Expand Down
2 changes: 2 additions & 0 deletions github/respository_rules_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ func expandRules(input []interface{}, org bool) []*github.RepositoryRule {
}

params := &github.RequiredStatusChecksRuleParameters{
DoNotEnforceOnCreate: requiredStatusMap["do_not_enforce_on_create"].(bool),
RequiredStatusChecks: requiredStatusChecks,
StrictRequiredStatusChecksPolicy: requiredStatusMap["strict_required_status_checks_policy"].(bool),
}
Expand Down Expand Up @@ -469,6 +470,7 @@ func flattenRules(rules []*github.RepositoryRule, org bool) []interface{} {
}

rule := make(map[string]interface{})
rule["do_not_enforce_on_create"] = params.DoNotEnforceOnCreate
rule["required_check"] = requiredStatusChecksSlice
rule["strict_required_status_checks_policy"] = params.StrictRequiredStatusChecksPolicy
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 @@ -169,6 +169,8 @@ The `rules` block supports the following:

#### rules.required_status_checks ####

* `do_not_enforce_on_create` - (Optional) (Boolean) Allow repositories and branches to be created if a check would otherwise prohibit it. Defaults to `false`.

* `required_check` - (Required) (Block Set, Min: 1) Status checks that are required. Several can be defined. (see [below for nested schema](#rules.required_status_checks.required_check))

* `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`.
Expand Down

0 comments on commit 2404cf7

Please sign in to comment.