Skip to content

Commit 5a2df39

Browse files
authored
Merge branch 'main' into v6
2 parents b0c279f + d975c70 commit 5a2df39

4 files changed

+88
-10
lines changed

github/resource_github_organization_ruleset.go

+36
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,42 @@ func resourceGithubOrganizationRuleset() *schema.Resource {
420420
},
421421
},
422422
},
423+
"required_workflows": {
424+
Type: schema.TypeList,
425+
MaxItems: 1,
426+
Optional: true,
427+
Description: "Choose which Actions workflows must pass before branches can be merged into a branch that matches this rule.",
428+
Elem: &schema.Resource{
429+
Schema: map[string]*schema.Schema{
430+
"required_workflow": {
431+
Type: schema.TypeSet,
432+
MinItems: 1,
433+
Required: true,
434+
Description: "Actions workflows that are required. Several can be defined.",
435+
Elem: &schema.Resource{
436+
Schema: map[string]*schema.Schema{
437+
"repository_id": {
438+
Type: schema.TypeInt,
439+
Required: true,
440+
Description: "The repository in which the workflow is defined.",
441+
},
442+
"path": {
443+
Type: schema.TypeString,
444+
Required: true,
445+
Description: "The path to the workflow YAML definition file.",
446+
},
447+
"ref": {
448+
Type: schema.TypeString,
449+
Optional: true,
450+
Default: "master",
451+
Description: "The ref (branch or tag) of the workflow file to use.",
452+
},
453+
},
454+
},
455+
},
456+
},
457+
},
458+
},
423459
},
424460
},
425461
},

github/resource_github_organization_ruleset_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ func TestGithubOrganizationRulesets(t *testing.T) {
6262
strict_required_status_checks_policy = true
6363
}
6464
65+
required_workflows {
66+
required_workflow {
67+
path = "path/to/workflow.yaml"
68+
repository_id = 1234
69+
}
70+
}
71+
6572
branch_name_pattern {
6673
name = "test"
6774
negate = false

github/respository_rules_utils.go

+31
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,37 @@ func expandRules(input []interface{}, org bool) []*github.RepositoryRule {
334334
rulesSlice = append(rulesSlice, github.NewRequiredStatusChecksRule(params))
335335
}
336336

337+
// Required workflows to pass before merging rule
338+
if v, ok := rulesMap["required_workflows"].([]interface{}); ok && len(v) != 0 {
339+
requiredWorkflowsMap := v[0].(map[string]interface{})
340+
requiredWorkflows := make([]*github.RuleRequiredWorkflow, 0)
341+
342+
if requiredWorkflowsInput, ok := requiredWorkflowsMap["required_workflow"]; ok {
343+
344+
requiredWorkflowsSet := requiredWorkflowsInput.(*schema.Set)
345+
for _, workflowMap := range requiredWorkflowsSet.List() {
346+
workflow := workflowMap.(map[string]interface{})
347+
348+
// Get all parameters
349+
repositoryID := github.Int64(int64(workflow["repository_id"].(int)))
350+
ref := github.String(workflow["ref"].(string))
351+
352+
params := &github.RuleRequiredWorkflow{
353+
RepositoryID: repositoryID,
354+
Path: workflow["path"].(string),
355+
Ref: ref,
356+
}
357+
358+
requiredWorkflows = append(requiredWorkflows, params)
359+
}
360+
}
361+
362+
params := &github.RequiredWorkflowsRuleParameters{
363+
RequiredWorkflows: requiredWorkflows,
364+
}
365+
rulesSlice = append(rulesSlice, github.NewRequiredWorkflowsRule(params))
366+
}
367+
337368
return rulesSlice
338369
}
339370

website/docs/r/organization_ruleset.html.markdown

