Skip to content

Commit 40c5111

Browse files
committed
flatten conditions for repository_property and fix schemas
1 parent 33d3f78 commit 40c5111

File tree

3 files changed

+27
-77
lines changed

3 files changed

+27
-77
lines changed

examples/github_organization_ruleset/main.tf

Lines changed: 0 additions & 61 deletions
This file was deleted.

github/resource_github_organization_ruleset.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,10 @@ func resourceGithubOrganizationRuleset() *schema.Resource {
113113
},
114114
},
115115
"repository_property": {
116-
Type: schema.TypeList,
117-
Optional: true,
118-
MaxItems: 1,
119-
ExactlyOneOf: []string{"conditions.0.repository_id"},
120-
AtLeastOneOf: []string{"conditions.0.repository_id"},
121-
Description: "Conditions to target repositories by property ",
116+
Type: schema.TypeList,
117+
Optional: true,
118+
MaxItems: 1,
119+
Description: "Conditions to target repositories by property ",
122120
Elem: &schema.Resource{
123121
Schema: map[string]*schema.Schema{
124122
"include": {
@@ -143,6 +141,7 @@ func resourceGithubOrganizationRuleset() *schema.Resource {
143141
},
144142
"source": {
145143
Type: schema.TypeString,
144+
Optional: true,
146145
Description: "The source of the repository property. Defaults to 'custom' if not specified.Can be one of: custom, system",
147146
Default: "custom",
148147
},
@@ -168,24 +167,27 @@ func resourceGithubOrganizationRuleset() *schema.Resource {
168167
AtLeastOneOf: []string{"conditions.0.repository_id"},
169168
Elem: &schema.Resource{
170169
Schema: map[string]*schema.Schema{
171-
172-
"name": {
173-
Type: schema.TypeString,
170+
"include": {
171+
Type: schema.TypeList,
174172
Required: true,
175-
Description: "The name of the repository property to target",
173+
Description: "Array of repository names or patterns to include. One of these patterns must match for the condition to pass. Also accepts `~ALL` to include all repositories.",
174+
Elem: &schema.Schema{
175+
Type: schema.TypeString,
176+
},
176177
},
177-
"property_values": {
178+
"exclude": {
178179
Type: schema.TypeList,
179180
Required: true,
180-
Description: "The values to match for the repository property.",
181+
Description: "Array of repository names or patterns to exclude. The condition will not pass if any of these patterns match.",
181182
Elem: &schema.Schema{
182183
Type: schema.TypeString,
183184
},
184185
},
185-
"source": {
186-
Type: schema.TypeString,
187-
Description: "The source of the repository property. Defaults to 'custom' if not specified.Can be one of: custom, system",
188-
Default: "custom",
186+
"protected": {
187+
Type: schema.TypeBool,
188+
Optional: true,
189+
Default: false,
190+
Description: "Whether renaming of target repositories is prevented.",
189191
},
190192
},
191193
},

github/respository_rules_utils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ func flattenConditions(conditions *github.RulesetConditions, org bool) []interfa
226226
if conditions.RepositoryID != nil {
227227
conditionsMap["repository_id"] = conditions.RepositoryID.RepositoryIDs
228228
}
229+
if conditions.RepositoryProperty != nil {
230+
repositoryPropertySlice := make([]map[string]interface{}, 0)
231+
232+
repositoryPropertySlice = append(repositoryPropertySlice, map[string]interface{}{
233+
"include": conditions.RepositoryProperty.Include,
234+
"exclude": conditions.RepositoryProperty.Exclude,
235+
})
236+
conditionsMap["repository_property"] = repositoryPropertySlice
237+
}
229238
}
230239

231240
return []interface{}{conditionsMap}

0 commit comments

Comments
 (0)