fbe 0.23.3 → 0.23.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fbe/octo.rb +4 -3
- data/lib/fbe.rb +1 -1
- data/test/fbe/test_conclude.rb +6 -2
- data/test/fbe/test_octo.rb +34 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 157b3bb591e16d535883feb11b531f9f64a9b87dd078f858345a7f91cc29185d
|
4
|
+
data.tar.gz: bb1b991edbcec6cf8caaedb11e32e8359d5f0487d1339572f0e43e4cf296354f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9821935ea70538efc8847b7368ed2af195f40f348f07ab432f52712bdafa85b5c629455079d8697ca0c7b5a969c93233d99d133ae5744a1c7c7f359a26483d89
|
7
|
+
data.tar.gz: 105e6d4f0934d8ce1b166e43417c258944f0e502ee6de1fa8487f9ccbe656f1f9f67c5a50a76403a98f89986576e44aad6bb9f12d75e8ee7a2d7e096b67ccdcb
|
data/lib/fbe/octo.rb
CHANGED
@@ -87,7 +87,7 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
|
|
87
87
|
)
|
88
88
|
if options.sqlite_cache
|
89
89
|
maxsize = Filesize.from(options.sqlite_cache_maxsize || '10M').to_i
|
90
|
-
maxvsize = Filesize.from(options.
|
90
|
+
maxvsize = Filesize.from(options.sqlite_cache_maxvsize || '10K').to_i
|
91
91
|
store = Fbe::Middleware::SqliteStore.new(options.sqlite_cache, Fbe::VERSION, loog:, maxsize:, maxvsize:)
|
92
92
|
loog.info(
|
93
93
|
"Using HTTP cache in SQLite file: #{store.path} (" \
|
@@ -150,14 +150,14 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
|
|
150
150
|
.join("\n")
|
151
151
|
@loog.info(
|
152
152
|
"GitHub API trace (#{grouped.count} URLs vs #{@trace.count} requests, " \
|
153
|
-
"#{@origin.rate_limit
|
153
|
+
"#{@origin.rate_limit!.remaining} quota left):\n#{message}"
|
154
154
|
)
|
155
155
|
@trace.clear
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
159
|
def off_quota?(threshold: 50)
|
160
|
-
left = @origin.rate_limit
|
160
|
+
left = @origin.rate_limit!.remaining
|
161
161
|
if left < threshold
|
162
162
|
@loog.info("Too much GitHub API quota consumed already (#{left} < #{threshold}), stopping")
|
163
163
|
true
|
@@ -258,6 +258,7 @@ class Fbe::FakeOctokit
|
|
258
258
|
end
|
259
259
|
o
|
260
260
|
end
|
261
|
+
alias rate_limit! rate_limit
|
261
262
|
|
262
263
|
# Lists repositories for a user or organization.
|
263
264
|
#
|
data/lib/fbe.rb
CHANGED
data/test/fbe/test_conclude.rb
CHANGED
@@ -79,8 +79,12 @@ class TestConclude < Fbe::Test
|
|
79
79
|
}
|
80
80
|
)
|
81
81
|
stub_request(:get, 'https://api.github.com/rate_limit').to_return(
|
82
|
-
body: 'hm...', headers: { 'X-RateLimit-Remaining' => '777' }
|
83
|
-
|
82
|
+
{ body: 'hm...', headers: { 'X-RateLimit-Remaining' => '777' } },
|
83
|
+
{ body: 'hm...', headers: { 'X-RateLimit-Remaining' => '777' } },
|
84
|
+
{ body: 'hm...', headers: { 'X-RateLimit-Remaining' => '777' } },
|
85
|
+
{ body: 'hm...', headers: { 'X-RateLimit-Remaining' => '999' } },
|
86
|
+
{ body: 'hm...', headers: { 'X-RateLimit-Remaining' => '9' } }
|
87
|
+
)
|
84
88
|
global = {}
|
85
89
|
o = Fbe.octo(loog: Loog::NULL, options:, global:)
|
86
90
|
Fbe.conclude(fb:, judge: 'boom', loog: Loog::NULL, options:, global:) do
|
data/test/fbe/test_octo.rb
CHANGED
@@ -133,7 +133,9 @@ class TestOcto < Fbe::Test
|
|
133
133
|
def test_off_quota?
|
134
134
|
WebMock.disable_net_connect!
|
135
135
|
stub_request(:get, 'https://api.github.com/rate_limit').to_return(
|
136
|
-
body: '{}', headers: { 'X-RateLimit-Remaining' => '333' }
|
136
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '333' } },
|
137
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '333' } },
|
138
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '3' } }
|
137
139
|
)
|
138
140
|
stub_request(:get, 'https://api.github.com/user/42').to_return(
|
139
141
|
body: '', headers: { 'X-RateLimit-Remaining' => '3' }
|
@@ -147,7 +149,11 @@ class TestOcto < Fbe::Test
|
|
147
149
|
def test_off_quota_twice
|
148
150
|
WebMock.disable_net_connect!
|
149
151
|
stub_request(:get, 'https://api.github.com/rate_limit').to_return(
|
150
|
-
body: '{}', headers: { 'X-RateLimit-Remaining' => '333' }
|
152
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '333' } },
|
153
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '333' } },
|
154
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '333' } },
|
155
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '5555' } },
|
156
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '5' } }
|
151
157
|
)
|
152
158
|
stub_request(:get, 'https://api.github.com/user/42').to_return(
|
153
159
|
{ body: '', headers: { 'X-RateLimit-Remaining' => '5555' } },
|
@@ -239,7 +245,9 @@ class TestOcto < Fbe::Test
|
|
239
245
|
def test_pauses_when_quota_is_exceeded
|
240
246
|
WebMock.disable_net_connect!
|
241
247
|
stub_request(:get, 'https://api.github.com/rate_limit').to_return(
|
242
|
-
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
|
248
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } },
|
249
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '1' } },
|
250
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '10000' } }
|
243
251
|
)
|
244
252
|
o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new({ 'github_api_pause' => 0.01 }))
|
245
253
|
stub_request(:get, 'https://api.github.com/users/foo')
|
@@ -364,6 +372,8 @@ class TestOcto < Fbe::Test
|
|
364
372
|
loog = Loog::Buffer.new
|
365
373
|
WebMock.disable_net_connect!
|
366
374
|
stub_request(:get, 'https://api.github.com/rate_limit').to_return(
|
375
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } },
|
376
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } },
|
367
377
|
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
|
368
378
|
)
|
369
379
|
stub_request(:get, 'https://api.github.com/user/123').to_return do
|
@@ -386,8 +396,9 @@ class TestOcto < Fbe::Test
|
|
386
396
|
octo.repository('foo/bar')
|
387
397
|
octo.print_trace!(all: true, max: 9_999)
|
388
398
|
output = loog.to_s
|
389
|
-
assert_includes output, '3 URLs vs
|
399
|
+
assert_includes output, '3 URLs vs 6 requests'
|
390
400
|
assert_includes output, '222 quota left'
|
401
|
+
assert_includes output, '/rate_limit: 3'
|
391
402
|
assert_includes output, '/user/123: 1'
|
392
403
|
assert_includes output, '/repos/foo/bar: 2'
|
393
404
|
repo_index = output.index('/repos/foo/bar: 2')
|
@@ -524,4 +535,23 @@ class TestOcto < Fbe::Test
|
|
524
535
|
end
|
525
536
|
end
|
526
537
|
end
|
538
|
+
|
539
|
+
def test_fetch_rate_limit_by_making_new_request
|
540
|
+
WebMock.disable_net_connect!
|
541
|
+
stub_request(:get, 'https://api.github.com/rate_limit').to_return(
|
542
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '321' } }
|
543
|
+
).to_return(
|
544
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '123' } }
|
545
|
+
).to_return(
|
546
|
+
{ body: '{}', headers: { 'X-RateLimit-Remaining' => '1' } }
|
547
|
+
).to_raise(StandardError.new('no more requests to https://api.github.com/rate_limit'))
|
548
|
+
loog = Loog::Buffer.new
|
549
|
+
o = Fbe.octo(loog:, global: {}, options: Judges::Options.new)
|
550
|
+
refute_predicate(o, :off_quota?)
|
551
|
+
assert_match(/321 GitHub API quota left/, loog.to_s)
|
552
|
+
o.print_trace!(all: true)
|
553
|
+
assert_match(/123 quota left/, loog.to_s)
|
554
|
+
assert_predicate(o, :off_quota?)
|
555
|
+
assert_match(/1 GitHub API quota left/, loog.to_s)
|
556
|
+
end
|
527
557
|
end
|