Skip to content
14 changes: 6 additions & 8 deletions github/resource_github_repository_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,16 +460,14 @@

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,7 +501,7 @@
opts.Branch = &branch
}

_, _, err := client.Repositories.DeleteFile(ctx, owner, repo, file, opts)

Check failure on line 504 in github/resource_github_repository_file.go

View workflow job for this annotation

GitHub Actions / ci

no new variables on left side of :=

Check failure on line 504 in github/resource_github_repository_file.go

View workflow job for this annotation

GitHub Actions / ci

no new variables on left side of :=) (typecheck)
return handleArchivedRepoDelete(err, "repository file", file, owner, repo)
}

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 @@

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 @@
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",
Expand Down Expand Up @@ -111,7 +109,7 @@
commit_email = "terraform@example.com"
}

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

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -202,7 +200,7 @@
commit_author = "Terraform User"
commit_email = "terraform@example.com"
}
`, randomID)
`, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -280,7 +278,7 @@
commit_email = "terraform@example.com"
autocreate_branch = false
}
`, randomID)
`, acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -362,7 +360,7 @@
commit_author = "Terraform User"
commit_email = "terraform@example.com"
}
`, randomID)

Check failure on line 363 in github/resource_github_repository_file_test.go

View workflow job for this annotation

GitHub Actions / ci

undefined: randomID

archivedConfig := strings.Replace(config,
`auto_init = true`,
Expand Down Expand Up @@ -401,7 +399,7 @@
auto_init = true
archived = true
}
`, randomID),

Check failure on line 402 in github/resource_github_repository_file_test.go

View workflow job for this annotation

GitHub Actions / ci

undefined: randomID (typecheck)
},
},
})
Expand Down
Loading