Skip to content

Commit 71bbe3f

Browse files
authored
chore: Fix repo allow forking (#3094)
Signed-off-by: Steve Hipwell <steve.hipwell@gmail.com>
1 parent b46999d commit 71bbe3f

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

github/resource_github_repository.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,10 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository {
634634
}
635635

636636
// only configure allow forking if repository is not public
637-
allowForking, ok := d.Get("allow_forking").(bool)
638-
if ok && visibility != "public" {
639-
repository.AllowForking = github.Ptr(allowForking)
637+
if allowForking, ok := d.GetOk("allow_forking"); ok && visibility != "public" {
638+
if val, ok := allowForking.(bool); ok {
639+
repository.AllowForking = github.Ptr(val)
640+
}
640641
}
641642

642643
return repository

github/resource_github_repository_test.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ func TestAccGithubRepository(t *testing.T) {
571571

572572
t.Run("create_private_with_forking", func(t *testing.T) {
573573
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
574-
repoName := fmt.Sprintf("%svisibility-%s", testResourcePrefix, randomID)
574+
repoName := fmt.Sprintf("%s%s", testResourcePrefix, randomID)
575575

576576
config := fmt.Sprintf(`
577577
resource "github_repository" "test" {
@@ -597,6 +597,33 @@ func TestAccGithubRepository(t *testing.T) {
597597
})
598598
})
599599

600+
t.Run("create_private_with_forking_unset", func(t *testing.T) {
601+
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
602+
repoName := fmt.Sprintf("%s%s", testResourcePrefix, randomID)
603+
604+
config := fmt.Sprintf(`
605+
resource "github_repository" "test" {
606+
name = "%s"
607+
description = "A private repository with forking disabled"
608+
visibility = "private"
609+
}
610+
`, repoName)
611+
612+
resource.Test(t, resource.TestCase{
613+
PreCheck: func() { skipUnlessHasOrgs(t) },
614+
ProviderFactories: providerFactories,
615+
Steps: []resource.TestStep{
616+
{
617+
Config: config,
618+
Check: resource.ComposeTestCheckFunc(
619+
resource.TestCheckResourceAttr("github_repository.test", "visibility", "private"),
620+
resource.TestCheckResourceAttr("github_repository.test", "allow_forking", "false"),
621+
),
622+
},
623+
},
624+
})
625+
})
626+
600627
t.Run("configures vulnerability alerts for a private repository", func(t *testing.T) {
601628
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
602629
repoName := fmt.Sprintf("%sprv-vuln-%s", testResourcePrefix, randomID)

0 commit comments

Comments
 (0)