fbe 0.21.1 → 0.21.3

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: 10045af8e71603e4647d934f3b10afa96385ebca7dc678911ff5e443be0af638
4
- data.tar.gz: c8fe68b60de2232967d242733764f1025b2c9d0b8884114c6480c7b345d0fd3b
3
+ metadata.gz: 94437e7a9ee360556e5efadf0dda8990f44ae8b5166cb12682b4f77d4d8c054f
4
+ data.tar.gz: 042b18778e3007c9ea15a6ac60a0f76aa7dfe9f471c2523b657291e9a72df72d
5
5
  SHA512:
6
- metadata.gz: fd3fc1d0b158be59858edf4292027e71c73bffd8c1cbc7ef45ae743c9e9b521fe4faf4ab1995999fad3e3c798107d75925d74cc3ae8fd130cc535901259d68fc
7
- data.tar.gz: d7d494cf9f5c5f4b5899be7caad9d4fdaa5203483c8bdd450117ea86241b0894df164d16d2c42505fda6c7e50627c803ed58f5e9d7910c7406f77cd4cc601dfb
6
+ metadata.gz: 9566f00402a00f1235452c6ab352b6e2824d1d930b2068c3a10f6acd8201093a6c54a096b987a2603f867927bd1b33402865b48327a8f52559c32ae1927beefe
7
+ data.tar.gz: 27ce07102a08f9324c6261eedc1bc76d249267df198a1e8834c2ab104a034e9cc7a307e49f8b5aab4dc974a5f6d5f01ad10370c0ced8005b7ccd83543ea350ca
data/Gemfile.lock CHANGED
@@ -43,18 +43,18 @@ GEM
43
43
  ast (2.4.3)
44
44
  backtrace (0.4.1)
45
45
  base64 (0.3.0)
46
- baza.rb (0.5.1)
47
- backtrace (> 0)
48
- elapsed (> 0)
49
- faraday (> 0)
50
- faraday-http-cache (> 0)
51
- faraday-multipart (> 0)
52
- faraday-retry (> 0)
53
- iri (> 0)
54
- loog (> 0)
55
- retries (~> 0)
56
- tago (~> 0)
57
- typhoeus (~> 1.3)
46
+ baza.rb (0.9.5)
47
+ backtrace (~> 0.4)
48
+ elapsed (~> 0.0)
49
+ faraday (~> 2.13)
50
+ faraday-http-cache (~> 2.5)
51
+ faraday-multipart (~> 1.1)
52
+ faraday-retry (~> 2.3)
53
+ iri (~> 0.11)
54
+ loog (~> 0.6)
55
+ retries (~> 0.0)
56
+ tago (~> 0.0)
57
+ typhoeus (~> 1.4)
58
58
  benchmark (0.4.1)
59
59
  bigdecimal (3.2.2)
60
60
  builder (3.3.0)
@@ -87,11 +87,11 @@ GEM
87
87
  logger
88
88
  faraday-http-cache (2.5.1)
89
89
  faraday (>= 0.8)
90
- faraday-multipart (1.1.0)
90
+ faraday-multipart (1.1.1)
91
91
  multipart-post (~> 2.0)
92
- faraday-net_http (3.4.0)
92
+ faraday-net_http (3.4.1)
93
93
  net-http (>= 0.5.0)
94
- faraday-retry (2.3.1)
94
+ faraday-retry (2.3.2)
95
95
  faraday (~> 2.0)
96
96
  ffi (1.17.2-arm64-darwin)
97
97
  ffi (1.17.2-x64-mingw-ucrt)
@@ -112,7 +112,7 @@ GEM
112
112
  concurrent-ruby (~> 1.0)
113
113
  iri (0.11.2)
114
114
  json (2.12.2)
115
- judges (0.46.0)
115
+ judges (0.50.3)
116
116
  backtrace (~> 0.4)
117
117
  baza.rb (~> 0.5)
118
118
  concurrent-ruby (~> 1.2)
@@ -131,7 +131,7 @@ GEM
131
131
  typhoeus (~> 1.3)
132
132
  language_server-protocol (3.17.0.5)
133
133
  lint_roller (1.1.0)
134
- liquid (5.8.6)
134
+ liquid (5.8.7)
135
135
  bigdecimal
136
136
  strscan (>= 3.1.1)
