fix: Fetch all GitHub teams on login (#2951)

This wasn't looping prior, so organizations with >100 teams
couldn't login. Contributes to #2848.
This commit is contained in:
Kyle Carberry 2022-07-12 18:06:27 -05:00 committed by GitHub
parent 59facdd8dc
commit 5ee112bc00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 3 deletions

View File

@ -771,10 +771,23 @@ func configureGithubOAuth2(accessURL *url.URL, clientID, clientSecret string, al
return memberships, err
},
ListTeams: func(ctx context.Context, client *http.Client, org string) ([]*github.Team, error) {
teams, _, err := github.NewClient(client).Teams.ListTeams(ctx, org, &github.ListOptions{
opt := &github.ListOptions{
// This is the maximum amount per-page that GitHub allows.
PerPage: 100,
})
return teams, err
}
var allTeams []*github.Team
for {
teams, resp, err := github.NewClient(client).Teams.ListTeams(ctx, org, opt)
if err != nil {
return nil, err
}
allTeams = append(allTeams, teams...)
if resp.NextPage == 0 {
break
}
opt.Page = resp.NextPage
}
return allTeams, nil
},
}, nil
}