Skip to content

Commit 374aae8

Browse files
committed
Remove DRY schema
Signed-off-by: Timo Sand <[email protected]>
1 parent f3607cc commit 374aae8

3 files changed

Lines changed: 84 additions & 48 deletions

File tree

github/resource_github_organization_ruleset.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,48 @@ func resourceGithubOrganizationRuleset() *schema.Resource {
249249
Default: false,
250250
Description: "All conversations on code must be resolved before a pull request can be merged. Defaults to `false`.",
251251
},
252-
"required_reviewers": requiredReviewersSchema(),
252+
"required_reviewers": {
253+
Type: schema.TypeList,
254+
Optional: true,
255+
Description: "Require specific reviewers to approve pull requests targeting matching branches. Note: This feature is in beta and subject to change.",
256+
Elem: &schema.Resource{
257+
Schema: map[string]*schema.Schema{
258+
"reviewer": {
259+
Type: schema.TypeList,
260+
Required: true,
261+
MaxItems: 1,
262+
Description: "The reviewer that must review matching files.",
263+
Elem: &schema.Resource{
264+
Schema: map[string]*schema.Schema{
265+
"id": {
266+
Type: schema.TypeInt,
267+
Required: true,
268+
Description: "The ID of the reviewer that must review.",
269+
},
270+
"type": {
271+
Type: schema.TypeString,
272+
Required: true,
273+
ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"Team"}, false), "type"),
274+
Description: "The type of reviewer. Currently only `Team` is supported.",
275+
},
276+
},
277+
},
278+
},
279+
"file_patterns": {
280+
Type: schema.TypeList,
281+
Required: true,
282+
MinItems: 1,
283+
Description: "File patterns (fnmatch syntax) that this reviewer must approve.",
284+
Elem: &schema.Schema{Type: schema.TypeString},
285+
},
286+
"minimum_approvals": {
287+
Type: schema.TypeInt,
288+
Required: true,
289+
Description: "Minimum number of approvals required from this reviewer. Set to 0 to make approval optional.",
290+
},
291+
},
292+
},
293+
},
253294
},
254295
},
255296
},

github/resource_github_repository_ruleset.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,48 @@ func resourceGithubRepositoryRuleset() *schema.Resource {
236236
Default: false,
237237
Description: "All conversations on code must be resolved before a pull request can be merged. Defaults to `false`.",
238238
},
239-
"required_reviewers": requiredReviewersSchema(),
239+
"required_reviewers": {
240+
Type: schema.TypeList,
241+
Optional: true,
242+
Description: "Require specific reviewers to approve pull requests targeting matching branches. Note: This feature is in beta and subject to change.",
243+
Elem: &schema.Resource{
244+
Schema: map[string]*schema.Schema{
245+
"reviewer": {
246+
Type: schema.TypeList,
247+
Required: true,
248+
MaxItems: 1,
249+
Description: "The reviewer that must review matching files.",
250+
Elem: &schema.Resource{
251+
Schema: map[string]*schema.Schema{
252+
"id": {
253+
Type: schema.TypeInt,
254+
Required: true,
255+
Description: "The ID of the reviewer that must review.",
256+
},
257+
"type": {
258+
Type: schema.TypeString,
259+
Required: true,
260+
ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"Team"}, false), "type"),
261+
Description: "The type of reviewer. Currently only `Team` is supported.",
262+
},
263+
},
264+
},
265+
},
266+
"file_patterns": {
267+
Type: schema.TypeList,
268+
Required: true,
269+
MinItems: 1,
270+
Description: "File patterns (fnmatch syntax) that this reviewer must approve.",
271+
Elem: &schema.Schema{Type: schema.TypeString},
272+
},
273+
"minimum_approvals": {
274+
Type: schema.TypeInt,
275+
Required: true,
276+
Description: "Minimum number of approvals required from this reviewer. Set to 0 to make approval optional.",
277+
},
278+
},
279+
},
280+
},
240281
},
241282
},
242283
},

github/util_rules.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,8 @@ import (
88
"github.com/google/go-github/v82/github"
99
"github.com/hashicorp/terraform-plugin-log/tflog"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1211
)
1312

14-
func requiredReviewersSchema() *schema.Schema {
15-
return &schema.Schema{
16-
Type: schema.TypeList,
17-
Optional: true,
18-
Description: "Require specific reviewers to approve pull requests targeting matching branches. Note: This feature is in beta and subject to change.",
19-
Elem: &schema.Resource{
20-
Schema: map[string]*schema.Schema{
21-
"reviewer": {
22-
Type: schema.TypeList,
23-
Required: true,
24-
MaxItems: 1,
25-
Description: "The reviewer that must review matching files.",
26-
Elem: &schema.Resource{
27-
Schema: map[string]*schema.Schema{
28-
"id": {
29-
Type: schema.TypeInt,
30-
Required: true,
31-
Description: "The ID of the reviewer that must review.",
32-
},
33-
"type": {
34-
Type: schema.TypeString,
35-
Required: true,
36-
ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"Team"}, false), "type"),
37-
Description: "The type of reviewer. Currently only `Team` is supported.",
38-
},
39-
},
40-
},
41-
},
42-
"file_patterns": {
43-
Type: schema.TypeList,
44-
Required: true,
45-
MinItems: 1,
46-
Description: "File patterns (fnmatch syntax) that this reviewer must approve.",
47-
Elem: &schema.Schema{Type: schema.TypeString},
48-
},
49-
"minimum_approvals": {
50-
Type: schema.TypeInt,
51-
Required: true,
52-
Description: "Minimum number of approvals required from this reviewer. Set to 0 to make approval optional.",
53-
},
54-
},
55-
},
56-
}
57-
}
58-
5913
// Helper function to safely convert interface{} to int, handling both int and float64.
6014
func toInt(v any) int {
6115
switch val := v.(type) {

0 commit comments

Comments
 (0)