diff --git a/github/github.go b/github/github.go index 7cdd73eb25e..ebb56605e4f 100644 --- a/github/github.go +++ b/github/github.go @@ -801,7 +801,11 @@ func parseTokenExpiration(r *http.Response) Timestamp { type requestContext uint8 const ( - bypassRateLimitCheck requestContext = iota + // BypassRateLimitCheck prevents a pre-emptive check for exceeded primary rate limits + // Specify this by providing a context with this key, e.g. + // context.WithValue(context.Background(), github.BypassRateLimitCheck, true) + BypassRateLimitCheck requestContext = iota + SleepUntilPrimaryRateLimitResetWhenRateLimited ) @@ -822,7 +826,7 @@ func (c *Client) BareDo(ctx context.Context, req *http.Request) (*Response, erro rateLimitCategory := GetRateLimitCategory(req.Method, req.URL.Path) - if bypass := ctx.Value(bypassRateLimitCheck); bypass == nil { + if bypass := ctx.Value(BypassRateLimitCheck); bypass == nil { // If we've hit rate limit, don't make further requests before Reset time. if err := c.checkRateLimitBeforeDo(req, rateLimitCategory); err != nil { return &Response{ diff --git a/github/github_test.go b/github/github_test.go index 43c9bde4f82..f2957242d78 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -231,7 +231,7 @@ func testNewRequestAndDoFailureCategory(t *testing.T, methodName string, client client.BaseURL.Path = "/api-v3/" client.rateLimits[category].Reset.Time = time.Now().Add(10 * time.Minute) resp, err = f() - if bypass := resp.Request.Context().Value(bypassRateLimitCheck); bypass != nil { + if bypass := resp.Request.Context().Value(BypassRateLimitCheck); bypass != nil { return } if want := http.StatusForbidden; resp == nil || resp.Response.StatusCode != want { diff --git a/github/rate_limit.go b/github/rate_limit.go index 5b01b573d8a..d55c545e7a5 100644 --- a/github/rate_limit.go +++ b/github/rate_limit.go @@ -77,7 +77,7 @@ func (s *RateLimitService) Get(ctx context.Context) (*RateLimits, *Response, err }) // This resource is not subject to rate limits. - ctx = context.WithValue(ctx, bypassRateLimitCheck, true) + ctx = context.WithValue(ctx, BypassRateLimitCheck, true) resp, err := s.client.Do(ctx, req, response) if err != nil { return nil, resp, err