From ec4dc099c576ca6385441b92e42ecaaddcbaae07 Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Thu, 6 May 2021 11:41:36 -0700 Subject: [PATCH 1/4] has_projects --- .gitignore | 1 + github/data_source_github_repository.go | 1 + github/data_source_github_repository_test.go | 45 ++++++++++++++++++++ 3 files changed, 47 insertions(+) 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..595fc44f20 100644 --- a/github/data_source_github_repository.go +++ b/github/data_source_github_repository.go @@ -207,6 +207,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) diff --git a/github/data_source_github_repository_test.go b/github/data_source_github_repository_test.go index 4063e85886..8a7addb81a 100644 --- a/github/data_source_github_repository_test.go +++ b/github/data_source_github_repository_test.go @@ -151,4 +151,49 @@ func TestAccGithubRepositoryDataSource(t *testing.T) { }) + t.Run("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.TestCheckResourceAttrSet( + "data.github_repository.test", "has_projects", + ), + ) + + 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) + }) + + }) + } From 87bed62e36d1ae8268947fcfc269026cac82da71 Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Thu, 6 May 2021 12:04:57 -0700 Subject: [PATCH 2/4] description default --- github/data_source_github_repository.go | 3 ++- github/data_source_github_repository_test.go | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/github/data_source_github_repository.go b/github/data_source_github_repository.go index 595fc44f20..dc990f85d3 100644 --- a/github/data_source_github_repository.go +++ b/github/data_source_github_repository.go @@ -27,6 +27,7 @@ func dataSourceGithubRepository() *schema.Resource { "description": { Type: schema.TypeString, + Default: nil, Computed: true, }, "homepage_url": { @@ -186,7 +187,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()) diff --git a/github/data_source_github_repository_test.go b/github/data_source_github_repository_test.go index 8a7addb81a..e32190630b 100644 --- a/github/data_source_github_repository_test.go +++ b/github/data_source_github_repository_test.go @@ -171,6 +171,9 @@ func TestAccGithubRepositoryDataSource(t *testing.T) { resource.TestCheckResourceAttrSet( "data.github_repository.test", "has_projects", ), + resource.TestCheckResourceAttr( + "data.github_repository.test", "description", "", + ), ) testCase := func(t *testing.T, mode string) { From 898b0e843dbea064ebed14494adad00d3fe70b7e Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Thu, 6 May 2021 12:18:55 -0700 Subject: [PATCH 3/4] Other attributes --- github/data_source_github_repository.go | 7 +++++-- github/data_source_github_repository_test.go | 14 ++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/github/data_source_github_repository.go b/github/data_source_github_repository.go index dc990f85d3..255da1676e 100644 --- a/github/data_source_github_repository.go +++ b/github/data_source_github_repository.go @@ -28,11 +28,12 @@ func dataSourceGithubRepository() *schema.Resource { "description": { Type: schema.TypeString, Default: nil, - Computed: true, + Optional: true, }, "homepage_url": { Type: schema.TypeString, - Computed: true, + Default: "", + Optional: true, }, "private": { Type: schema.TypeBool, @@ -218,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 e32190630b..fbf2aa1fb7 100644 --- a/github/data_source_github_repository_test.go +++ b/github/data_source_github_repository_test.go @@ -151,7 +151,7 @@ func TestAccGithubRepositoryDataSource(t *testing.T) { }) - t.Run("defaults on a new repository", func(t *testing.T) { + t.Run("checks defaults on a new repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) @@ -174,6 +174,12 @@ func TestAccGithubRepositoryDataSource(t *testing.T) { 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) { @@ -189,9 +195,9 @@ func TestAccGithubRepositoryDataSource(t *testing.T) { }) } - //t.Run("with an individual account", func(t *testing.T) { - // testCase(t, individual) - //}) + 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) From bfe40bf44c6f2876ab8da7f3c8052fb010891192 Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Thu, 6 May 2021 12:22:13 -0700 Subject: [PATCH 4/4] Test on name --- github/data_source_github_repository_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/github/data_source_github_repository_test.go b/github/data_source_github_repository_test.go index fbf2aa1fb7..7350084293 100644 --- a/github/data_source_github_repository_test.go +++ b/github/data_source_github_repository_test.go @@ -168,6 +168,9 @@ func TestAccGithubRepositoryDataSource(t *testing.T) { `, randomID) check := resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "data.github_repository.test", "name", "tf-acc-"+randomID, + ), resource.TestCheckResourceAttrSet( "data.github_repository.test", "has_projects", ),