Skip to content

create repository with internal visibility initially instead of changing it later #794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
7 changes: 1 addition & 6 deletions github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,6 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er
}

repoReq.Private = github.Bool(isPrivate)
if isPrivate {
repoReq.Visibility = github.String("private")
} else {
repoReq.Visibility = github.String("public")
}
Comment on lines -312 to -316
Copy link
Contributor Author

@jtgrohn jtgrohn May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block was incorrectly overriding the Visibility property which was already set on line 262 by the call to resourceGithubRepositoryObject on line 287


if template, ok := d.GetOk("template"); ok {
templateConfigBlocks := template.([]interface{})
Expand Down Expand Up @@ -567,7 +562,7 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er
log.Printf("[DEBUG] <<<<<<<<<<<<< Updating repository visibility from %s to %s", o, n)
_, _, err = client.Repositories.Edit(ctx, owner, repoName, repoReq)
if err != nil {
if !strings.Contains(err.Error(), "422 Visibility is already private") {
if !strings.Contains(err.Error(), fmt.Sprintf("422 Visibility is already %s", n.(string))) {
return err
}
}
Expand Down
43 changes: 43 additions & 0 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,49 @@ func TestAccGithubRepositoryVisibility(t *testing.T) {
})
})

t.Run("creates repos with internal visibility", func(t *testing.T) {
t.Skip("organization used in automated tests does not support internal repositories")

config := fmt.Sprintf(`
resource "github_repository" "internal" {
name = "tf-acc-test-visibility-internal-%s"
visibility = "internal"
}
`, randomID)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_repository.internal", "visibility",
"internal",
),
)

testCase := func(t *testing.T, mode string) {
resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessMode(t, mode) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
}

t.Run("with an anonymous account", func(t *testing.T) {
t.Skip("anonymous account not supported for this operation")
})

t.Run("with an individual account", func(t *testing.T) {
testCase(t, individual)
})

t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})
})

t.Run("updates repos to private visibility", func(t *testing.T) {

config := fmt.Sprintf(`
Expand Down