Skip to content

Commit 8dcb9e2

Browse files
authored
Merge branch 'main' into gpg-sign
2 parents 65dbdd2 + d975c70 commit 8dcb9e2

25 files changed

+1015
-137
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

+11-4
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,21 @@ func TestGithubOrganizationRulesets(t *testing.T) {
5454
}
5555
5656
required_status_checks {
57-
57+
5858
required_check {
5959
context = "ci"
6060
}
61-
61+
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
@@ -197,11 +204,11 @@ func TestGithubOrganizationRulesets(t *testing.T) {
197204
}
198205
199206
required_status_checks {
200-
207+
201208
required_check {
202209
context = "ci"
203210
}
204-
211+
205212
strict_required_status_checks_policy = true
206213
}
207214

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

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ require (
1111
github.com/hashicorp/terraform-plugin-sdk v1.17.2
1212
github.com/shurcooL/githubv4 v0.0.0-20221126192849-0b5c4c7994eb
1313
github.com/stretchr/testify v1.8.4
14-
golang.org/x/crypto v0.17.0
15-
golang.org/x/oauth2 v0.15.0
14+
golang.org/x/crypto v0.18.0
15+
golang.org/x/oauth2 v0.16.0
1616
gopkg.in/square/go-jose.v2 v2.6.0
1717
)
1818

@@ -200,9 +200,9 @@ require (
200200
go.opencensus.io v0.24.0 // indirect
201201
golang.org/x/exp/typeparams v0.0.0-20220827204233-334a2380cb91 // indirect
202202
golang.org/x/mod v0.8.0 // indirect
203-
golang.org/x/net v0.19.0 // indirect
203+
golang.org/x/net v0.20.0 // indirect
204204
golang.org/x/sync v0.2.0 // indirect
205-
golang.org/x/sys v0.15.0 // indirect
205+
golang.org/x/sys v0.16.0 // indirect
206206
golang.org/x/text v0.14.0 // indirect
207207
golang.org/x/tools v0.6.0 // indirect
208208
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect

go.sum

+725-2
Large diffs are not rendered by default.

vendor/golang.org/x/crypto/internal/poly1305/bits_compat.go

-39
This file was deleted.

vendor/golang.org/x/crypto/internal/poly1305/bits_go1.13.go

-21
This file was deleted.

vendor/golang.org/x/crypto/internal/poly1305/sum_generic.go

+23-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)