137
137
  logger (1.7.0)
@@ -161,8 +161,8 @@ GEM
161
161
  faraday (>= 1, < 3)
162
162
  sawyer (~> 0.9)
163
163
  os (1.1.4)
164
- ostruct (0.6.1)
165
- others (0.0.3)
164
+ ostruct (0.6.2)
165
+ others (0.1.1)
166
166
  parallel (1.27.0)
167
167
  parser (3.3.8.0)
168
168
  ast (~> 2.4.1)
@@ -219,10 +219,10 @@ GEM
219
219
  simplecov (~> 0.19)
220
220
  simplecov-html (0.13.1)
221
221
  simplecov_json_formatter (0.1.4)
222
- sqlite3 (2.6.0-arm64-darwin)
223
- sqlite3 (2.6.0-x64-mingw-ucrt)
224
- sqlite3 (2.6.0-x86_64-darwin)
225
- sqlite3 (2.6.0-x86_64-linux-gnu)
222
+ sqlite3 (2.7.0-arm64-darwin)
223
+ sqlite3 (2.7.0-x64-mingw-ucrt)
224
+ sqlite3 (2.7.0-x86_64-darwin)
225
+ sqlite3 (2.7.0-x86_64-linux-gnu)
226
226
  strscan (3.1.5)
227
227
  tago (0.1.0)
228
228
  timeout (0.4.3)
data/fbe.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  'manipulate the facts and create new ones'
19
19
  s.authors = ['Yegor Bugayenko']
20
20
  s.email = 'yegor256@gmail.com'
21
- s.homepage = 'http://github.com/zerocracy/fbe'
21
+ s.homepage = 'https://github.com/zerocracy/fbe'
22
22
  s.files = `git ls-files`.split($RS)
23
23
  s.rdoc_options = ['--charset=UTF-8']
24
24
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
data/lib/fbe/if_absent.rb CHANGED
@@ -51,7 +51,11 @@ def Fbe.if_absent(fb: Fbe.fb)
51
51
  others(map: attrs) do |*args|
52
52
  k = args[0]
53
53
  if k.end_with?('=')
54
- @map[k[0..-2].to_sym] = args[1]
54
+ k = k[0..-2].to_sym
55
+ v = args[1]
56
+ raise "Can't set #{k} to nil" if v.nil?
57
+ raise "Can't set #{k} to empty string" if v.is_a?(String) && v.empty?
58
+ @map[k] = v
55
59
  else
56
60
  @map[k.to_sym]
57
61
  end
data/lib/fbe/octo.rb CHANGED
@@ -10,6 +10,7 @@ require 'faraday/retry'
10
10
  require 'loog'
11
11
  require 'obk'
12
12
  require 'octokit'
13
+ require 'others'
13
14
  require 'uri'
14
15
  require 'verbose'
15
16
  require_relative '../fbe'
@@ -116,62 +117,71 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
116
117
  loog.debug('The connection to GitHub API is mocked')
117
118
  o = Fbe::FakeOctokit.new
118
119
  end
119
- decoor(o, loog:, trace:) do
120
- def print_trace!
121
- if @trace.empty?
122
- @loog.debug('GitHub API trace is empty')
123
- else
124
- grouped =
125
- @trace.group_by do |entry|
126
- uri = URI.parse(entry[:url])
127
- "#{uri.scheme}://#{uri.host}#{uri.path}"
128
- end
129
- message = grouped
130
- .sort_by { |_path, entries| -entries.count }
131
- .map { |path, entries| " #{path}: #{entries.count}" }
132
- .join("\n")
133
- @loog.info("GitHub API trace (#{grouped.count} URLs vs #{@trace.count} requests):\n#{message}")
134
- @trace.clear
120
+ o =
121
+ decoor(o, loog:, trace:) do
122
+ def print_trace!
123
+ if @trace.empty?
124
+ @loog.debug('GitHub API trace is empty')
125
+ else
126
+ grouped =
127
+ @trace.group_by do |entry|
128
+ uri = URI.parse(entry[:url])
129
+ "#{uri.scheme}://#{uri.host}#{uri.path}"
130
+ end
131
+ message = grouped
132
+ .sort_by { |_path, entries| -entries.count }
133
+ .map { |path, entries| " #{path}: #{entries.count}" }
134
+ .join("\n")
135
+ @loog.info("GitHub API trace (#{grouped.count} URLs vs #{@trace.count} requests):\n#{message}")
136
+ @trace.clear
137
+ end
135
138
  end
