@@ -20,7 +20,8 @@ func TestGithubRepositoryRulesets(t *testing.T) {
2020 config := fmt .Sprintf (`
2121 resource "github_repository" "test" {
2222 name = "tf-acc-test-%s"
23- auto_init = false
23+ auto_init = true
24+ default_branch = "main"
2425 }
2526
2627 resource "github_repository_environment" "example" {
@@ -36,7 +37,7 @@ func TestGithubRepositoryRulesets(t *testing.T) {
3637
3738 conditions {
3839 ref_name {
39- include = ["~ALL "]
40+ include = ["refs/heads/main "]
4041 exclude = []
4142 }
4243 }
@@ -73,16 +74,6 @@ func TestGithubRepositoryRulesets(t *testing.T) {
7374 require_last_push_approval = true
7475 }
7576
76- merge_queue {
77- check_response_timeout_minutes = 30
78- grouping_strategy = "HEADGREEN"
79- max_entries_to_build = 4
80- max_entries_to_merge = 4
81- merge_method = SQUASH
82- min_entries_to_merge = 2
83- min_entries_to_merge_wait_minutes = 10
84- }
85-
8677 required_status_checks {
8778
8879 required_check {
@@ -290,7 +281,8 @@ func TestGithubRepositoryRulesets(t *testing.T) {
290281 resource "github_repository" "test" {
291282 name = "tf-acc-test-import-%[1]s"
292283 description = "Terraform acceptance tests %[1]s"
293- auto_init = false
284+ auto_init = true
285+ default_branch = "main"
294286 }
295287
296288 resource "github_repository_environment" "example" {
@@ -306,7 +298,7 @@ func TestGithubRepositoryRulesets(t *testing.T) {
306298
307299 conditions {
308300 ref_name {
309- include = ["~ALL "]
301+ include = ["refs/heads/main "]
310302 exclude = []
311303 }
312304 }
@@ -338,7 +330,7 @@ func TestGithubRepositoryRulesets(t *testing.T) {
338330 grouping_strategy = "HEADGREEN"
339331 max_entries_to_build = 4
340332 max_entries_to_merge = 4
341- merge_method = SQUASH
333+ merge_method = " SQUASH"
342334 min_entries_to_merge = 2
343335 min_entries_to_merge_wait_minutes = 10
344336 }
@@ -396,6 +388,80 @@ func TestGithubRepositoryRulesets(t *testing.T) {
396388
397389 })
398390
391+ t .Run ("Creates repository ruleset with merge queue SQUASH method" , func (t * testing.T ) {
392+
393+ config := fmt .Sprintf (`
394+ resource "github_repository" "test" {
395+ name = "tf-acc-test-merge-queue-%s"
396+ auto_init = true
397+ default_branch = "main"
398+ }
399+
400+ resource "github_repository_ruleset" "test" {
401+ name = "merge-queue-test"
402+ repository = github_repository.test.id
403+ target = "branch"
404+ enforcement = "active"
405+
406+ conditions {
407+ ref_name {
408+ include = ["refs/heads/main"]
409+ exclude = []
410+ }
411+ }
412+
413+ rules {
414+ merge_queue {
415+ check_response_timeout_minutes = 30
416+ grouping_strategy = "HEADGREEN"
417+ max_entries_to_build = 4
418+ max_entries_to_merge = 4
419+ merge_method = "SQUASH"
420+ min_entries_to_merge = 2
421+ min_entries_to_merge_wait_minutes = 10
422+ }
423+ }
424+ }
425+ ` , randomID )
426+
427+ check := resource .ComposeTestCheckFunc (
428+ resource .TestCheckResourceAttr (
429+ "github_repository_ruleset.test" , "name" ,
430+ "merge-queue-test" ,
431+ ),
432+ resource .TestCheckResourceAttr (
433+ "github_repository_ruleset.test" , "rules.0.merge_queue.0.merge_method" ,
434+ "SQUASH" ,
435+ ),
436+ )
437+
438+ testCase := func (t * testing.T , mode string ) {
439+ resource .Test (t , resource.TestCase {
440+ PreCheck : func () { skipUnlessMode (t , mode ) },
441+ Providers : testAccProviders ,
442+ Steps : []resource.TestStep {
443+ {
444+ Config : config ,
445+ Check : check ,
446+ },
447+ },
448+ })
449+ }
450+
451+ t .Run ("with an anonymous account" , func (t * testing.T ) {
452+ t .Skip ("anonymous account not supported for this operation" )
453+ })
454+
455+ t .Run ("with an individual account" , func (t * testing.T ) {
456+ testCase (t , individual )
457+ })
458+
459+ t .Run ("with an organization account" , func (t * testing.T ) {
460+ testCase (t , organization )
461+ })
462+
463+ })
464+
399465}
400466
401467func importRepositoryRulesetByResourcePaths (repoLogicalName , rulesetLogicalName string ) resource.ImportStateIdFunc {
0 commit comments