diff --git a/github/resource_github_repository_file.go b/github/resource_github_repository_file.go index c84a8a195..ede8dada0 100644 --- a/github/resource_github_repository_file.go +++ b/github/resource_github_repository_file.go @@ -460,16 +460,14 @@ func resourceGithubRepositoryFileDelete(d *schema.ResourceData, meta interface{} 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 { @@ -503,9 +501,9 @@ func resourceGithubRepositoryFileDelete(d *schema.ResourceData, meta interface{} opts.Branch = &branch } - _, _, err := client.Repositories.DeleteFile(ctx, owner, repo, file, opts) + _, _, err = client.Repositories.DeleteFile(ctx, owner, repo, file, opts) if err != nil { - return nil + return err } return nil diff --git a/github/resource_github_repository_file_test.go b/github/resource_github_repository_file_test.go index 0a2da9aa5..c11ddd277 100644 --- a/github/resource_github_repository_file_test.go +++ b/github/resource_github_repository_file_test.go @@ -12,8 +12,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(` @@ -33,7 +31,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", @@ -111,7 +109,7 @@ func TestAccGithubRepositoryFile(t *testing.T) { commit_email = "terraform@example.com" } - `, randomID) + `, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)) check := resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -202,7 +200,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( @@ -280,7 +278,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(