Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions github/resource_github_repository_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions github/resource_github_repository_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand All @@ -33,7 +31,7 @@ func TestAccGithubRepositoryFile(t *testing.T) {
commit_author = "Terraform User"
commit_email = "[email protected]"
}
`, randomID)
`, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))
check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_repository_file.test", "content",
Expand Down Expand Up @@ -111,7 +109,7 @@ func TestAccGithubRepositoryFile(t *testing.T) {
commit_email = "[email protected]"
}

`, randomID)
`, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -202,7 +200,7 @@ func TestAccGithubRepositoryFile(t *testing.T) {
commit_author = "Terraform User"
commit_email = "[email protected]"
}
`, randomID)
`, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -280,7 +278,7 @@ func TestAccGithubRepositoryFile(t *testing.T) {
commit_email = "[email protected]"
autocreate_branch = false
}
`, randomID)
`, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
Expand Down