Skip to content

Commit

Permalink
Merge pull request #26 from runwaylab/github-ratelimit-issues
Browse files Browse the repository at this point in the history
GitHub ratelimit issues
  • Loading branch information
GrantBirki authored May 21, 2024
2 parents eec87bd + 2cd24d1 commit 08c829b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/runway/services/github.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,22 @@ module Runway
# this is a blocking operation
def check_rate_limit!
# Octokit::RateLimit(@limit=5000, @remaining=4278, @resets_at=2024-04-29 06:23:52.0 UTC, @resets_in=1784)
rate_limit = @client.rate_limit
rate_limit = nil
begin
rate_limit = @client.rate_limit
rescue ex : KeyError
error_message = ex.message.not_nil!
if error_message.includes?("Missing hash key: HTTP::Headers::Key(@name=\"X-RateLimit-Limit\")")
# https://github.com/runwaylab/runway/issues/25
@log.debug { "GitHub API rate limit headers are missing - attempting to fetch the rate limit again" }
@client.get("rate_limit")
rate_limit = @client.rate_limit
else
raise ex
end
end

rate_limit = rate_limit.not_nil!

# if rate_limit.remaining is nil, exit early
if rate_limit.remaining.nil?
Expand Down

0 comments on commit 08c829b

Please sign in to comment.