+14-10
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ resource "github_organization_ruleset" "example" {
6767

6868
The `rules` block supports the following:
6969

70-
7170
* `branch_name_pattern` - (Optional) (Block List, Max: 1) Parameters to be used for the branch_name_pattern rule. This rule only applies to repositories within an enterprise, it cannot be applied to repositories owned by individuals or regular organizations. Conflicts with `tag_name_pattern` as it only applies to rulesets with target `branch`. (see [below for nested schema](#rules.branch_name_pattern))
7271

7372
* `commit_author_email_pattern` - (Optional) (Block List, Max: 1) Parameters to be used for the commit_author_email_pattern rule. This rule only applies to repositories within an enterprise, it cannot be applied to repositories owned by individuals or regular organizations. (see [below for nested schema](#rules.commit_author_email_pattern))
@@ -90,6 +89,8 @@ The `rules` block supports the following:
9089

9190
* `required_status_checks` - (Optional) (Block List, Max: 1) Choose which status checks must pass before branches can be merged into a branch that matches this rule. When enabled, commits must first be pushed to another branch, then merged or pushed directly to a branch that matches this rule after status checks have passed. (see [below for nested schema](#rules.required_status_checks))
9291

92+
* `required_workflows` - (Optional) (Block List, Max: 1) Define which Actions workflows must pass before changes can be merged into a branch matching the rule. Multiple workflows can be specified. (see [below for nested schema](#rules.required_workflows))
93+
9394
* `tag_name_pattern` - (Optional) (Block List, Max: 1) Parameters to be used for the tag_name_pattern rule. This rule only applies to repositories within an enterprise, it cannot be applied to repositories owned by individuals or regular organizations. Conflicts with `branch_name_pattern` as it only applies to rulesets with target `tag`. (see [below for nested schema](#rules.tag_name_pattern))
9495

9596
* `update` - (Optional) (Boolean) Only allow users with bypass permission to update matching refs.
@@ -104,7 +105,6 @@ The `rules` block supports the following:
104105

105106
* `negate` - (Optional) (Boolean) If true, the rule will fail if the pattern matches.
106107

107-
108108
#### rules.commit_author_email_pattern ####
109109

110110
* `operator` - (Required) (String) The operator to use for matching. Can be one of: `starts_with`, `ends_with`, `contains`, `regex`.
@@ -115,7 +115,6 @@ The `rules` block supports the following:
115115

116116
* `negate` - (Optional) (Boolean) If true, the rule will fail if the pattern matches.
117117

118-
119118
#### rules.commit_message_pattern ####
120119

121120
* `operator` - (Required) (String) The operator to use for matching. Can be one of: `starts_with`, `ends_with`, `contains`, `regex`.
@@ -126,7 +125,6 @@ The `rules` block supports the following:
126125

127126
* `negate` - (Optional) (Boolean) If true, the rule will fail if the pattern matches.
128127

129-
130128
#### rules.committer_email_pattern ####
131129

132130
* `operator` - (Required) (String) The operator to use for matching. Can be one of: `starts_with`, `ends_with`, `contains`, `regex`.
@@ -137,7 +135,6 @@ The `rules` block supports the following:
137135

138136
* `negate` - (Optional) (Boolean) If true, the rule will fail if the pattern matches.
139137

140-
141138
#### rules.pull_request ####
142139

143140
* `dismiss_stale_reviews_on_push` - (Optional) (Boolean) New, reviewable commits pushed will dismiss previous pull request review approvals. Defaults to `false`.
@@ -162,7 +159,17 @@ The `rules` block supports the following:
162159

163160
* `integration_id` - (Optional) (Number) The optional integration ID that this status check must originate from.
164161

162+
#### rules.required_workflows ####
163+
164+
* `required_workflow` - (Required) (Block Set, Min: 1) Actions workflows that are required. Multiple can be defined. (see [below for nested schema](#rules.required_workflows.required_workflow))
165+
166+
#### rules.required_workflows.required_workflow ####
165167

168+
* `repository_id` - (Required) (Number) The ID of the repository. Names, full names and repository URLs are not supported.
169+
170+
* `path` - (Required) (String) The path to the YAML definition file of the workflow.
171+
172+
* `ref` - (Optional) (String) The optional ref from which to fetch the workflow. Defaults to `master`.
166173

167174
#### rules.tag_name_pattern ####
168175

@@ -174,8 +181,6 @@ The `rules` block supports the following:
174181

175182
* `negate` - (Optional) (Boolean) If true, the rule will fail if the pattern matches.
176183

177-
178-
179184
#### bypass_actors ####
180185

181186
* `actor_id` - (Required) (Number) The ID of the actor that can bypass a ruleset.
@@ -185,6 +190,7 @@ The `rules` block supports the following:
185190
* `bypass_mode` - (Optional) (String) When the specified actor can bypass the ruleset. pull_request means that an actor can only bypass rules on pull requests. Can be one of: `always`, `pull_request`.
186191

187192
~>Note: at the time of writing this, the following actor types correspond to the following actor IDs:
193+
188194
* `OrganizationAdmin` -> `1`
189195
* `RepositoryRole` (This is the actor type, the following are the base repository roles and their associated IDs.)
190196
* `maintain` -> `2`
@@ -208,21 +214,19 @@ One of `repository_id` and `repository_name` must be set for the rule to target
208214
#### conditions.repository_name ####
209215

210216
* `exclude` - (Required) (List of String) Array of repository names or patterns to exclude. The condition will not pass if any of these patterns match.
211-
217+
212218
* `include` - (Required) (List of String) 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.
213219

214220
## Attributes Reference
215221

216222
The following additional attributes are exported:
217223

218-
219224
* `etag` (String)
220225

221226
* `node_id` (String) GraphQL global node id for use with v4 API.
222227

223228
* `ruleset_id` (Number) GitHub ID for the ruleset.
224229

225-
226230
## Import
227231

228232
GitHub Organization Rulesets can be imported using the GitHub ruleset ID e.g.

0 commit comments

Comments
 (0)