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

Add members to organization data source. #811

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
32 changes: 32 additions & 0 deletions github/data_source_github_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ func dataSourceGithubOrganization() *schema.Resource {
Type: schema.TypeString,
},
},
"members": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}
Expand Down Expand Up @@ -81,12 +88,37 @@ func dataSourceGithubOrganizationRead(d *schema.ResourceData, meta interface{})
repoList = append(repoList, allRepos[index].GetFullName())
}

membershipOpts := &github.ListMembersOptions{
ListOptions: github.ListOptions{PerPage: 10, Page: 1},
}

var memberList []string
var allMembers []*github.User

for {
members, resp, err := client.Organizations.ListMembers(ctx, name, membershipOpts)
if err != nil {
return err
}
allMembers = append(allMembers, members...)

membershipOpts.Page = resp.NextPage

if resp.NextPage == 0 {
break
}
}
for index := range allMembers {
memberList = append(memberList, *allMembers[index].Login)
}

d.SetId(strconv.FormatInt(organization.GetID(), 10))
d.Set("login", organization.GetLogin())
d.Set("name", organization.GetName())
d.Set("description", organization.GetDescription())
d.Set("plan", plan.Name)
d.Set("repositories", repoList)
d.Set("members", memberList)

return nil
}
1 change: 1 addition & 0 deletions github/data_source_github_organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestAccGithubOrganizationDataSource(t *testing.T) {
resource.TestCheckResourceAttrSet("data.github_organization.test", "description"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "plan"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "repositories.#"),
resource.TestCheckResourceAttrSet("data.github_organization.test", "members.#"),
)

testCase := func(t *testing.T, mode string) {
Expand Down