fbe 0.7.0 → 0.7.1

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: af8e39332315cd637642316ea61761792955d43688813b75339b112b58747900
4
- data.tar.gz: 6a2fa9d6c135c1ec2500872ace2bba09d00a89fe87c1af6435e54e880f361df4
3
+ metadata.gz: e1ce252b4d0093ff1f94e319d2c65502e134dad520398ca018fad1820b9dac78
4
+ data.tar.gz: f0039a70dcd2533e2acd36f80b7ef3ac68441f1f68611b38ee07d9c67449ddf3
5
5
  SHA512:
6
- metadata.gz: 94a48b37c3d821a8c609e99accfc1fb350b1e317f2cb27c7d351a8a472ff1565edec77d4a3bd2a1d39c758c8e6faa71e5706a1a30fe0364bceffd25144466642
7
- data.tar.gz: 8073b49266007c50ae6989ffb1b006fbcddce056cb042be19f5ca39c4e99ad97b58ad77c598d51102b51ef77b9545a4f86fd29cf0323edb7fee9920ff6e65227
6
+ metadata.gz: 25191aefeccb723456f4de449c6f042ce628c895fc7f2e941f5e63e0685bfb2bccf550e04c288ff28e288acf8a4c0b57f3402b2826cae5ccb5da549c977f1ffe
7
+ data.tar.gz: 6362777ada12c805d463db462afbfbf5bab5d20b897565b798c2ede567d097f3250622d1a67656731e94f0ac8fc37fb604ace94c150e51e47c2a83ec14f4be60
data/Gemfile.lock CHANGED
@@ -70,7 +70,7 @@ GEM
70
70
  tago (> 0)
71
71
  ethon (0.16.0)
72
72
  ffi (>= 1.15.0)
73
- factbase (0.9.10)
73
+ factbase (0.10.0)
74
74
  backtrace (~> 0.4)
75
75
  decoor (~> 0.0)
76
76
  json (~> 2.7)
@@ -92,11 +92,11 @@ GEM
92
92
  net-http (>= 0.5.0)
93
93
  faraday-retry (2.3.1)
94
94
  faraday (~> 2.0)
95
- ffi (1.17.1-arm64-darwin)
96
- ffi (1.17.1-x64-mingw-ucrt)
97
- ffi (1.17.1-x86_64-darwin)
98
- ffi (1.17.1-x86_64-linux-gnu)
99
- fiber-storage (1.0.0)
95
+ ffi (1.17.2-arm64-darwin)
96
+ ffi (1.17.2-x64-mingw-ucrt)
97
+ ffi (1.17.2-x86_64-darwin)
98
+ ffi (1.17.2-x86_64-linux-gnu)
99
+ fiber-storage (1.0.1)
100
100
  gli (2.22.2)
101
101
  ostruct
102
102
  graphql (2.5.3)
data/lib/fbe/conclude.rb CHANGED
@@ -160,21 +160,20 @@ class Fbe::Conclude
160
160
  def roll(&)
161
161
  passed = 0
162
162
  start = Time.now
163
- catch :stop do
164
- @fb.txn do |fbt|
165
- fbt.query(@query).each do |a|
166
- if @quota_aware && Fbe.octo(loog: @loog, options: @options, global: @global).off_quota
167
- @loog.debug('We ran out of GitHub quota, must stop here')
168
- throw :stop
169
- end
170
- if Time.now > start + @timeout
171
- @loog.debug("We've spent more than #{start.ago}, must stop here")
172
- throw :stop
173
- end
174
- n = yield fbt, a
175
- @loog.info("#{n.what}: #{n.details}") unless n.nil?
176
- passed += 1
163
+ oct = Fbe.octo(loog: @loog, options: @options, global: @global)
164
+ @fb.txn do |fbt|
165
+ fbt.query(@query).each do |a|
166
+ if @quota_aware && oct.off_quota
167
+ @loog.debug('We ran out of GitHub quota, must stop here')
168
+ throw :commit
177
169
  end
