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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c12118d96ea30271b8b724c90d498eb3cc34a679bbef6be04153a53eec96e8e
4
- data.tar.gz: 45363b59481ccff7b37d367acbabba81e7bddf0a649c204ac4e87559d9622729
3
+ metadata.gz: 157b3bb591e16d535883feb11b531f9f64a9b87dd078f858345a7f91cc29185d
4
+ data.tar.gz: bb1b991edbcec6cf8caaedb11e32e8359d5f0487d1339572f0e43e4cf296354f
5
5
  SHA512:
6
- metadata.gz: 04f4c500161bbb87de44b25e1c160c2c03276c4f4737589dea8691c76f0a4a24824b74d4b278db5ac777e306d8c01b7879434ced44ee28b9efcd0cf96c4b0ea9
7
- data.tar.gz: 1f75a0011d1be3518a72b99d8ffd5e6e4746b4a0a130d3e6507c145b389197419e788a2b0eb7e09fce0ba913ef0621be2754fcfa2000babb03bf58d0250b9748
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.sqlite_cache_maxxsize || '10K').to_i
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.remaining} quota left):\n#{message}"
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.remaining
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
@@ -10,5 +10,5 @@
10
10
  # License:: MIT
11
11
  module Fbe
12
12
  # Current version of the gem (changed by +.rultor.yml+ on every release)
13
- VERSION = '0.23.3' unless const_defined?(:VERSION)
13
+ VERSION = '0.23.5' unless const_defined?(:VERSION)
14
14
  end
@@ -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
- ).times(1)
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
@@ -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 4 requests'
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.3
4
+ version: 0.23.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko