From 88d9f10de03a2dda6ddea3c6a875e430aa9fac3c Mon Sep 17 00:00:00 2001 From: Mitja Adebahr Date: Thu, 11 Feb 2021 16:40:41 +0100 Subject: [PATCH] Use pagination to retrieve all team members --- github/data_source_github_team.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/github/data_source_github_team.go b/github/data_source_github_team.go index 312ba87f5e..9996a3fc5e 100644 --- a/github/data_source_github_team.go +++ b/github/data_source_github_team.go @@ -2,6 +2,7 @@ package github import ( "context" + "github.com/google/go-github/v32/github" "log" "strconv" @@ -59,14 +60,27 @@ func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error { return err } - member, _, err := client.Teams.ListTeamMembersByID(ctx, orgId, team.GetID(), nil) - if err != nil { - return err + options := github.TeamListTeamMembersOptions{ + ListOptions: github.ListOptions{ + PerPage: maxPerPage, + }, } - members := []string{} - for _, v := range member { - members = append(members, v.GetLogin()) + var members []string + for { + member, resp, err := client.Teams.ListTeamMembersByID(ctx, orgId, team.GetID(), &options) + if err != nil { + return err + } + + for _, v := range member { + members = append(members, v.GetLogin()) + } + + if resp.NextPage == 0 { + break + } + options.Page = resp.NextPage } d.SetId(strconv.FormatInt(team.GetID(), 10))