Skip to content

Commit 4f660b5

Browse files
authored
create repository with internal visibility initially instead of changing it later (#794)
* create repository with internal visibility initially instead of changing it later * revert to only a test for creates repos with private visibility * add skippable test for creating internal repositories
1 parent 4e45222 commit 4f660b5

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

github/resource_github_repository.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,6 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er
309309
}
310310

311311
repoReq.Private = github.Bool(isPrivate)
312-
if isPrivate {
313-
repoReq.Visibility = github.String("private")
314-
} else {
315-
repoReq.Visibility = github.String("public")
316-
}
317312

318313
if template, ok := d.GetOk("template"); ok {
319314
templateConfigBlocks := template.([]interface{})
@@ -567,7 +562,7 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er
567562
log.Printf("[DEBUG] <<<<<<<<<<<<< Updating repository visibility from %s to %s", o, n)
568563
_, _, err = client.Repositories.Edit(ctx, owner, repoName, repoReq)
569564
if err != nil {
570-
if !strings.Contains(err.Error(), "422 Visibility is already private") {
565+
if !strings.Contains(err.Error(), fmt.Sprintf("422 Visibility is already %s", n.(string))) {
571566
return err
572567
}
573568
}

github/resource_github_repository_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,49 @@ func TestAccGithubRepositoryVisibility(t *testing.T) {
844844
})
845845
})
846846

847+
t.Run("creates repos with internal visibility", func(t *testing.T) {
848+
t.Skip("organization used in automated tests does not support internal repositories")
849+
850+
config := fmt.Sprintf(`
851+
resource "github_repository" "internal" {
852+
name = "tf-acc-test-visibility-internal-%s"
853+
visibility = "internal"
854+
}
855+
`, randomID)
856+
857+
check := resource.ComposeTestCheckFunc(
858+
resource.TestCheckResourceAttr(
859+
"github_repository.internal", "visibility",
860+
"internal",
861+
),
862+
)
863+
864+
testCase := func(t *testing.T, mode string) {
865+
resource.Test(t, resource.TestCase{
866+
PreCheck: func() { skipUnlessMode(t, mode) },
867+
Providers: testAccProviders,
868+
Steps: []resource.TestStep{
869+
{
870+
Config: config,
871+
Check: check,
872+
},
873+
},
874+
})
875+
}
876+
877+
t.Run("with an anonymous account", func(t *testing.T) {
878+
t.Skip("anonymous account not supported for this operation")
879+
})
880+
881+
t.Run("with an individual account", func(t *testing.T) {
882+
testCase(t, individual)
883+
})
884+
885+
t.Run("with an organization account", func(t *testing.T) {
886+
testCase(t, organization)
887+
})
888+
})
889+
847890
t.Run("updates repos to private visibility", func(t *testing.T) {
848891

849892
config := fmt.Sprintf(`

0 commit comments

Comments
 (0)