From 49eac771f87f31a1392c57b104c7a5c58c96a704 Mon Sep 17 00:00:00 2001 From: SotaNakajima Date: Tue, 12 Sep 2023 15:58:50 -0700 Subject: [PATCH 1/9] fix: Fix commit strategies when updating repos --- github/resource_github_repository.go | 40 +++--- github/resource_github_repository_test.go | 149 +++++++++++++++------- 2 files changed, 129 insertions(+), 60 deletions(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 2d41530c44..094ada0260 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -524,23 +524,7 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er } } - // only configure merge commit if we are in commit merge strategy - allowMergeCommit, ok := d.Get("allow_merge_commit").(bool) - if ok { - if allowMergeCommit { - repoReq.MergeCommitTitle = github.String(d.Get("merge_commit_title").(string)) - repoReq.MergeCommitMessage = github.String(d.Get("merge_commit_message").(string)) - } - } - - // only configure squash commit if we are in squash merge strategy - allowSquashMerge, ok := d.Get("allow_squash_merge").(bool) - if ok { - if allowSquashMerge { - repoReq.SquashMergeCommitTitle = github.String(d.Get("squash_merge_commit_title").(string)) - repoReq.SquashMergeCommitMessage = github.String(d.Get("squash_merge_commit_message").(string)) - } - } + configureCommitStrategies(d, repoReq) repoReq.Private = github.Bool(isPrivate) @@ -729,6 +713,8 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er repoReq := resourceGithubRepositoryObject(d) + configureCommitStrategies(d, repoReq) + // handle visibility updates separately from other fields repoReq.Visibility = nil @@ -859,6 +845,26 @@ func resourceGithubRepositoryDelete(d *schema.ResourceData, meta interface{}) er return err } +func configureCommitStrategies(d *schema.ResourceData, r *github.Repository) { + // only configure merge commit if we are in commit merge strategy + allowMergeCommit, ok := d.Get("allow_merge_commit").(bool) + if ok { + if allowMergeCommit { + r.MergeCommitTitle = github.String(d.Get("merge_commit_title").(string)) + r.MergeCommitMessage = github.String(d.Get("merge_commit_message").(string)) + } + } + + // only configure squash commit if we are in squash merge strategy + allowSquashMerge, ok := d.Get("allow_squash_merge").(bool) + if ok { + if allowSquashMerge { + r.SquashMergeCommitTitle = github.String(d.Get("squash_merge_commit_title").(string)) + r.SquashMergeCommitMessage = github.String(d.Get("squash_merge_commit_message").(string)) + } + } +} + func expandPages(input []interface{}) *github.Pages { if len(input) == 0 || input[0] == nil { return nil diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index df6aad5fad..3a10dc751b 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -771,27 +771,54 @@ func TestAccGithubRepositories(t *testing.T) { }) - t.Run("modify merge commit strategy without error", func(t *testing.T) { - config := fmt.Sprintf(` - resource "github_repository" "test" { - - name = "tf-acc-test-modify-co-str-%[1]s" - allow_merge_commit = true - merge_commit_title = "PR_TITLE" - merge_commit_message = "BLANK" - } - `, randomID) + t.Run("create and modify merge commit strategy without error", func(t *testing.T) { + mergeCommitTitle := "MERGE_MESSAGE" + mergeCommitMessage := "PR_BODY" + updatedMergeCommitTitle := "PR_TITLE" + updatedMergeCommitMessage := "BLANK" + + configs := map[string]string{ + "before": fmt.Sprintf(` + resource "github_repository" "test" { + + name = "tf-acc-test-modify-co-str-%[1]s" + allow_merge_commit = true + merge_commit_title = "%s" + merge_commit_message = "%s" + } + `, randomID, mergeCommitTitle, mergeCommitMessage), + "after": fmt.Sprintf(` + resource "github_repository" "test" { + name = "tf-acc-test-modify-co-str-%[1]s" + allow_merge_commit = true + merge_commit_title = "%s" + merge_commit_message = "%s" + } + `, randomID, updatedMergeCommitTitle, updatedMergeCommitMessage), + } - check := resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "github_repository.test", "merge_commit_title", - "PR_TITLE", - ), - resource.TestCheckResourceAttr( - "github_repository.test", "merge_commit_message", - "BLANK", - ), - ) + checks := map[string]resource.TestCheckFunc{ + "before": resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "merge_commit_title", + mergeCommitTitle, + ), + resource.TestCheckResourceAttr( + "github_repository.test", "merge_commit_message", + mergeCommitMessage, + ), + ), + "after": resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "merge_commit_title", + updatedMergeCommitTitle, + ), + resource.TestCheckResourceAttr( + "github_repository.test", "merge_commit_message", + updatedMergeCommitMessage, + ), + ), + } testCase := func(t *testing.T, mode string) { resource.Test(t, resource.TestCase{ @@ -799,8 +826,12 @@ func TestAccGithubRepositories(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: config, - Check: check, + Config: configs["before"], + Check: checks["before"], + }, + { + Config: configs["after"], + Check: checks["after"], }, }, }) @@ -819,26 +850,53 @@ func TestAccGithubRepositories(t *testing.T) { }) }) - t.Run("modify squash merge strategy without error", func(t *testing.T) { - config := fmt.Sprintf(` - resource "github_repository" "test" { - name = "tf-acc-test-modify-sq-str-%[1]s" - allow_squash_merge = true - squash_merge_commit_title = "PR_TITLE" - squash_merge_commit_message = "BLANK" - } - `, randomID) + t.Run("create and modify squash merge commit strategy without error", func(t *testing.T) { + squashMergeCommitTitle := "PR_TITLE" + squashMergeCommitMessage := "PR_BODY" + updatedSquashMergeCommitTitle := "COMMIT_OR_PR_TITLE" + updatedSquashMergeCommitMessage := "COMMIT_MESSAGES" + + configs := map[string]string{ + "before": fmt.Sprintf(` + resource "github_repository" "test" { + name = "tf-acc-test-modify-sq-str-%[1]s" + allow_squash_merge = true + squash_merge_commit_title = "%s" + squash_merge_commit_message = "%s" + } + `, randomID, squashMergeCommitTitle, squashMergeCommitMessage), + "after": fmt.Sprintf(` + resource "github_repository" "test" { + name = "tf-acc-test-modify-sq-str-%[1]s" + allow_squash_merge = true + squash_merge_commit_title = "%s" + squash_merge_commit_message = "%s" + } + `, randomID, updatedSquashMergeCommitTitle, updatedSquashMergeCommitMessage), + } - check := resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "github_repository.test", "squash_merge_commit_title", - "PR_TITLE", - ), - resource.TestCheckResourceAttr( - "github_repository.test", "squash_merge_commit_message", - "BLANK", - ), - ) + checks := map[string]resource.TestCheckFunc{ + "before": resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "squash_merge_commit_title", + squashMergeCommitTitle, + ), + resource.TestCheckResourceAttr( + "github_repository.test", "squash_merge_commit_message", + squashMergeCommitMessage, + ), + ), + "after": resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "squash_merge_commit_title", + updatedSquashMergeCommitTitle, + ), + resource.TestCheckResourceAttr( + "github_repository.test", "squash_merge_commit_message", + updatedSquashMergeCommitMessage, + ), + ), + } testCase := func(t *testing.T, mode string) { resource.Test(t, resource.TestCase{ @@ -846,8 +904,12 @@ func TestAccGithubRepositories(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: config, - Check: check, + Config: configs["before"], + Check: checks["before"], + }, + { + Config: configs["after"], + Check: checks["after"], }, }, }) @@ -865,6 +927,7 @@ func TestAccGithubRepositories(t *testing.T) { testCase(t, organization) }) }) + t.Run("create a repository with go as primary_language", func(t *testing.T) { config := fmt.Sprintf(` resource "github_repository" "test" { From ceb1a8e8b6eba19abb56c547e61bef245d4abde5 Mon Sep 17 00:00:00 2001 From: SotaNakajima Date: Tue, 12 Sep 2023 16:44:15 -0700 Subject: [PATCH 2/9] spacing --- github/resource_github_repository_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 3a10dc751b..4c1f9d2627 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -777,8 +777,8 @@ func TestAccGithubRepositories(t *testing.T) { updatedMergeCommitTitle := "PR_TITLE" updatedMergeCommitMessage := "BLANK" - configs := map[string]string{ - "before": fmt.Sprintf(` + configs := map[string]string{ + "before": fmt.Sprintf(` resource "github_repository" "test" { name = "tf-acc-test-modify-co-str-%[1]s" @@ -797,7 +797,7 @@ func TestAccGithubRepositories(t *testing.T) { `, randomID, updatedMergeCommitTitle, updatedMergeCommitMessage), } - checks := map[string]resource.TestCheckFunc{ + checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository.test", "merge_commit_title", @@ -818,7 +818,7 @@ func TestAccGithubRepositories(t *testing.T) { updatedMergeCommitMessage, ), ), - } + } testCase := func(t *testing.T, mode string) { resource.Test(t, resource.TestCase{ @@ -856,8 +856,8 @@ func TestAccGithubRepositories(t *testing.T) { updatedSquashMergeCommitTitle := "COMMIT_OR_PR_TITLE" updatedSquashMergeCommitMessage := "COMMIT_MESSAGES" - configs := map[string]string{ - "before": fmt.Sprintf(` + configs := map[string]string{ + "before": fmt.Sprintf(` resource "github_repository" "test" { name = "tf-acc-test-modify-sq-str-%[1]s" allow_squash_merge = true @@ -873,9 +873,9 @@ func TestAccGithubRepositories(t *testing.T) { squash_merge_commit_message = "%s" } `, randomID, updatedSquashMergeCommitTitle, updatedSquashMergeCommitMessage), - } + } - checks := map[string]resource.TestCheckFunc{ + checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository.test", "squash_merge_commit_title", @@ -896,7 +896,7 @@ func TestAccGithubRepositories(t *testing.T) { updatedSquashMergeCommitMessage, ), ), - } + } testCase := func(t *testing.T, mode string) { resource.Test(t, resource.TestCase{ From 8a357e328ed81371cd781f7a439efab54d7681f3 Mon Sep 17 00:00:00 2001 From: SotaNakajima Date: Tue, 12 Sep 2023 16:52:09 -0700 Subject: [PATCH 3/9] spacing --- github/resource_github_repository_test.go | 178 +++++++++++----------- 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 4c1f9d2627..fcbe28c42c 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -772,53 +772,53 @@ func TestAccGithubRepositories(t *testing.T) { }) t.Run("create and modify merge commit strategy without error", func(t *testing.T) { - mergeCommitTitle := "MERGE_MESSAGE" - mergeCommitMessage := "PR_BODY" - updatedMergeCommitTitle := "PR_TITLE" - updatedMergeCommitMessage := "BLANK" + mergeCommitTitle := "MERGE_MESSAGE" + mergeCommitMessage := "PR_BODY" + updatedMergeCommitTitle := "PR_TITLE" + updatedMergeCommitMessage := "BLANK" - configs := map[string]string{ + configs := map[string]string{ "before": fmt.Sprintf(` - resource "github_repository" "test" { - - name = "tf-acc-test-modify-co-str-%[1]s" - allow_merge_commit = true - merge_commit_title = "%s" - merge_commit_message = "%s" - } - `, randomID, mergeCommitTitle, mergeCommitMessage), - "after": fmt.Sprintf(` - resource "github_repository" "test" { - name = "tf-acc-test-modify-co-str-%[1]s" - allow_merge_commit = true - merge_commit_title = "%s" - merge_commit_message = "%s" - } - `, randomID, updatedMergeCommitTitle, updatedMergeCommitMessage), + resource "github_repository" "test" { + + name = "tf-acc-test-modify-co-str-%[1]s" + allow_merge_commit = true + merge_commit_title = "%s" + merge_commit_message = "%s" + } + `, randomID, mergeCommitTitle, mergeCommitMessage), + "after": fmt.Sprintf(` + resource "github_repository" "test" { + name = "tf-acc-test-modify-co-str-%[1]s" + allow_merge_commit = true + merge_commit_title = "%s" + merge_commit_message = "%s" + } + `, randomID, updatedMergeCommitTitle, updatedMergeCommitMessage), } - checks := map[string]resource.TestCheckFunc{ - "before": resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "github_repository.test", "merge_commit_title", - mergeCommitTitle, - ), - resource.TestCheckResourceAttr( - "github_repository.test", "merge_commit_message", - mergeCommitMessage, - ), - ), - "after": resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "github_repository.test", "merge_commit_title", - updatedMergeCommitTitle, - ), - resource.TestCheckResourceAttr( - "github_repository.test", "merge_commit_message", - updatedMergeCommitMessage, - ), - ), - } + checks := map[string]resource.TestCheckFunc{ + "before": resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "merge_commit_title", + mergeCommitTitle, + ), + resource.TestCheckResourceAttr( + "github_repository.test", "merge_commit_message", + mergeCommitMessage, + ), + ), + "after": resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "merge_commit_title", + updatedMergeCommitTitle, + ), + resource.TestCheckResourceAttr( + "github_repository.test", "merge_commit_message", + updatedMergeCommitMessage, + ), + ), + } testCase := func(t *testing.T, mode string) { resource.Test(t, resource.TestCase{ @@ -851,52 +851,52 @@ func TestAccGithubRepositories(t *testing.T) { }) t.Run("create and modify squash merge commit strategy without error", func(t *testing.T) { - squashMergeCommitTitle := "PR_TITLE" - squashMergeCommitMessage := "PR_BODY" - updatedSquashMergeCommitTitle := "COMMIT_OR_PR_TITLE" - updatedSquashMergeCommitMessage := "COMMIT_MESSAGES" - - configs := map[string]string{ - "before": fmt.Sprintf(` - resource "github_repository" "test" { - name = "tf-acc-test-modify-sq-str-%[1]s" - allow_squash_merge = true - squash_merge_commit_title = "%s" - squash_merge_commit_message = "%s" - } - `, randomID, squashMergeCommitTitle, squashMergeCommitMessage), - "after": fmt.Sprintf(` - resource "github_repository" "test" { - name = "tf-acc-test-modify-sq-str-%[1]s" - allow_squash_merge = true - squash_merge_commit_title = "%s" - squash_merge_commit_message = "%s" - } - `, randomID, updatedSquashMergeCommitTitle, updatedSquashMergeCommitMessage), - } - - checks := map[string]resource.TestCheckFunc{ - "before": resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "github_repository.test", "squash_merge_commit_title", - squashMergeCommitTitle, - ), - resource.TestCheckResourceAttr( - "github_repository.test", "squash_merge_commit_message", - squashMergeCommitMessage, - ), - ), - "after": resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "github_repository.test", "squash_merge_commit_title", - updatedSquashMergeCommitTitle, - ), - resource.TestCheckResourceAttr( - "github_repository.test", "squash_merge_commit_message", - updatedSquashMergeCommitMessage, - ), - ), - } + squashMergeCommitTitle := "PR_TITLE" + squashMergeCommitMessage := "PR_BODY" + updatedSquashMergeCommitTitle := "COMMIT_OR_PR_TITLE" + updatedSquashMergeCommitMessage := "COMMIT_MESSAGES" + + configs := map[string]string{ + "before": fmt.Sprintf(` + resource "github_repository" "test" { + name = "tf-acc-test-modify-sq-str-%[1]s" + allow_squash_merge = true + squash_merge_commit_title = "%s" + squash_merge_commit_message = "%s" + } + `, randomID, squashMergeCommitTitle, squashMergeCommitMessage), + "after": fmt.Sprintf(` + resource "github_repository" "test" { + name = "tf-acc-test-modify-sq-str-%[1]s" + allow_squash_merge = true + squash_merge_commit_title = "%s" + squash_merge_commit_message = "%s" + } + `, randomID, updatedSquashMergeCommitTitle, updatedSquashMergeCommitMessage), + } + + checks := map[string]resource.TestCheckFunc{ + "before": resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "squash_merge_commit_title", + squashMergeCommitTitle, + ), + resource.TestCheckResourceAttr( + "github_repository.test", "squash_merge_commit_message", + squashMergeCommitMessage, + ), + ), + "after": resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "squash_merge_commit_title", + updatedSquashMergeCommitTitle, + ), + resource.TestCheckResourceAttr( + "github_repository.test", "squash_merge_commit_message", + updatedSquashMergeCommitMessage, + ), + ), + } testCase := func(t *testing.T, mode string) { resource.Test(t, resource.TestCase{ From d643b6cc897bd5c6fbd05c5d1e84ef4319aa743c Mon Sep 17 00:00:00 2001 From: SotaNakajima Date: Tue, 12 Sep 2023 21:09:29 -0700 Subject: [PATCH 4/9] simplify --- github/resource_github_repository.go | 46 +++++++++++++--------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 094ada0260..93d5ea5770 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -469,7 +469,7 @@ func calculateSecurityAndAnalysis(d *schema.ResourceData) *github.SecurityAndAna } func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository { - return &github.Repository{ + repoReq := &github.Repository{ Name: github.String(d.Get("name").(string)), Description: github.String(d.Get("description").(string)), Homepage: github.String(d.Get("homepage_url").(string)), @@ -493,6 +493,26 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository { AllowUpdateBranch: github.Bool(d.Get("allow_update_branch").(bool)), SecurityAndAnalysis: calculateSecurityAndAnalysis(d), } + + // only configure merge commit if we are in commit merge strategy + allowMergeCommit, ok := d.Get("allow_merge_commit").(bool) + if ok { + if allowMergeCommit { + repoReq.MergeCommitTitle = github.String(d.Get("merge_commit_title").(string)) + repoReq.MergeCommitMessage = github.String(d.Get("merge_commit_message").(string)) + } + } + + // only configure squash commit if we are in squash merge strategy + allowSquashMerge, ok := d.Get("allow_squash_merge").(bool) + if ok { + if allowSquashMerge { + repoReq.SquashMergeCommitTitle = github.String(d.Get("squash_merge_commit_title").(string)) + repoReq.SquashMergeCommitMessage = github.String(d.Get("squash_merge_commit_message").(string)) + } + } + + return repoReq } func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) error { @@ -524,8 +544,6 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er } } - configureCommitStrategies(d, repoReq) - repoReq.Private = github.Bool(isPrivate) if template, ok := d.GetOk("template"); ok { @@ -713,8 +731,6 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er repoReq := resourceGithubRepositoryObject(d) - configureCommitStrategies(d, repoReq) - // handle visibility updates separately from other fields repoReq.Visibility = nil @@ -845,26 +861,6 @@ func resourceGithubRepositoryDelete(d *schema.ResourceData, meta interface{}) er return err } -func configureCommitStrategies(d *schema.ResourceData, r *github.Repository) { - // only configure merge commit if we are in commit merge strategy - allowMergeCommit, ok := d.Get("allow_merge_commit").(bool) - if ok { - if allowMergeCommit { - r.MergeCommitTitle = github.String(d.Get("merge_commit_title").(string)) - r.MergeCommitMessage = github.String(d.Get("merge_commit_message").(string)) - } - } - - // only configure squash commit if we are in squash merge strategy - allowSquashMerge, ok := d.Get("allow_squash_merge").(bool) - if ok { - if allowSquashMerge { - r.SquashMergeCommitTitle = github.String(d.Get("squash_merge_commit_title").(string)) - r.SquashMergeCommitMessage = github.String(d.Get("squash_merge_commit_message").(string)) - } - } -} - func expandPages(input []interface{}) *github.Pages { if len(input) == 0 || input[0] == nil { return nil From 6f736ebb30655b275fa61bf72b3db0277c9ab948 Mon Sep 17 00:00:00 2001 From: SotaNakajima Date: Tue, 12 Sep 2023 21:22:13 -0700 Subject: [PATCH 5/9] repoReq -> repository --- github/resource_github_repository.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 93d5ea5770..9d177649d5 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -469,7 +469,7 @@ func calculateSecurityAndAnalysis(d *schema.ResourceData) *github.SecurityAndAna } func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository { - repoReq := &github.Repository{ + repository := &github.Repository{ Name: github.String(d.Get("name").(string)), Description: github.String(d.Get("description").(string)), Homepage: github.String(d.Get("homepage_url").(string)), @@ -498,8 +498,8 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository { allowMergeCommit, ok := d.Get("allow_merge_commit").(bool) if ok { if allowMergeCommit { - repoReq.MergeCommitTitle = github.String(d.Get("merge_commit_title").(string)) - repoReq.MergeCommitMessage = github.String(d.Get("merge_commit_message").(string)) + repository.MergeCommitTitle = github.String(d.Get("merge_commit_title").(string)) + repository.MergeCommitMessage = github.String(d.Get("merge_commit_message").(string)) } } @@ -507,12 +507,12 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository { allowSquashMerge, ok := d.Get("allow_squash_merge").(bool) if ok { if allowSquashMerge { - repoReq.SquashMergeCommitTitle = github.String(d.Get("squash_merge_commit_title").(string)) - repoReq.SquashMergeCommitMessage = github.String(d.Get("squash_merge_commit_message").(string)) + repository.SquashMergeCommitTitle = github.String(d.Get("squash_merge_commit_title").(string)) + repository.SquashMergeCommitMessage = github.String(d.Get("squash_merge_commit_message").(string)) } } - return repoReq + return repository } func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) error { From 6a3129e20813d3eb870d75a434f4e67c2b93e97c Mon Sep 17 00:00:00 2001 From: SotaNakajima Date: Wed, 13 Sep 2023 10:23:09 -0700 Subject: [PATCH 6/9] Update repository.html.markdown --- website/docs/r/repository.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/r/repository.html.markdown b/website/docs/r/repository.html.markdown index c29f743f98..aee836b9b6 100644 --- a/website/docs/r/repository.html.markdown +++ b/website/docs/r/repository.html.markdown @@ -84,13 +84,13 @@ The following arguments are supported: * `allow_auto_merge` - (Optional) Set to `true` to allow auto-merging pull requests on the repository. -* `squash_merge_commit_title` - (Optional) Can be `PR_TITLE` or `COMMIT_OR_PR_TITLE` for a default squash merge commit title. +* `squash_merge_commit_title` - (Optional) Can be `PR_TITLE` or `COMMIT_OR_PR_TITLE` for a default squash merge commit title. Applicable only if `allow_squash_merge` is true. -* `squash_merge_commit_message` - (Optional) Can be `PR_BODY`, `COMMIT_MESSAGES`, or `BLANK` for a default squash merge commit message. +* `squash_merge_commit_message` - (Optional) Can be `PR_BODY`, `COMMIT_MESSAGES`, or `BLANK` for a default squash merge commit message. Applicable only if `allow_squash_merge` is true. -* `merge_commit_title` - Can be `PR_TITLE` or `MERGE_MESSAGE` for a default merge commit title. +* `merge_commit_title` - Can be `PR_TITLE` or `MERGE_MESSAGE` for a default merge commit title. Applicable only if `allow_merge_commit` is true. -* `merge_commit_message` - Can be `PR_BODY`, `PR_TITLE`, or `BLANK` for a default merge commit message. +* `merge_commit_message` - Can be `PR_BODY`, `PR_TITLE`, or `BLANK` for a default merge commit message. Applicable only if `allow_merge_commit` is true. * `delete_branch_on_merge` - (Optional) Automatically delete head branch after a pull request is merged. Defaults to `false`. From 346d6a0c8b24c925a786ebc75925aa845bdeafb1 Mon Sep 17 00:00:00 2001 From: SotaNakajima Date: Wed, 13 Sep 2023 10:24:32 -0700 Subject: [PATCH 7/9] Update repository.html.markdown --- website/docs/r/repository.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/r/repository.html.markdown b/website/docs/r/repository.html.markdown index aee836b9b6..adef0129d6 100644 --- a/website/docs/r/repository.html.markdown +++ b/website/docs/r/repository.html.markdown @@ -84,13 +84,13 @@ The following arguments are supported: * `allow_auto_merge` - (Optional) Set to `true` to allow auto-merging pull requests on the repository. -* `squash_merge_commit_title` - (Optional) Can be `PR_TITLE` or `COMMIT_OR_PR_TITLE` for a default squash merge commit title. Applicable only if `allow_squash_merge` is true. +* `squash_merge_commit_title` - (Optional) Can be `PR_TITLE` or `COMMIT_OR_PR_TITLE` for a default squash merge commit title. Applicable only if `allow_squash_merge` is `true`. -* `squash_merge_commit_message` - (Optional) Can be `PR_BODY`, `COMMIT_MESSAGES`, or `BLANK` for a default squash merge commit message. Applicable only if `allow_squash_merge` is true. +* `squash_merge_commit_message` - (Optional) Can be `PR_BODY`, `COMMIT_MESSAGES`, or `BLANK` for a default squash merge commit message. Applicable only if `allow_squash_merge` is `true`. -* `merge_commit_title` - Can be `PR_TITLE` or `MERGE_MESSAGE` for a default merge commit title. Applicable only if `allow_merge_commit` is true. +* `merge_commit_title` - Can be `PR_TITLE` or `MERGE_MESSAGE` for a default merge commit title. Applicable only if `allow_merge_commit` is `true`. -* `merge_commit_message` - Can be `PR_BODY`, `PR_TITLE`, or `BLANK` for a default merge commit message. Applicable only if `allow_merge_commit` is true. +* `merge_commit_message` - Can be `PR_BODY`, `PR_TITLE`, or `BLANK` for a default merge commit message. Applicable only if `allow_merge_commit` is `true`. * `delete_branch_on_merge` - (Optional) Automatically delete head branch after a pull request is merged. Defaults to `false`. From 0bb2ab78d3962d1d8b91819bebd83859ef61cb50 Mon Sep 17 00:00:00 2001 From: SotaNakajima Date: Wed, 13 Sep 2023 10:44:40 -0700 Subject: [PATCH 8/9] Fix test --- github/resource_github_repository_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index fcbe28c42c..f278b07f1c 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -772,10 +772,10 @@ func TestAccGithubRepositories(t *testing.T) { }) t.Run("create and modify merge commit strategy without error", func(t *testing.T) { - mergeCommitTitle := "MERGE_MESSAGE" - mergeCommitMessage := "PR_BODY" - updatedMergeCommitTitle := "PR_TITLE" - updatedMergeCommitMessage := "BLANK" + mergeCommitTitle := "PR_TITLE" + mergeCommitMessage := "BLANK" + updatedMergeCommitTitle := "MERGE_MESSAGE" + updatedMergeCommitMessage := "PR_TITLE" configs := map[string]string{ "before": fmt.Sprintf(` From bbd383ef29fa27a9f8ceaae4db5e9f48b32a9457 Mon Sep 17 00:00:00 2001 From: Sota Nakajima Date: Mon, 18 Sep 2023 08:13:30 -0700 Subject: [PATCH 9/9] lint --- github/resource_github_repository.go | 2 +- github/resource_github_repository_test.go | 92 +++++++++++------------ 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 670b3b6f17..54218f8901 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -469,7 +469,7 @@ func calculateSecurityAndAnalysis(d *schema.ResourceData) *github.SecurityAndAna } func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository { - repository := &github.Repository{ + repository := &github.Repository{ Name: github.String(d.Get("name").(string)), Description: github.String(d.Get("description").(string)), Homepage: github.String(d.Get("homepage_url").(string)), diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index f278b07f1c..bab9cf7b0c 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -773,11 +773,11 @@ func TestAccGithubRepositories(t *testing.T) { t.Run("create and modify merge commit strategy without error", func(t *testing.T) { mergeCommitTitle := "PR_TITLE" - mergeCommitMessage := "BLANK" - updatedMergeCommitTitle := "MERGE_MESSAGE" - updatedMergeCommitMessage := "PR_TITLE" + mergeCommitMessage := "BLANK" + updatedMergeCommitTitle := "MERGE_MESSAGE" + updatedMergeCommitMessage := "PR_TITLE" - configs := map[string]string{ + configs := map[string]string{ "before": fmt.Sprintf(` resource "github_repository" "test" { @@ -800,24 +800,24 @@ func TestAccGithubRepositories(t *testing.T) { checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( - "github_repository.test", "merge_commit_title", - mergeCommitTitle, + "github_repository.test", "merge_commit_title", + mergeCommitTitle, ), resource.TestCheckResourceAttr( - "github_repository.test", "merge_commit_message", - mergeCommitMessage, + "github_repository.test", "merge_commit_message", + mergeCommitMessage, ), - ), - "after": resource.ComposeTestCheckFunc( + ), + "after": resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( - "github_repository.test", "merge_commit_title", - updatedMergeCommitTitle, + "github_repository.test", "merge_commit_title", + updatedMergeCommitTitle, ), resource.TestCheckResourceAttr( - "github_repository.test", "merge_commit_message", - updatedMergeCommitMessage, + "github_repository.test", "merge_commit_message", + updatedMergeCommitMessage, ), - ), + ), } testCase := func(t *testing.T, mode string) { @@ -851,13 +851,13 @@ func TestAccGithubRepositories(t *testing.T) { }) t.Run("create and modify squash merge commit strategy without error", func(t *testing.T) { - squashMergeCommitTitle := "PR_TITLE" - squashMergeCommitMessage := "PR_BODY" - updatedSquashMergeCommitTitle := "COMMIT_OR_PR_TITLE" - updatedSquashMergeCommitMessage := "COMMIT_MESSAGES" + squashMergeCommitTitle := "PR_TITLE" + squashMergeCommitMessage := "PR_BODY" + updatedSquashMergeCommitTitle := "COMMIT_OR_PR_TITLE" + updatedSquashMergeCommitMessage := "COMMIT_MESSAGES" - configs := map[string]string{ - "before": fmt.Sprintf(` + configs := map[string]string{ + "before": fmt.Sprintf(` resource "github_repository" "test" { name = "tf-acc-test-modify-sq-str-%[1]s" allow_squash_merge = true @@ -865,7 +865,7 @@ func TestAccGithubRepositories(t *testing.T) { squash_merge_commit_message = "%s" } `, randomID, squashMergeCommitTitle, squashMergeCommitMessage), - "after": fmt.Sprintf(` + "after": fmt.Sprintf(` resource "github_repository" "test" { name = "tf-acc-test-modify-sq-str-%[1]s" allow_squash_merge = true @@ -873,30 +873,30 @@ func TestAccGithubRepositories(t *testing.T) { squash_merge_commit_message = "%s" } `, randomID, updatedSquashMergeCommitTitle, updatedSquashMergeCommitMessage), - } - - checks := map[string]resource.TestCheckFunc{ - "before": resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "github_repository.test", "squash_merge_commit_title", - squashMergeCommitTitle, - ), - resource.TestCheckResourceAttr( - "github_repository.test", "squash_merge_commit_message", - squashMergeCommitMessage, - ), - ), - "after": resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "github_repository.test", "squash_merge_commit_title", - updatedSquashMergeCommitTitle, - ), - resource.TestCheckResourceAttr( - "github_repository.test", "squash_merge_commit_message", - updatedSquashMergeCommitMessage, - ), - ), - } + } + + checks := map[string]resource.TestCheckFunc{ + "before": resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "squash_merge_commit_title", + squashMergeCommitTitle, + ), + resource.TestCheckResourceAttr( + "github_repository.test", "squash_merge_commit_message", + squashMergeCommitMessage, + ), + ), + "after": resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "squash_merge_commit_title", + updatedSquashMergeCommitTitle, + ), + resource.TestCheckResourceAttr( + "github_repository.test", "squash_merge_commit_message", + updatedSquashMergeCommitMessage, + ), + ), + } testCase := func(t *testing.T, mode string) { resource.Test(t, resource.TestCase{