Skip to content

Commit 7a98de4

Browse files
committed
Define schema for repository_property
1 parent f3792c8 commit 7a98de4

File tree

3 files changed

+116
-8
lines changed

3 files changed

+116
-8
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
resource "github_organization_ruleset" "protect_branch" {
2+
enforcement = "active"
3+
name = "Protect Master Branch (Beta)"
4+
target = "branch"
5+
conditions {
6+
repository_property {
7+
exclude = []
8+
include = [
9+
{
10+
name = "visibility"
11+
value = "public"
12+
}
13+
]
14+
}
15+
ref_name {
16+
exclude = []
17+
include = [
18+
"~DEFAULT_BRANCH",
19+
]
20+
}
21+
}
22+
rules {
23+
creation = false
24+
deletion = true
25+
non_fast_forward = true
26+
required_linear_history = false
27+
required_signatures = false
28+
update = false
29+
30+
pull_request {
31+
dismiss_stale_reviews_on_push = true
32+
require_code_owner_review = true
33+
require_last_push_approval = true
34+
required_approving_review_count = 1
35+
required_review_thread_resolution = false
36+
}
37+
38+
required_status_checks {
39+
strict_required_status_checks_policy = false
40+
41+
required_check {
42+
context = "SonarQube Code Analysis"
43+
integration_id = 0
44+
}
45+
}
46+
47+
required_workflows {
48+
required_workflow {
49+
repository_id = "442515790"
50+
path = ".github/workflows/trivy-scan-pr-commit.yml"
51+
ref = "refs/heads/master"
52+
}
53+
required_workflow {
54+
repository_id = "442515790"
55+
path = ".github/workflows/required_neodora.yml"
56+
ref = "refs/heads/master"
57+
}
58+
}
59+
60+
}
61+
}

github/resource_github_organization_ruleset.go

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,41 @@ func resourceGithubOrganizationRuleset() *schema.Resource {
112112
},
113113
},
114114
},
115-
"repository_name": {
115+
"repository_property": {
116116
Type: schema.TypeList,
117117
Optional: true,
118118
MaxItems: 1,
119119
ExactlyOneOf: []string{"conditions.0.repository_id"},
120120
AtLeastOneOf: []string{"conditions.0.repository_id"},
121+
Description: "Conditions to target repositories by property ",
121122
Elem: &schema.Resource{
122123
Schema: map[string]*schema.Schema{
123124
"include": {
124125
Type: schema.TypeList,
125126
Required: true,
126127
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.",
127-
Elem: &schema.Schema{
128-
Type: schema.TypeString,
128+
Elem: &schema.Resource{
129+
Schema: map[string]*schema.Schema{
130+
131+
"name": {
132+
Type: schema.TypeString,
133+
Required: true,
134+
Description: "The name of the repository property to target",
135+
},
136+
"property_values": {
137+
Type: schema.TypeList,
138+
Required: true,
139+
Description: "The values to match for the repository property.",
140+
Elem: &schema.Schema{
141+
Type: schema.TypeString,
142+
},
143+
},
144+
"source": {
145+
Type: schema.TypeString,
146+
Description: "The source of the repository property. Defaults to 'custom' if not specified.Can be one of: custom, system",
147+
Default: "custom",
148+
},
149+
},
129150
},
130151
},
131152
"exclude": {
@@ -136,11 +157,35 @@ func resourceGithubOrganizationRuleset() *schema.Resource {
136157
Type: schema.TypeString,
137158
},
138159
},
139-
"protected": {
140-
Type: schema.TypeBool,
141-
Optional: true,
142-
Default: false,
143-
Description: "Whether renaming of target repositories is prevented.",
160+
},
161+
},
162+
},
163+
"repository_name": {
164+
Type: schema.TypeList,
165+
Optional: true,
166+
MaxItems: 1,
167+
ExactlyOneOf: []string{"conditions.0.repository_id"},
168+
AtLeastOneOf: []string{"conditions.0.repository_id"},
169+
Elem: &schema.Resource{
170+
Schema: map[string]*schema.Schema{
171+
172+
"name": {
173+
Type: schema.TypeString,
174+
Required: true,
175+
Description: "The name of the repository property to target",
176+
},
177+
"property_values": {
178+
Type: schema.TypeList,
179+
Required: true,
180+
Description: "The values to match for the repository property.",
181+
Elem: &schema.Schema{
182+
Type: schema.TypeString,
183+
},
184+
},
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",
144189
},
145190
},
146191
},

github/respository_rules_utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ func expandConditions(input []interface{}, org bool) *github.RulesetConditions {
146146
}
147147

148148
rulesetConditions.RepositoryID = &github.RulesetRepositoryIDsConditionParameters{RepositoryIDs: repositoryIDs}
149+
} else if v, ok := inputConditions["repository_property"].([]interface{}); ok && v != nil && len(v) != 0 {
150+
rulesetConditions.
149151
}
150152
}
151153

0 commit comments

Comments
 (0)