Skip to content
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

Missing GitHub repository data source attributes #778

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
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)
})

})

}