From ad63fe1003d2458d7f9f04cedb9199e13e51af70 Mon Sep 17 00:00:00 2001 From: Camilo Roca Date: Thu, 17 Mar 2022 16:37:35 +0100 Subject: [PATCH 1/2] fix: use pagination to fetch all team members --- github/resource_github_team_members.go | 49 ++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/github/resource_github_team_members.go b/github/resource_github_team_members.go index 7726afcac0..fb7603a603 100644 --- a/github/resource_github_team_members.go +++ b/github/resource_github_team_members.go @@ -205,17 +205,52 @@ func resourceGithubTeamMembersRead(d *schema.ResourceData, meta interface{}) err ctx = context.WithValue(ctx, ctxEtag, d.Get("etag").(string)) } + etags := make([]string, 0) // List members & maintainers as list 'all' drops role information log.Printf("[DEBUG] Reading team members: %s", teamIdString) - members, resp1, err := client.Teams.ListTeamMembersByID(ctx, orgId, teamId, &github.TeamListTeamMembersOptions{Role: "member"}) - if err != nil { - return err + memberOptions := github.TeamListTeamMembersOptions{ + ListOptions: github.ListOptions{ + PerPage: maxPerPage, + }, + Role: "member", + } + + var members []*github.User + for { + member, resp, err := client.Teams.ListTeamMembersByID(ctx, orgId, teamId, &memberOptions) + if err != nil { + return err + } + + etags = append(etags, resp.Header.Get("ETag")) + members = append(members, member...) + if resp.NextPage == 0 { + break + } + memberOptions.Page = resp.NextPage } log.Printf("[DEBUG] Reading team maintainers: %s", teamIdString) - maintainers, resp2, err := client.Teams.ListTeamMembersByID(ctx, orgId, teamId, &github.TeamListTeamMembersOptions{Role: "maintainer"}) - if err != nil { - return err + maintainerOptions := github.TeamListTeamMembersOptions{ + ListOptions: github.ListOptions{ + PerPage: maxPerPage, + }, + Role: "maintainer", + } + var maintainers []*github.User + for { + maintaner, resp, err := client.Teams.ListTeamMembersByID(ctx, orgId, teamId, &maintainerOptions) + if err != nil { + return err + } + + etags = append(etags, resp.Header.Get("ETag")) + maintainers = append(maintainers, maintaner...) + + if resp.NextPage == 0 { + break + } + maintainerOptions.Page = resp.NextPage } teamMembersAndMaintainers := make([]interface{}, len(members)+len(maintainers)) @@ -239,7 +274,7 @@ func resourceGithubTeamMembersRead(d *schema.ResourceData, meta interface{}) err } // Combine etag of both requests - d.Set("etag", buildTwoPartID(resp1.Header.Get("ETag"), resp2.Header.Get("ETag"))) + d.Set("etag", buildChecksumID(etags)) return nil } From bda6110a997d701ca69741cae8e53a977eae0532 Mon Sep 17 00:00:00 2001 From: Camilo Roca Date: Fri, 18 Mar 2022 09:01:50 +0100 Subject: [PATCH 2/2] chore: typo Co-authored-by: Pascal Hofmann --- github/resource_github_team_members.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/resource_github_team_members.go b/github/resource_github_team_members.go index fb7603a603..241a458857 100644 --- a/github/resource_github_team_members.go +++ b/github/resource_github_team_members.go @@ -273,7 +273,7 @@ func resourceGithubTeamMembersRead(d *schema.ResourceData, meta interface{}) err return err } - // Combine etag of both requests + // Combine etag of all requests d.Set("etag", buildChecksumID(etags)) return nil