diff --git a/internal/github/client.go b/internal/github/client.go index 40a87dd..b80db22 100644 --- a/internal/github/client.go +++ b/internal/github/client.go @@ -23,7 +23,10 @@ func NewClient(ctx context.Context, ghToken string) (*Client, error) { tc := oauth2.NewClient(ctx, ts) // use a rate limiter to handle better the github api limit // focuses on the secondary limit: https://github.com/google/go-github#rate-limiting - rateLimiter, err := github_ratelimit.NewRateLimitWaiterClient(tc.Transport) + rateLimiter, err := github_ratelimit.NewRateLimitWaiterClient( + tc.Transport, + github_ratelimit.WithLimitDetectedCallback(LogOnLimitDetected), + ) if err != nil { return nil, err } diff --git a/internal/github/ratelimit.go b/internal/github/ratelimit.go new file mode 100644 index 0000000..345b416 --- /dev/null +++ b/internal/github/ratelimit.go @@ -0,0 +1,11 @@ +package github + +import ( + "gha-file-sync/internal/log" + + "github.com/gofri/go-github-ratelimit/github_ratelimit" +) + +func LogOnLimitDetected(ctx *github_ratelimit.CallbackContext) { + log.Warnf("secondary rate limit detected, will continue at %v", ctx.SleepUntil) +}