diff --git a/github/respository_rules_utils.go b/github/respository_rules_utils.go index 7d3b3b33b..0420d525d 100644 --- a/github/respository_rules_utils.go +++ b/github/respository_rules_utils.go @@ -658,6 +658,28 @@ func flattenRules(rules []*github.RepositoryRule, org bool) []any { rule["min_entries_to_merge_wait_minutes"] = params.MinEntriesToMergeWaitMinutes rulesMap[v.Type] = []map[string]any{rule} + case "required_code_scanning": + var params github.RequiredCodeScanningRuleParameters + + err := json.Unmarshal(*v.Parameters, ¶ms) + if err != nil { + log.Printf("[INFO] Unexpected error unmarshalling rule %s with parameters: %v", + v.Type, v.Parameters) + } + + requiredCodeScanningToolSlice := make([]map[string]any, 0) + for _, tool := range params.RequiredCodeScanningTools { + requiredCodeScanningToolSlice = append(requiredCodeScanningToolSlice, map[string]any{ + "alerts_threshold": tool.AlertsThreshold, + "security_alerts_threshold": tool.SecurityAlertsThreshold, + "tool": tool.Tool, + }) + } + + rule := make(map[string]any) + rule["required_code_scanning_tool"] = requiredCodeScanningToolSlice + rulesMap[v.Type] = []map[string]any{rule} + case "file_path_restriction": var params github.RuleFileParameters err := json.Unmarshal(*v.Parameters, ¶ms) diff --git a/website/docs/r/organization_ruleset.html.markdown b/website/docs/r/organization_ruleset.html.markdown index 8a114739d..e04118f67 100644 --- a/website/docs/r/organization_ruleset.html.markdown +++ b/website/docs/r/organization_ruleset.html.markdown @@ -54,6 +54,14 @@ resource "github_organization_ruleset" "example" { ref = "main" } } + + required_code_scanning { + required_code_scanning_tool { + alerts_threshold = "errors" + security_alerts_threshold = "high_or_higher" + tool = "CodeQL" + } + } } } diff --git a/website/docs/r/repository_ruleset.html.markdown b/website/docs/r/repository_ruleset.html.markdown index 27c95547b..277582d58 100644 --- a/website/docs/r/repository_ruleset.html.markdown +++ b/website/docs/r/repository_ruleset.html.markdown @@ -49,7 +49,13 @@ resource "github_repository_ruleset" "example" { required_deployment_environments = ["test"] } - + required_code_scanning { + required_code_scanning_tool { + alerts_threshold = "errors" + security_alerts_threshold = "high_or_higher" + tool = "CodeQL" + } + } } }