136
- end
137
139
 
138
- def off_quota?(threshold: 50)
139
- left = @origin.rate_limit.remaining
140
- if left < threshold
141
- @loog.info("Too much GitHub API quota consumed already (#{left} < #{threshold}), stopping")
142
- true
143
- else
144
- @loog.debug("Still #{left} GitHub API quota left (>#{threshold})")
145
- false
140
+ def off_quota?(threshold: 50)
141
+ left = @origin.rate_limit.remaining
142
+ if left < threshold
143
+ @loog.info("Too much GitHub API quota consumed already (#{left} < #{threshold}), stopping")
144
+ true
145
+ else
146
+ @loog.debug("Still #{left} GitHub API quota left (>#{threshold})")
147
+ false
148
+ end
146
149
  end
147
- end
148
150
 
149
- def user_name_by_id(id)
150
- raise 'The ID of the user is nil' if id.nil?
151
- raise 'The ID of the user must be an Integer' unless id.is_a?(Integer)
152
- json = @origin.user(id)
153
- name = json[:login].downcase
154
- @loog.debug("GitHub user ##{id} has a name: @#{name}")
155
- name
156
- end
151
+ def user_name_by_id(id)
152
+ raise 'The ID of the user is nil' if id.nil?
153
+ raise 'The ID of the user must be an Integer' unless id.is_a?(Integer)
154
+ json = @origin.user(id)
155
+ name = json[:login].downcase
156
+ @loog.debug("GitHub user ##{id} has a name: @#{name}")
157
+ name
158
+ end
157
159
 
158
- def repo_id_by_name(name)
159
- raise 'The name of the repo is nil' if name.nil?
160
- json = @origin.repository(name)
161
- id = json[:id]
162
- @loog.debug("GitHub repository #{name.inspect} has an ID: ##{id}")
163
- id
164
- end
160
+ def repo_id_by_name(name)
161
+ raise 'The name of the repo is nil' if name.nil?
162
+ json = @origin.repository(name)
163
+ id = json[:id]
164
+ @loog.debug("GitHub repository #{name.inspect} has an ID: ##{id}")
165
+ id
166
+ end
165
167
 
166
- def repo_name_by_id(id)
167
- raise 'The ID of the repo is nil' if id.nil?
168
- raise 'The ID of the repo must be an Integer' unless id.is_a?(Integer)
169
- json = @origin.repository(id)
170
- name = json[:full_name].downcase
171
- @loog.debug("GitHub repository ##{id} has a name: #{name}")
172
- name
168
+ def repo_name_by_id(id)
169
+ raise 'The ID of the repo is nil' if id.nil?
170
+ raise 'The ID of the repo must be an Integer' unless id.is_a?(Integer)
171
+ json = @origin.repository(id)
172
+ name = json[:full_name].downcase
173
+ @loog.debug("GitHub repository ##{id} has a name: #{name}")
174
+ name
175
+ end
173
176
  end
174
- end
177
+ o =
178
+ others(o:) do |*args|
179
+ if args.first != :off_quota? && args.first != :print_trace! && @o.off_quota?
180
+ raise "We are off-quota (remaining: #{@o.rate_limit.remaining})"
181
+ end
182
+ @o.__send__(*args)
183
+ end
184
+ o
175
185
  end
176
186
  end
177
187
 
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.21.1' unless const_defined?(:VERSION)
13
+ VERSION = '0.21.3' unless const_defined?(:VERSION)
14
14
  end
@@ -24,6 +24,24 @@ class TestIfAbsent < Fbe::Test
24
24
  assert_nil(n)
25
25
  end
26
26
 
27
+ def test_raises_on_empty_value
28
+ assert_raises(StandardError) do
29
+ Fbe.if_absent(fb: Factbase.new) do |f|
30
+ f.foo = ''
31
+ end
32
+ end
33
+ end
34
+
35
+ def test_raises_on_nil
36
+ fb = Factbase.new
37
+ fb.insert.foo = 42
38
+ assert_raises(StandardError) do
39
+ Fbe.if_absent(fb: Factbase.new) do |f|
40
+ f.foo = nil
41
+ end
42
+ end
43
+ end
44
+
27
45
  def test_ignores_with_time
