Skip to content

Commit

Permalink
Syncing with upstream main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jspaleta committed Dec 10, 2024
2 parents 812447d + 4b5389c commit 6910cae
Show file tree
Hide file tree
Showing 182 changed files with 5,787 additions and 1,449 deletions.
2 changes: 1 addition & 1 deletion cmd/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"fmt"

gh "github.com/google/go-github/v59/github"
gh "github.com/google/go-github/v67/github"
"github.com/spf13/cobra"

"github.com/cilium/team-manager/pkg/config"
Expand Down
2 changes: 1 addition & 1 deletion cmd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"strings"

gh "github.com/google/go-github/v59/github"
gh "github.com/google/go-github/v67/github"
"github.com/spf13/cobra"

"github.com/cilium/team-manager/pkg/config"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/cilium/team-manager
go 1.22

require (
github.com/google/go-github/v59 v59.0.0
github.com/google/go-github/v67 v67.0.0
github.com/google/renameio v1.0.1
github.com/kr/pretty v0.3.1
github.com/pmezard/go-difflib v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v59 v59.0.0 h1:7h6bgpF5as0YQLLkEiVqpgtJqjimMYhBkD4jT5aN3VA=
github.com/google/go-github/v59 v59.0.0/go.mod h1:rJU4R0rQHFVFDOkqGWxfLNo6vEk4dv40oDjhV/gH6wM=
github.com/google/go-github/v67 v67.0.0 h1:g11NDAmfaBaCO8qYdI9fsmbaRipHNWRIU/2YGvlh4rg=
github.com/google/go-github/v67 v67.0.0/go.mod h1:zH3K7BxjFndr9QSeFibx4lTKkYS3K9nDanoI1NjaOtY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/renameio v1.0.1 h1:Lh/jXZmvZxb0BBeSY5VKEfidcbcbenKjZFzM/q0fSeU=
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"
"os"

gh "github.com/google/go-github/v59/github"
gh "github.com/google/go-github/v67/github"
"github.com/shurcooL/githubv4"
"golang.org/x/oauth2"
)
Expand Down
30 changes: 28 additions & 2 deletions pkg/team/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ package team

import (
"context"
"errors"
"fmt"
"sort"
"strings"
"time"

gh "github.com/google/go-github/v59/github"
gh "github.com/google/go-github/v67/github"
"github.com/schollz/progressbar/v3"
"github.com/shurcooL/githubv4"
"github.com/shurcooL/graphql"
Expand Down Expand Up @@ -110,7 +112,7 @@ func (tm *Manager) fetchRepositories(ctx context.Context, c *config.Config) erro
if requeryOrgs {
resultRepos, err = tm.queryOrgRepos(ctx, variables)
if err != nil {
return fmt.Errorf("failed to requery teams: %w", err)
return fmt.Errorf("failed to requery org repositories: %w", err)
}
requeryOrgs = false
}
Expand Down Expand Up @@ -582,3 +584,27 @@ func (tm *Manager) fetchMemberLimitedAvailability(ctx context.Context, login str

return bool(resultMember.User.Status.IndicatesLimitedAvailability), nil
}

func (tm *Manager) gqlQuery(ctx context.Context, q interface{}, variables map[string]interface{}) error {
var (
rateLimitError *gh.RateLimitError
abuseRateLimitError *gh.AbuseRateLimitError
)
for {
err := tm.gqlGHClient.Query(ctx, q, variables)
if err != nil {
switch {
case errors.As(err, &rateLimitError):
fmt.Printf("hit rate limit, sleeping for 30 seconds...\n")
time.Sleep(30 * time.Second)
case errors.As(err, &abuseRateLimitError) || strings.Contains(err.Error(), "You have exceeded a secondary rate limit"):
fmt.Printf("hit secondary limit, sleeping for 30 seconds...\n")
time.Sleep(30 * time.Second)
default:
return err
}
continue
}
return nil
}
}
2 changes: 1 addition & 1 deletion pkg/team/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/cilium/team-manager/pkg/github"
"github.com/cilium/team-manager/pkg/slices"
"github.com/cilium/team-manager/pkg/terminal"
gh "github.com/google/go-github/v59/github"
gh "github.com/google/go-github/v67/github"
"github.com/shurcooL/githubv4"
)

Expand Down
11 changes: 6 additions & 5 deletions pkg/team/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func (tm *Manager) queryOrgRepos(ctx context.Context, additionalVariables map[st
variables[k] = v
}

err := tm.gqlGHClient.Query(ctx, &q, variables)
err := tm.gqlQuery(ctx, &q, variables)

if err != nil {
return queryResultRepositories{}, err
}
Expand All @@ -52,7 +53,7 @@ func (tm *Manager) queryOrgMembers(ctx context.Context, additionalVariables map[
variables[k] = v
}

err := tm.gqlGHClient.Query(ctx, &q, variables)
err := tm.gqlQuery(ctx, &q, variables)
if err != nil {
return queryResultMembers{}, err
}
Expand All @@ -72,7 +73,7 @@ func (tm *Manager) queryTeamsRepositories(ctx context.Context, additionalVariabl
variables[k] = v
}

err := tm.gqlGHClient.Query(ctx, &q, variables)
err := tm.gqlQuery(ctx, &q, variables)
if err != nil {
return queryTeamsRepositoriesResult{}, err
}
Expand All @@ -92,7 +93,7 @@ func (tm *Manager) queryTeamsMembers(ctx context.Context, additionalVariables ma
variables[k] = v
}

err := tm.gqlGHClient.Query(ctx, &q, variables)
err := tm.gqlQuery(ctx, &q, variables)
if err != nil {
return queryTeamsMembersResult{}, err
}
Expand All @@ -110,7 +111,7 @@ func (tm *Manager) queryOrgMemberLimitedAvailability(ctx context.Context, additi
variables[k] = v
}

err := tm.gqlGHClient.Query(ctx, &q, variables)
err := tm.gqlQuery(ctx, &q, variables)
if err != nil {
return queryResultMemberLimitedAvailability{}, err
}
Expand Down
Loading

0 comments on commit 6910cae

Please sign in to comment.