170
+ if Time.now > start + @timeout
171
+ @loog.debug("We've spent more than #{start.ago}, must stop here")
172
+ throw :commit
173
+ end
174
+ n = yield fbt, a
175
+ @loog.info("#{n.what}: #{n.details}") unless n.nil?
176
+ passed += 1
178
177
  end
179
178
  end
180
179
  @loog.debug("Found and processed #{passed} facts by: #{@query}")
data/lib/fbe/octo.rb CHANGED
@@ -88,6 +88,7 @@ def Fbe.octo(options: $options, global: $global, loog: $loog)
88
88
  @loog.info("Too much GitHub API quota consumed already (#{left} < #{threshold}), stopping")
89
89
  true
90
90
  else
91
+ @loog.debug("Still #{left} GitHub API quota left (>#{threshold})")
91
92
  false
92
93
  end
93
94
  end
@@ -147,13 +148,14 @@ class Fbe::FakeOctokit
147
148
  true
148
149
  end
149
150
 
150
- def user(name)
151
- login = name
152
- login = name == 526_301 ? 'yegor256' : 'torvalds' if login.is_a?(Integer)
151
+ # Get details of the user.
152
+ # @param [String|Integer] uid The login of the user or its ID
153
+ def user(uid)
154
+ login = (uid == 526_301 ? 'yegor256' : 'torvalds') if uid.is_a?(Integer)
153
155
  {
154
156
  id: 444,
155
157
  login:,
156
- type: name == 29_139_614 ? 'Bot' : 'User'
158
+ type: uid == 29_139_614 ? 'Bot' : 'User'
157
159
  }
158
160
  end
159
161
 
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.7.0' unless const_defined?(:VERSION)
13
+ VERSION = '0.7.1' unless const_defined?(:VERSION)
14
14
  end
@@ -61,6 +61,38 @@ class TestConclude < Fbe::Test
61
61
  assert_equal(42, f.bar)
62
62
  end
63
63
 
64
+ def test_considers_until_quota
65
+ WebMock.disable_net_connect!
66
+ fb = Factbase.new
67
+ 5.times do
68
+ fb.insert.foo = 1
69
+ end
70
+ options = Judges::Options.new
71
+ stub_request(:get, %r{https://api.github.com/users/.*}).to_return(
72
+ {
73
+ body: { id: rand(100) }.to_json,
74
+ headers: { 'Content-Type' => 'application/json', 'X-RateLimit-Remaining' => '999' }
75
+ },
76
+ {
77
+ body: { id: rand(100) }.to_json,
78
+ headers: { 'Content-Type' => 'application/json', 'X-RateLimit-Remaining' => '9' }
79
+ }
80
+ )
81
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
82
+ body: 'hm...', headers: { 'X-RateLimit-Remaining' => '777' }
83
+ ).times(1)
84
+ global = {}
85
+ o = Fbe.octo(loog: Loog::NULL, options:, global:)
86
+ Fbe.conclude(fb:, judge: 'boom', loog: Loog::NULL, options:, global:) do
87
+ quota_aware
88
+ on '(exists foo)'
89
+ consider do |f|
90
+ f.bar = o.user("user-#{rand(100)}")[:id]
91
+ end
92
+ end
93
+ assert_equal(2, fb.query('(exists bar)').each.to_a.size)
94
+ end
95
+
64
96
  def test_ignores_globals
65
97
  $fb = nil
66
98
  $loog = nil
@@ -56,7 +56,7 @@ class TestOcto < Fbe::Test
56
56
  global = {}
57
57
  o = Fbe.octo(loog: Loog::NULL, global:, options: Judges::Options.new)
58
58
  stub_request(:get, 'https://api.github.com/users/yegor256')
59
- .to_return(status: 200, body: '{}', headers: { 'Cache-Control' => 'public, max-age=60', 'etag' => 'abc' })
59
+ .to_return(body: '{}', headers: { 'Cache-Control' => 'public, max-age=60', 'etag' => 'abc' })
60
60
  .times(1)