28
46
  fb = Factbase.new
29
47
  t = Time.now
@@ -53,8 +53,10 @@ class TestOcto < Fbe::Test
53
53
 
54
54
  def test_reads_nickname_by_id
55
55
  WebMock.disable_net_connect!
56
- global = {}
57
- o = Fbe.octo(loog: Loog::NULL, global:, options: Judges::Options.new)
56
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
57
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
58
+ )
59
+ o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new)
58
60
  stub_request(:get, 'https://api.github.com/user/42').to_return(
59
61
  body: { login: 'Dude56' }.to_json, headers: { 'Content-Type': 'application/json' }
60
62
  )
@@ -62,8 +64,29 @@ class TestOcto < Fbe::Test
62
64
  assert_equal('dude56', nick)
63
65
  end
64
66
 
67
+ def test_fails_user_request_when_off_quota
68
+ WebMock.disable_net_connect!
69
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
70
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '3' } }
71
+ )
72
+ o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new)
73
+ assert_raises(StandardError) { o.user(42) }
74
+ end
75
+
76
+ def test_no_failure_on_printing_when_off_quota
77
+ WebMock.disable_net_connect!
78
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
79
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '3' } }
80
+ )
81
+ o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new)
82
+ o.print_trace!
83
+ end
84
+
65
85
  def test_reads_repo_name_by_id
66
86
  WebMock.disable_net_connect!
87
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
88
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
89
+ )
67
90
  global = {}
68
91
  o = Fbe.octo(loog: Loog::NULL, global:, options: Judges::Options.new)
69
92
  stub_request(:get, 'https://api.github.com/repositories/42').to_return(
@@ -75,10 +98,16 @@ class TestOcto < Fbe::Test
75
98
 
76
99
  def test_caching
77
100
  WebMock.disable_net_connect!
101
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
102
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
103
+ )
78
104
  global = {}
79
105
  o = Fbe.octo(loog: Loog::NULL, global:, options: Judges::Options.new)
80
106
  stub_request(:get, 'https://api.github.com/users/yegor256')
81
- .to_return(body: '{}', headers: { 'Cache-Control' => 'public, max-age=60', 'etag' => 'abc' })
107
+ .to_return(
108
+ body: '{}',
109
+ headers: { 'Cache-Control' => 'public, max-age=60', 'etag' => 'abc', 'x-ratelimit-remaining' => '10000' }
110
+ )
82
111
  .times(1)
83
112
  .then
84
113
  .to_raise('second request should be cached, not passed to GitHub API!')
@@ -144,6 +173,9 @@ class TestOcto < Fbe::Test
144
173
 
145
174
  def test_retrying
146
175
  WebMock.disable_net_connect!
176
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
177
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
178
+ )
147
179
  global = {}
148
180
  o = Fbe.octo(loog: Loog::NULL, global:, options: Judges::Options.new)
149
181
  stub_request(:get, 'https://api.github.com/users/yegor256')
@@ -156,6 +188,9 @@ class TestOcto < Fbe::Test
156
188
 
157
189
  def test_retrying_on_error_response
158
190
  WebMock.disable_net_connect!
191
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
192
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
193
+ )
159
194
  global = {}
160
195
  o = Fbe.octo(loog: Loog::NULL, global:, options: Judges::Options.new)
161
196
  stub_request(:get, 'https://api.github.com/users/yegor256')
@@ -203,6 +238,9 @@ class TestOcto < Fbe::Test
203
238
 
204
239
  def test_pauses_when_quota_is_exceeded
205
240
  WebMock.disable_net_connect!
241
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
242
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
243
+ )
206
244
  o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new({ 'github_api_pause' => 0.01 }))
207
245
  stub_request(:get, 'https://api.github.com/users/foo')
208
246
  .to_return(
@@ -215,8 +253,6 @@ class TestOcto < Fbe::Test
215
253
  )
216
254
  o.user('foo')
217
255
  assert_predicate(o, :off_quota?)
218
- o.user('foo')
219
- refute_predicate(o, :off_quota?)
220
256
  end
221
257
 
222
258
  def test_fetches_fake_check_runs_for_ref
