diff --git a/github/resource_github_repository_file.go b/github/resource_github_repository_file.go index 46775f9c6b..1714125165 100644 --- a/github/resource_github_repository_file.go +++ b/github/resource_github_repository_file.go @@ -455,16 +455,14 @@ func resourceGithubRepositoryFileDelete(d *schema.ResourceData, meta any) error var branch string - message := fmt.Sprintf("Delete %s", file) - - if commitMessage, hasCommitMessage := d.GetOk("commit_message"); hasCommitMessage { - message = commitMessage.(string) + opts, err := resourceGithubRepositoryFileOptions(d) + if err != nil { + return err } - sha := d.Get("sha").(string) - opts := &github.RepositoryContentFileOptions{ - Message: &message, - SHA: &sha, + if *opts.Message == fmt.Sprintf("Add %s", file) { + m := fmt.Sprintf("Delete %s", file) + opts.Message = &m } if b, ok := d.GetOk("branch"); ok { diff --git a/github/resource_github_repository_file_test.go b/github/resource_github_repository_file_test.go index 34d37c5898..36725588a7 100644 --- a/github/resource_github_repository_file_test.go +++ b/github/resource_github_repository_file_test.go @@ -11,7 +11,6 @@ import ( ) func TestAccGithubRepositoryFile(t *testing.T) { - randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) t.Run("creates and manages files", func(t *testing.T) { config := fmt.Sprintf(` @@ -31,7 +30,7 @@ func TestAccGithubRepositoryFile(t *testing.T) { commit_author = "Terraform User" commit_email = "terraform@example.com" } - `, randomID) + `, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "github_repository_file.test", "content", @@ -107,7 +106,7 @@ func TestAccGithubRepositoryFile(t *testing.T) { commit_email = "terraform@example.com" } - `, randomID) + `, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -196,7 +195,7 @@ func TestAccGithubRepositoryFile(t *testing.T) { commit_author = "Terraform User" commit_email = "terraform@example.com" } - `, randomID) + `, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -272,7 +271,7 @@ func TestAccGithubRepositoryFile(t *testing.T) { commit_email = "terraform@example.com" autocreate_branch = false } - `, randomID) + `, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(