Skip to content

Commit

Permalink
Missing GitHub repository data source attributes (integrations#778)
Browse files Browse the repository at this point in the history
* has_projects

* description default

* Other attributes

* Test on name
  • Loading branch information
cnuss authored May 22, 2021
1 parent fc29bdb commit cb73a81
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ website/node_modules
*.test
*.iml
*.tfvars
.vscode/

website/vendor

Expand Down
11 changes: 8 additions & 3 deletions github/data_source_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand All @@ -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)
Expand All @@ -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))
Expand Down
57 changes: 57 additions & 0 deletions github/data_source_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

})

}

0 comments on commit cb73a81

Please sign in to comment.