@@ -327,13 +363,18 @@ class TestOcto < Fbe::Test
327
363
  def test_print_trace
328
364
  loog = Loog::Buffer.new
329
365
  WebMock.disable_net_connect!
366
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
367
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
368
+ )
330
369
  stub_request(:get, 'https://api.github.com/user/123').to_return(
331
370
  status: 200,
332
- body: '{"id":123,"login":"test"}'
371
+ body: '{"id":123,"login":"test"}',
372
+ headers: { 'X-RateLimit-Remaining' => '222' }
333
373
  )
334
374
  stub_request(:get, 'https://api.github.com/repos/foo/bar').to_return(
335
375
  status: 200,
336
- body: '{"id":456,"full_name":"foo/bar"}'
376
+ body: '{"id":456,"full_name":"foo/bar"}',
377
+ headers: { 'X-RateLimit-Remaining' => '222' }
337
378
  )
338
379
  octo = Fbe.octo(loog:, global: {}, options: Judges::Options.new)
339
380
  octo.user(123)
@@ -341,7 +382,7 @@ class TestOcto < Fbe::Test
341
382
  octo.repository('foo/bar')
342
383
  octo.print_trace!
343
384
  output = loog.to_s
344
- assert_includes output, 'GitHub API trace (2 URLs vs 3 requests)'
385
+ assert_includes output, 'GitHub API trace (3 URLs vs 4 requests)'
345
386
  assert_includes output, 'https://api.github.com/user/123: 1'
346
387
  assert_includes output, 'https://api.github.com/repos/foo/bar: 2'
347
388
  repo_index = output.index('https://api.github.com/repos/foo/bar: 2')
@@ -351,9 +392,13 @@ class TestOcto < Fbe::Test
351
392
 
352
393
  def test_trace_gets_cleared_after_print
353
394
  WebMock.disable_net_connect!
395
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
396
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
397
+ )
354
398
  stub_request(:get, 'https://api.github.com/user/456').to_return(
355
399
  status: 200,
356
- body: '{"id":456,"login":"testuser"}'
400
+ body: '{"id":456,"login":"testuser"}',
401
+ headers: { 'X-RateLimit-Remaining' => '222' }
357
402
  )
358
403
  first_loog = Loog::Buffer.new
359
404
  octo = Fbe.octo(loog: first_loog, global: {}, options: Judges::Options.new)
@@ -361,15 +406,13 @@ class TestOcto < Fbe::Test
361
406
  octo.print_trace!
362
407
  first_output = first_loog.to_s
363
408
  assert_includes first_output, 'GitHub API trace'
364
- second_loog = Loog::Buffer.new
365
- octo.instance_variable_set(:@loog, second_loog)
366
- octo.print_trace!
367
- second_output = second_loog.to_s
368
- assert_includes second_output, 'GitHub API trace is empty'
369
409
  end
370
410
 
371
411
  def test_works_via_sqlite_store
372
412
  WebMock.disable_net_connect!
413
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
414
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
415
+ )
373
416
  Dir.mktmpdir do |dir|
374
417
  global = {}
375
418
  sqlite_cache = File.expand_path('test.db', dir)
@@ -394,6 +437,9 @@ class TestOcto < Fbe::Test
394
437
 
395
438
  def test_through_sqlite_store_when_broken_token
396
439
  WebMock.disable_net_connect!
440
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
441
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
442
+ )
397
443
  Dir.mktmpdir do |dir|
398
444
  global = {}
399
445
  file = File.expand_path('test.db', dir)
@@ -408,6 +454,9 @@ class TestOcto < Fbe::Test
408
454
 
409
455
  def test_sqlite_store_for_use_in_different_versions
410
456
  WebMock.disable_net_connect!
457
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
458
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
459
+ )
411
460
  Dir.mktmpdir do |dir|
412
461
  global = {}
413
462
  stub =
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.21.1
4
+ version: 0.21.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -358,7 +358,7 @@ files:
358
358
  - test/fbe/test_who.rb
359
359
  - test/test__helper.rb
360
360
  - test/test_fbe.rb
361
- homepage: http://github.com/zerocracy/fbe
361
+ homepage: https://github.com/zerocracy/fbe
362
362
  licenses:
363
363
  - MIT
364
364
  metadata: