Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/fbe/octo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,18 @@ def print_trace!(all: false, max: 5)
end
.take(max)
.join("\n")
quota =
begin
"#{@origin.rate_limit!.remaining} quota left"
rescue Octokit::ServerError, Octokit::Unauthorized, Octokit::Forbidden,
Faraday::ConnectionFailed, Faraday::TimeoutError => e
@loog.warn("Failed to check GitHub API quota for the trace: #{e.message}")
'quota unknown'
end
@loog.info(
"GitHub API trace (#{grouped.count} URLs vs #{shown.count} requests, " \
"#{@trace.count - shown.count} fast ones skipped, " \
"#{@origin.rate_limit!.remaining} quota left):\n#{message}"
"#{quota}):\n#{message}"
)
@trace.clear
end
Expand Down
18 changes: 18 additions & 0 deletions test/fbe/test_octo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,24 @@ def test_print_trace_counts_only_printed_requests
assert_operator(shown + skipped, :>=, total)
end

def test_print_trace_when_quota_can_not_be_read
loog = Loog::Buffer.new
WebMock.disable_net_connect!
stub_request(:get, 'https://api.github.com/rate_limit').to_return(
body: '{"rate":{"remaining":222}}', headers: { 'X-RateLimit-Remaining' => '222' }
)
stub_request(:get, 'https://api.github.com/repos/foo/bar').to_return(
body: '{"id":456,"full_name":"foo/bar"}', headers: { 'X-RateLimit-Remaining' => '220' }
)
octo = Fbe.octo(loog:, global: {}, options: Judges::Options.new)
octo.repository('foo/bar')
octo.instance_variable_get(:@origin).define_singleton_method(:rate_limit!) do
raise(Faraday::ConnectionFailed, 'GitHub is down')
end
octo.print_trace!(all: true)
assert_includes(loog.to_s, 'quota unknown')
end

def test_print_trace
loog = Loog::Buffer.new
WebMock.disable_net_connect!
Expand Down
Loading