Skip to content

Commit

Permalink
export BypassRateLimitCheck to allow toggling of rate limit checks …
Browse files Browse the repository at this point in the history
…by consumers
  • Loading branch information
manicminer committed Dec 13, 2024
1 parent 7bc4871 commit edb51b3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ func parseTokenExpiration(r *http.Response) Timestamp {
type requestContext uint8

const (
bypassRateLimitCheck requestContext = iota
BypassRateLimitCheck requestContext = iota
SleepUntilPrimaryRateLimitResetWhenRateLimited
)

Expand All @@ -822,7 +822,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{
Expand Down
2 changes: 1 addition & 1 deletion github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion github/rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit edb51b3

Please sign in to comment.