61
61
  .then
62
62
  .to_raise('second request should be cached, not passed to GitHub API!')
@@ -64,12 +64,50 @@ class TestOcto < Fbe::Test
64
64
  o.user('yegor256')
65
65
  end
66
66
 
67
+ def test_rate_limit_remaining
68
+ WebMock.disable_net_connect!
69
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
70
+ { body: '{}', headers: { 'X-RateLimit-Remaining' => '222' } }
71
+ )
72
+ stub_request(:get, 'https://api.github.com/user/42').to_return(
73
+ body: '', headers: { 'X-RateLimit-Remaining' => '4' }
74
+ )
75
+ o = Octokit::Client.new
76
+ assert_equal(222, o.rate_limit.remaining)
77
+ o.user(42)
78
+ assert_equal(4, o.rate_limit.remaining)
79
+ assert_equal(4, o.rate_limit.remaining)
80
+ end
81
+
67
82
  def test_off_quota
68
83
  WebMock.disable_net_connect!
69
- stub_request(:get, 'https://api.github.com/rate_limit')
70
- .to_return(status: 200, body: '{}', headers: { 'X-RateLimit-Remaining' => '1000' })
84
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
85
+ body: '{}', headers: { 'X-RateLimit-Remaining' => '333' }
86
+ )
87
+ stub_request(:get, 'https://api.github.com/user/42').to_return(
88
+ body: '', headers: { 'X-RateLimit-Remaining' => '3' }
89
+ )
71
90
  o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new)
72
91
  refute(o.off_quota)
92
+ o.user(42)
93
+ assert(o.off_quota)
94
+ end
95
+
96
+ def test_off_quota_twice
97
+ WebMock.disable_net_connect!
98
+ stub_request(:get, 'https://api.github.com/rate_limit').to_return(
99
+ body: '{}', headers: { 'X-RateLimit-Remaining' => '333' }
100
+ )
101
+ stub_request(:get, 'https://api.github.com/user/42').to_return(
102
+ { body: '', headers: { 'X-RateLimit-Remaining' => '5555' } },
103
+ { body: '', headers: { 'X-RateLimit-Remaining' => '5' } }
104
+ )
105
+ o = Fbe.octo(loog: Loog::VERBOSE, global: {}, options: Judges::Options.new)
106
+ refute(o.off_quota)
107
+ o.user(42)
108
+ refute(o.off_quota)
109
+ o.user(42)
110
+ assert(o.off_quota)
73
111
  end
74
112
 
75
113
  def test_retrying
@@ -80,7 +118,7 @@ class TestOcto < Fbe::Test
80
118
  .to_raise(Octokit::TooManyRequests.new)
81
119
  .times(1)
82
120
  .then
83
- .to_return(status: 200, body: '{}')
121
+ .to_return(body: '{}')
84
122
  o.user('yegor256')
85
123
  end
86
124
 
@@ -92,7 +130,7 @@ class TestOcto < Fbe::Test
92
130
  .to_return(status: 503)
93
131
  .times(1)
94
132
  .then
95
- .to_return(status: 200, body: '{}')
133
+ .to_return(body: '{}')
96
134
  o.user('yegor256')
97
135
  end
98
136
 
@@ -136,11 +174,11 @@ class TestOcto < Fbe::Test
136
174
  o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new({ 'github_api_pause' => 0.01 }))
137
175
  stub_request(:get, 'https://api.github.com/users/foo')
138
176
  .to_return(
139
- status: 200, body: '{}',
177
+ body: '{}',
140
178
  headers: { 'x-ratelimit-remaining' => '1' }
141
179
  )
142
180
  .to_return(
143
- status: 200, body: '{}',
181
+ body: '{}',
144
182
  headers: { 'x-ratelimit-remaining' => '10000' }
145
183
  )
146
184
  o.user('foo')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-15 00:00:00.000000000 Z
10
+ date: 2025-04-16 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: backtrace