diff --git a/.gitignore b/.gitignore index 337726fdc7..93aa5a4d10 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ website/node_modules *.test *.iml *.tfvars +.vscode/ website/vendor diff --git a/github/data_source_github_repository.go b/github/data_source_github_repository.go index 6e20bfee3e..255da1676e 100644 --- a/github/data_source_github_repository.go +++ b/github/data_source_github_repository.go @@ -27,11 +27,13 @@ func dataSourceGithubRepository() *schema.Resource { "description": { Type: schema.TypeString, - Computed: true, + Default: nil, + Optional: true, }, "homepage_url": { Type: schema.TypeString, - Computed: true, + Default: "", + Optional: true, }, "private": { Type: schema.TypeBool, @@ -186,7 +188,7 @@ func dataSourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) er d.SetId(repoName) - d.Set("name", repoName) + d.Set("name", repo.GetName()) d.Set("description", repo.GetDescription()) d.Set("homepage_url", repo.GetHomepage()) d.Set("private", repo.GetPrivate()) @@ -207,6 +209,7 @@ func dataSourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) er d.Set("archived", repo.GetArchived()) d.Set("node_id", repo.GetNodeID()) d.Set("repo_id", repo.GetID()) + d.Set("has_projects", repo.GetHasProjects()) if repo.GetHasPages() { pages, _, err := client.Repositories.GetPagesInfo(context.TODO(), owner, repoName) @@ -216,6 +219,8 @@ func dataSourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) er if err := d.Set("pages", flattenPages(pages)); err != nil { return fmt.Errorf("error setting pages: %w", err) } + } else { + d.Set("pages", flattenPages(nil)) } err = d.Set("topics", flattenStringList(repo.Topics)) diff --git a/github/data_source_github_repository_test.go b/github/data_source_github_repository_test.go index 4063e85886..7350084293 100644 --- a/github/data_source_github_repository_test.go +++ b/github/data_source_github_repository_test.go @@ -151,4 +151,61 @@ func TestAccGithubRepositoryDataSource(t *testing.T) { }) + t.Run("checks defaults on a new repository", func(t *testing.T) { + + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + + config := fmt.Sprintf(` + + resource "github_repository" "test" { + name = "tf-acc-%s" + auto_init = true + } + + data "github_repository" "test" { + name = github_repository.test.name + } + `, randomID) + + check := resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "data.github_repository.test", "name", "tf-acc-"+randomID, + ), + resource.TestCheckResourceAttrSet( + "data.github_repository.test", "has_projects", + ), + resource.TestCheckResourceAttr( + "data.github_repository.test", "description", "", + ), + resource.TestCheckResourceAttr( + "data.github_repository.test", "homepage_url", "", + ), + resource.TestCheckResourceAttr( + "data.github_repository.test", "pages.#", "0", + ), + ) + + 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 individual account", func(t *testing.T) { + testCase(t, individual) + }) + + t.Run("with an organization account", func(t *testing.T) { + testCase(t, organization) + }) + + }) + }