vishwa5772 2 months ago committed by GitHub
parent
commit
e5fa997c5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 15
      connector/github/github.go

15
connector/github/github.go

@ -343,6 +343,14 @@ func formatTeamName(org string, team string) string {
func (c *githubConnector) groupsForOrgs(ctx context.Context, client *http.Client, userName string) ([]string, error) { func (c *githubConnector) groupsForOrgs(ctx context.Context, client *http.Client, userName string) ([]string, error) {
groups := make([]string, 0) groups := make([]string, 0)
var inOrgNoTeams bool var inOrgNoTeams bool
// Fetch all user teams once to avoid redundant API calls across multiple orgs.
// This prevents fetching the same team data repeatedly when iterating through orgs.
allTeamsByOrg, err := c.userOrgTeams(ctx, client)
if err != nil {
return nil, fmt.Errorf("github: get teams: %v", err)
}
for _, org := range c.orgs { for _, org := range c.orgs {
inOrg, err := c.userInOrg(ctx, client, userName, org.Name) inOrg, err := c.userInOrg(ctx, client, userName, org.Name)
if err != nil { if err != nil {
@ -352,10 +360,9 @@ func (c *githubConnector) groupsForOrgs(ctx context.Context, client *http.Client
continue continue
} }
teams, err := c.teamsForOrg(ctx, client, org.Name) // Use cached teams from the single fetch above instead of fetching per-org
if err != nil { teams := allTeamsByOrg[org.Name]
return nil, err
}
// User is in at least one org. User is authorized if no teams are specified // User is in at least one org. User is authorized if no teams are specified
// in config; include all teams in claim. Otherwise filter out teams not in // in config; include all teams in claim. Otherwise filter out teams not in
// 'teams' list in config. // 'teams' list in config.

Loading…
Cancel
Save