Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ee112b

Browse files
authored
fix: Fetch all GitHub teams on login (coder#2951)
This wasn't looping prior, so organizations with >100 teams couldn't login. Contributes to coder#2848.
1 parent 59facdd commit 5ee112b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

cli/server.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -771,10 +771,23 @@ func configureGithubOAuth2(accessURL *url.URL, clientID, clientSecret string, al
771771
return memberships, err
772772
},
773773
ListTeams: func(ctx context.Context, client *http.Client, org string) ([]*github.Team, error) {
774-
teams, _, err := github.NewClient(client).Teams.ListTeams(ctx, org, &github.ListOptions{
774+
opt := &github.ListOptions{
775+
// This is the maximum amount per-page that GitHub allows.
775776
PerPage: 100,
776-
})
777-
return teams, err
777+
}
778+
var allTeams []*github.Team
779+
for {
780+
teams, resp, err := github.NewClient(client).Teams.ListTeams(ctx, org, opt)
781+
if err != nil {
782+
return nil, err
783+
}
784+
allTeams = append(allTeams, teams...)
785+
if resp.NextPage == 0 {
786+
break
787+
}
788+
opt.Page = resp.NextPage
789+
}
790+
return allTeams, nil
778791
},
779792
}, nil
780793
}

0 commit comments

Comments
 (0)